get angel difrence from face normal to camera?

Previous topic - Next topic

djtoon

any one done this?
the math is messing with my brain :)

Slydog

I'm not the best person to answer, but I'll try.

You can represent your camera angle / vector by subtracting your 'look_at' location from your 'camera' location'.
This should give you the direction your camera is facing.
ie: The values you put into your 'X_CAMERA' command, where c=camera, and l=lookat
Code (glbasic) Select
X_CAMERA cx, cy, cz, lx, ly, lz

Do you know your face normal already?  (If not, I don't know how to find it!).
Is a normal represented by a direction vector?
If so, then can't you just take the difference of the calculated camera vector above, and the normal vector?

If you want this represented in degress, you can choose an axis, and use 'ATAN()' to calculate it (by passing in the delta values of the two vectors).

[Edit] Whoa! Just did a quick Google search, I think I see what you're asking.  As I said above, this is not my area! ha
But I did see this formula on one page:
cos(theta) = dot(A,B) / (norm(A) * norm(B))
I think you take the Dot Product of the two vectors and divide by the unit vectors multiplied together.  Maybe then use ACOS on that value?  Ha, very grasping at straws here!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

mentalthink

I think if you use the raycollision from the camera and use 2 times, one time from the same position of the camera and the other calculing, to top or down when it´s coliding, perhaps you have the angle...

I´m not sure about this, I thinked in "real time"  =D ... perhaps not works...

Hemlos

This is the oldest dilema in the book, and a mouthfull to think about!
What slydog has above might be a better solution and faster...it has come up before in the forums here, but no one even knew what i was talking about LMAO...they made me feel like a nerd with no friends.

I solved the issue by drawing the problem on paper, then i created this formula:
It uses 2 functions...the output you need is AngleX and AngleY as a global variable.
Code (glbasic) Select

FUNCTION GLM_X_GETVECTORANGLES: vX , vY , vZ
//Vector XYZ is the input, transforms to rotations, for use with X_Rotation .
//Object Face must be created towards +Z, so a camera IN +Z pointing to 0,0,0 sees the face.
//
// Billboarding:
//   Call these before X_ROTATION:
//
// DistanceX = CameraX - BillBoardX
// DistanceY = CameraY - BillBoardY
// DistanceZ = CameraZ - BillBoardZ
// X_Velocity2Rotation( DistanceX , DistanceX , DistanceZ )
// X_ROTATION AngleZ,0,0,1
// X_ROTATION AngleX,1,0,0
// X_ROTATION AngleY,0,1,0
//
// Missles Guidance:
//   This will use the vector velocity(dist per frame) of the missle to guide the rotations.
//   Just use the real 3d velocity:
//
// GLM_X_GETVECTORANGLES( VelocityX , VelocityX , VelocityZ )
// X_ROTATION AngleZ,0,0,1
// X_ROTATION AngleX,1,0,0
// X_ROTATION AngleY,0,1,0

vX2 = GLM_X_Magnitude( 0 , vY , 0 , vX , vY , vZ )
AngleX = ATAN(-vX2 , -vY ) + 90
AngleY = ATAN( -vX , -vZ ) + 180
AngleZ = 0

ENDFUNCTION

FUNCTION GLM_X_Magnitude: x0,y0,z0, x1,y1,z1
//It gives a distance between two points in 3d space.
//Vector 1 = x0,y0,z0
//Vector 2 = x1,y1,z1
// The return is the true distance between these 2 points. (Hypotenuese)

LOCAL x , y , z , xx , yy , zz
x  = x0 - x1; y  = y0 - y1; z  = z0 - z1;
xx = x*x; yy = y*y; zz = z*z;
RETURN SQR( xx + yy + zz )

ENDFUNCTION






And heres a point rotation:


Code (glbasic) Select
FUNCTION GLM_X_dPOINTROTATION: X,Y,Z, AnglePitch, AngleYaw, Radius //Point is returned as a vector add function
// vector add function
DIM NewPoint[3]
NewPoint[0] = X + COS( AngleYaw ) * SIN( AnglePitch ) * Radius
NewPoint[1] = Y + COS( AnglePitch ) * Radius
NewPoint[2] = Z + SIN( AngleYaw ) * SIN( AnglePitch ) * Radius

ENDFUNCTION // TRANSLATEANGLEVECTOR


And if you just happen to be using types for your vector system, this function is the same as above, using a TYPE instead of DIM:

Code (glbasic) Select
FUNCTION GLM_X_tPOINTROTATION AS ObjectVector: Point AS ObjectVector, AnglePitch, AngleYaw, Radius //Point is returned as a vector add function
// vector add function

Point.X = Point.X + COS( AngleYaw ) * SIN( AnglePitch ) * Radius
Point.Y = Point.Y + COS( AnglePitch ) * Radius
Point.Z = Point.Z + SIN( AngleYaw ) * SIN( AnglePitch ) * Radius

RETURN Point
ENDFUNCTION // TRANSLATEANGLEVECTOR


Djtoon, i might be able to help more, if you explain in detail what you need these calculations for.

This is all experimental code, i dont know if what i wrote is ACTUALLY the best method...but missles DO rotate and guide properly on any path i send it...even curves.
This is as far as i have gotten with experimenting:
When the missle stops, it rotates back to 0,0,0 rotations, so i do have more tinking to do.
But like i said...it work..when in motion.
Bing ChatGpt is pretty smart :O

Hemlos

PS. This does NOT solve gimbal locking objects when they are rotated.
The only thing this solves is the Face of an object relative to its movement.
If you want to solve gimbal locking ALSO: you must go back to the quaternion camera thread and read my last message.
3d is a mad disgusting monster, and really i wish i never touched this part of programming in the first place.

I hope i didnt waste my time here today, I dont remember if i already posted this function alreayd or not..duuuh.
And now this math will force me back into hibernation, dont wake me up till next spring.
Bing ChatGpt is pretty smart :O