|
-
FK founder & general loiterer
-
Senior Member
you take cross product of, for example, p1 - p0 and p1 - p2 (any pair of vectors, just make sure you always take same pair). the resulting vector then can be projected on triangle-to-camera vector (or in case of good coordinate choise you could just take its z coordinate), and the sign of the result will show you the way. the cross product, aka normal vector, can be computed once per game for static geometry; projection is a matter of dot product.
-
Couldn't you just use winding, such as F10 will offer, you just have to incorporate it into your objects.
-
Senior Member
View the ramp surface as a set of points which satisfies Ax+By+Cz=D. The surface of the ramp splits R3 into two halfspaces, above and below. Compute a displacement vector from any point on the ramp surface towards the camera. Dot this vector the against the surface normal and compare against the surfaces "D" parameter.
I think it's easier to explain in math than in words.
Inputs:
// the position vectors of your things in 3D (or 2D, since they're all at z=0)
p0, p1, p2 : Vector2D or Vector3D,
// the height of stick thingy),
h : Number
// 3D position of the camera
C : Vector3D;
Algorithm:
// Augment position vectors to 3D, if they aren't already.
p0prime : Vector3D = <p0.x, p0.y, 0.0>
p1prime : Vector3D = <p1.x, p1.y, 0.0>
p2prime : Vector3D = <p2.x, p2.y, 0.0>)
// Compute a point at the top of the ramp.
p2prime += h * <0 0 1>;
// Compute normal of ramp surface
normal : Vector3D = (p2prime-p1prime) CROSS (p0prime-p1prime)
normal.normalize();
D : Number = normal DOT p0prime
// Compute displacement from surface to camera.
displacement : Vector3D = C - p0prime;
Dcamera : Numer = normal DOT displacement
above : Boolean = Dcamera > D;
Output:
If (above) then use top surfaces texture.
If (!above) then use the bottom texture.
From a design standpoint, I think it would look better as a solid polyhedron. Maybe that can be a future refinement.
EDIT: yeah what makc said - you're gettin' gangbanged with answers out here
Last edited by rachil0; 05-22-2008 at 07:02 PM.
-
Senior Member
yes, you could have used winding: sign of (sx0*sy1 - sx1*sy0) + (sx1*sy2 - sx2*sy1) + (sx2*sy0 - sx0*sy2)
yet the dot product is simpler, ax*bx + ay*by + az*bz. doesn't really matter for the game like this.
EDIT: I have made slight error here.
Last edited by realMakc; 05-22-2008 at 07:16 PM.
-
FK founder & general loiterer
thanks for the quick replies....
looking at your one rachil0... are you saying that I can create an arbitrary triangle out of the ramps surface to do this check? SO I can use as you have mentioned the two bottom coordinates and one of the top positions?
I'll give that one a go
-
FK founder & general loiterer
ok realMakc can you elaborate further.....
I get the (p1 - p0) CROSS (p1 - p2)
but Im not sure how you implement the projection onto the triangle-to-camera vector. (Or what point to choose on the triangle to make the vector)
-
Senior Member
 Originally Posted by rachil0
EDIT: yeah what makc said
aren't you in effect suggesting winding, too? those 0-es you have added in z-s should make few products disappear I think. but I sort of thought he had raw 3d data.
-
Senior Member
@FK, (p1 - p0) CROSS (p1 - p2) is triangle normal, meaning it equally applies to any point on the triangle. I don't think you could construct a triangle (or even a plane) so that projections of its normal onto its point -to- some outer point vector would have different signs for different points. EDIT it could be easier to think about it other way around - projecting triangle-to-camera vector onto its normal... oh well. just go with Jerry's idea and use winding
Last edited by realMakc; 05-22-2008 at 07:29 PM.
-
Senior Member
[are you saying that I can create an arbitrary triangle out of the ramps surface to do this check?]
It's no so much you're creating a triangle, you're creating a plane. Although you're using 3 points to determining the ABCD of the plane, the triangle is just a subset of the points that satisfy the ABCD equation. Use any 3 points on the plane that you wish.
[Or what point to choose on the triangle to make the vector]
Pick any point on the triangle. Or get fancy, and pick any point on the plane. You'll still get the same projection (with exact arithmetic). I picked p0prime, but you could really pick any convex summation of p0prime, p1prime and p2prime.
[aren't you in effect suggesting winding, too?]
Winding works too. In my codes, I use this solution because the backface culling step is done before perspective projection into screen space.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|