fix weird deltatime issue
This commit is contained in:
parent
2e13ef34f8
commit
d54de1fbf5
1 changed files with 13 additions and 7 deletions
20
control.c
20
control.c
|
@ -34,11 +34,16 @@ int collision(struct chunk chunk, vec3 pos, vec3 dir_temp, int col, int n) {
|
||||||
|
|
||||||
struct v3f control_handler(double cx, double cy, vec3 pos, vec3 dir_temp,
|
struct v3f control_handler(double cx, double cy, vec3 pos, vec3 dir_temp,
|
||||||
GLFWwindow *window, struct chunk chunk) {
|
GLFWwindow *window, struct chunk chunk) {
|
||||||
vec3 direction = {cosf(cy) * sinf(cx), sinf(cy), cosf(cy) * cosf(cx)};
|
|
||||||
vec3 right = {sinf(cx - 3.14f / 2.0f) * 0.015, 0,
|
|
||||||
cosf(cx - 3.14f / 2.0f) * 0.015};
|
|
||||||
|
|
||||||
vec3 front = {sinf(cx) * 0.015, 0, cosf(cx) * 0.015};
|
double delta = glfwGetTime();
|
||||||
|
if (delta > 1/60.0) delta = 1/60.0;
|
||||||
|
glfwSetTime(0);
|
||||||
|
delta *= 20;
|
||||||
|
vec3 direction = {cosf(cy) * sinf(cx), sinf(cy), cosf(cy) * cosf(cx)};
|
||||||
|
vec3 right = {sinf(cx - 3.14f / 2.0f) * 0.015 * delta, 0,
|
||||||
|
cosf(cx - 3.14f / 2.0f) * 0.015 * delta};
|
||||||
|
|
||||||
|
vec3 front = {sinf(cx) * 0.015 * delta, 0, cosf(cx) * 0.015 * delta};
|
||||||
vec3 pos_temp = {0, 0, 0};
|
vec3 pos_temp = {0, 0, 0};
|
||||||
|
|
||||||
vec3_dup(pos_temp, pos);
|
vec3_dup(pos_temp, pos);
|
||||||
|
@ -59,7 +64,7 @@ struct v3f control_handler(double cx, double cy, vec3 pos, vec3 dir_temp,
|
||||||
vec3_sub(dir_temp, dir_temp, right);
|
vec3_sub(dir_temp, dir_temp, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3_scale(dir_temp, dir_temp, 0.9);
|
vec3_scale(dir_temp, dir_temp, pow(0.9,delta));
|
||||||
|
|
||||||
vec3 off = {0, 0, 0};
|
vec3 off = {0, 0, 0};
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
@ -76,7 +81,7 @@ struct v3f control_handler(double cx, double cy, vec3 pos, vec3 dir_temp,
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3_add(pos, pos, dir_temp);
|
vec3_add(pos, pos, dir_temp);
|
||||||
dir_temp[1] -= 0.03;
|
dir_temp[1] -= 0.03 * delta;
|
||||||
if (collision(chunk, pos, dir_temp, col, 1)) {
|
if (collision(chunk, pos, dir_temp, col, 1)) {
|
||||||
col = 0;
|
col = 0;
|
||||||
|
|
||||||
|
@ -176,7 +181,8 @@ void control_lclick(double cx, double cy, vec3 pos, struct item *inv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void control_rclick(double cx, double cy, vec3 pos, struct item *inv, int slot) {
|
void control_rclick(double cx, double cy, vec3 pos, struct item *inv,
|
||||||
|
int slot) {
|
||||||
struct v3f highlighted = control_rtrace(cx, cy, pos, 0);
|
struct v3f highlighted = control_rtrace(cx, cy, pos, 0);
|
||||||
struct chunk placeChunk;
|
struct chunk placeChunk;
|
||||||
int cube = gen_cube(highlighted.pos[0], highlighted.pos[1],
|
int cube = gen_cube(highlighted.pos[0], highlighted.pos[1],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue