Gradient
by Daniel Brown · in Torque Game Engine · 05/07/2004 (3:34 pm) · 12 replies
Is there any function to get the current gradient of the surface you are standing on?
About the author
#2
05/16/2004 (3:12 pm)
Gradient?
#3
05/16/2004 (3:41 pm)
Daniel BrownQuote:This is already in the playerdata block.
Or perhaps a way to limit the steepness a player can walk up?
#4
05/16/2004 (5:49 pm)
Assuming poly list is not empty, and looping through it.runSurfaceCos = mCos(mDegToRad(runSurfaceAngle));
...
F32 bestVd = -1;
...
F32 vd = poly->plane.z; // i.e. mDot(Point3F(0,0,1), poly->plane);
if (vd > bestVd) {
bestVd = vd;
*contactNormal = poly->plane;
}
*run = bestVd > mDataBlock->runSurfaceCos;
...
#5
runSurfaceAngle =
and
jumpSurfaceAngle =
alter those and it will limit what someone can run and jump up.
05/16/2004 (6:23 pm)
In the player datablock, located in player.cs, look for:runSurfaceAngle =
and
jumpSurfaceAngle =
alter those and it will limit what someone can run and jump up.
#6
05/17/2004 (12:11 am)
He is asking how you get the angle the player is standing on, not limiting what he can stand on.
#7
05/17/2004 (12:12 am)
Oh, sorry im 1/2 asleep, my eyes seemed to have totally missed the second post.
#8
sorry my math is rusty, i cant figure out what the value of bestVd is.
Why do we compare bestVd > mDatablock->runSurfaceCos. (i know why, i.e to restrict the player from moving uphill) but i cant figure out what bestVd represents or why that variable name was chosen. Is it best vertical distance?
If someone could explain it in detail I would apreciate it.
Thanks!
12/30/2005 (9:13 am)
Can someone please explain what the above code doessorry my math is rusty, i cant figure out what the value of bestVd is.
Why do we compare bestVd > mDatablock->runSurfaceCos. (i know why, i.e to restrict the player from moving uphill) but i cant figure out what bestVd represents or why that variable name was chosen. Is it best vertical distance?
If someone could explain it in detail I would apreciate it.
Thanks!
#9
and assuming you've got the normal to the surface,
then the cross-product is your friend!
note that vGrad becomes (logically) undefined as your surface gets closer to horizontal.
12/30/2005 (9:52 am)
If the "gradient" means "the most upwards-pointing vector which is on the surface",and assuming you've got the normal to the surface,
then the cross-product is your friend!
vNorm = normal to the surface vUp = the "up" vector. in torque this would be (0, 0, 1). vLevel = vUp CROSS vNorm. - vLevel is now horizontal. vGrad = vNorm CROSS vLevel. - vGrad is now pointing uphill.
note that vGrad becomes (logically) undefined as your surface gets closer to horizontal.
#10
12/30/2005 (9:58 am)
Thanks but were you answering my question or the original one? That was a year old question, perhaps i should have started a new thread but i figured why not keep the information in one place.
#11
i believe that clip of code you're asking about chooses the most horizontal surface in a list of surfaces, and tests to see if it's more horizontal than runSurfaceAngle.
bestVd in that code looks to me like the z-component of the surface normal,
which larger ones mean a more horizontal surface.
12/30/2005 (10:23 am)
Oh, hah. sorry, i answered the original Q.i believe that clip of code you're asking about chooses the most horizontal surface in a list of surfaces, and tests to see if it's more horizontal than runSurfaceAngle.
bestVd in that code looks to me like the z-component of the surface normal,
which larger ones mean a more horizontal surface.
#12
So the possible values for Z would range from -1 to 1 and when compared to the Cos(SomeAngle) which also ranges from -1 to 1, that should return true if the Z value is larger than Cos(SomeAngle).
Did I understand that correct?
12/30/2005 (12:10 pm)
Thanks that makes sense, I thought that it was the Z component of the plane. Which I was right and if i am correct a plane in vector form is described by the normal and the distance as the 4th vector component.So the possible values for Z would range from -1 to 1 and when compared to the Cos(SomeAngle) which also ranges from -1 to 1, that should return true if the Z value is larger than Cos(SomeAngle).
Did I understand that correct?
Torque Owner Daniel Brown