|
Post by shadow008 on Aug 5, 2010 20:20:04 GMT -5
Ok, i need an equation. Lets say i have a direction (dX,0,dZ) and a plane normal (pX,pY,pZ) and i want to end up with a result similar to this: with the direction being perpendicular to the normal (dX,NEWY,dZ)
Essencially its for my first person camera. I have a direction (dX,0,dY) and i want it to follow the slope of the plane(with normal(pX,pY,pZ).
If im missing any information, notify me.
PLZ?!
I givez u c00kie!
|
|
|
Post by chris857 on Sept 5, 2010 17:34:04 GMT -5
Say you have a plane normal (pX,pY,pZ), and a direction vector (dx, 0, dz). Your new direction vector, parallel to the plane, is (dx, -(pX*dx + pZ*dz) / pY, dz). Here is an explanation:
First, any two vectors v and u are perpendicular if v*u = 0 (dot product). This also means that v(0)*u(0) + v(1)*u(1) + v(2)*u(2) = 0. Since we are looking for a y-coeffecient of a vector and know the five other values, v(1)*u(1) = -(v(0)*u(0) + v(2)*u(2)), and u(1) = -(v(0)*u(0) + v(2)*u(2)) / v(1).
An important thing to note is that this equation only works for ground, trying to walk on a vertical cliff breaks the equation (make sure pY isn't zero).
|
|
|
Post by shadow008 on Sept 15, 2010 13:59:23 GMT -5
THANK YOU!!! And it works nicely
|
|
|
Post by shadow008 on Oct 15, 2010 18:50:33 GMT -5
Alright, i got another one. This time its for a "vertical" plane and a horizontal direction: -->|| (not always vertical). I have a direction (dx,0,dz) and a plane (px,py,pz) and want the direction to be parallel to the plane on the x and z axis. Im not guessing you could just do : NEWX = -(py*(dy=0) + pZ*dz) / px
Because dy is always 0
Any idea on how this could be done?
|
|
|
Post by chris857 on Oct 15, 2010 21:17:35 GMT -5
If I'm thinking about this right, the two directions in the x-z plane that are parallel to the normal are (pZ,0,-pX) and (-pZ,0,pX).
|
|
|
Post by shadow008 on Oct 22, 2010 18:19:12 GMT -5
So if i have the direction and the normal, how would this equation finish?:
Direction = (dx,dy,dz) Normal = (nx,ny,nz) NewDirection = vec3(?,dy,?)
|
|