Add normals to pyramid.

This commit is contained in:
Themaister 2013-05-15 00:44:28 +02:00
parent 3adb68448b
commit 1fa2414454
2 changed files with 21 additions and 4 deletions

16
box.obj
View File

@ -21,6 +21,17 @@ v 10 -10 10
v -10 10 10
v 10 10 10
v 3 -10 -5
v 5 -10 -3
v 7 -10 -5
v 5 -10 -7
v 5 -5 -5
vn -0.6804 0.2722 0.6804
vn 0.6804 0.2722 0.6804
vn 0.6804 0.2722 -0.6804
vn -0.6804 0.2722 -0.6804
usemtl block
f 1/1/5 2/2/5 3/3/5
f 4/4/5 3/3/5 2/2/5
@ -36,3 +47,8 @@ f 8/4/2 4/3/2 6/2/2
f 6/1/6 5/2/6 8/3/6
f 7/4/6 8/3/6 5/2/6
f 9/1/7 10/2/7 13/3/7
f 10/1/8 11/2/8 13/3/8
f 11/1/9 12/2/9 13/3/9
f 12/1/10 9/2/10 13/3/10

View File

@ -161,6 +161,7 @@ static bool inside_triangle(const Triangle& tri, const vec3& pos)
vec3 bp = pos - tri.b;
vec3 bc = tri.c - tri.b;
// Checks if point exists inside triangle.
if (dot(cross(ab, ap), real_normal) < 0.0f)
return false;
@ -184,7 +185,7 @@ static void wall_hug_detection(vec3& player_pos)
float plane_dist = tri.n0 - dot(player_pos, tri.normal);
// Might be hugging too close.
if (plane_dist >= 0.0f && plane_dist < min_dist)
if (plane_dist >= -1.0f && plane_dist < min_dist)
{
vec3 projected_pos = player_pos + tri.normal * vec3(plane_dist);
if (inside_triangle(tri, projected_pos))
@ -197,7 +198,7 @@ static void wall_hug_detection(vec3& player_pos)
if (closest_triangle_hug)
{
retro_stderr_print("Fixup hugging: Dist: %.6f.\n", min_dist);
//retro_stderr_print("Fixup hugging: Dist: %.6f.\n", min_dist);
// Push player out.
player_pos += vec3(min_dist - 1.0f) * closest_triangle_hug->normal;
}
@ -221,6 +222,7 @@ static void collision_detection(vec3& player_pos, vec3& velocity)
if (towards_plane_v > 0.00001f) // We're moving towards the plane.
{
float ticks_to_hit = (plane_dist - 1.0f) / towards_plane_v;
// We'll hit the plane in this frame.
if (ticks_to_hit >= 0.0f && ticks_to_hit < min_time)
{
@ -232,7 +234,6 @@ static void collision_detection(vec3& player_pos, vec3& velocity)
}
}
}
}
if (closest_triangle)
@ -242,7 +243,7 @@ static void collision_detection(vec3& player_pos, vec3& velocity)
// Make velocity vector parallel with plane.
velocity -= vec3(dot(velocity, closest_triangle->normal)) * closest_triangle->normal;
retro_stderr_print("Fixup V: %.6f, %.6f, %.6f\n", velocity[0], velocity[1], velocity[2]);
//retro_stderr_print("Fixup V: %.6f, %.6f, %.6f\n", velocity[0], velocity[1], velocity[2]);
player_pos += velocity * vec3(1.0f - min_time); // Used up some time.
}