Finding z-axis with only view vector and position vector

Started by
3 comments, last by crossbow 21 years, 8 months ago
Hi, How do I find the z-axis of my object with only the view vector and position vector? I don''t have the up vector yet so don''t say the cross product of the view and the up vector, because I would have tried that. Thanks for your help!
Advertisement
I''m assuming from your post that the Z vector is the right vector correct?

Anyway, a view vector and a position vector isn''t enough information to find the Z-axis. Do you know anything else, such as the roll?
Sorry, I didn't mension the roll is 0, but I'm using axis rotation so does a roll value matter? Would finding the cross product of the up vector 0,1,0 and the view vector be enough to get the z(right)-axis, and then find the up vector from the cross product of the z and view(x) vector? This probably isn't right, but I am new to 3D math. I have a rotate view function the takes the number of degrees and the axis to rotate, so I'm just trying to find the axis to input it. Here is how the rotate function works:
If I want to rotate down:
RotateObj(-0.01f, vPos->zaxis.x, vPos->zaxis.y,vPos->zaxis.z, vPos);
vPos is just a sturct to store the new rotations, but I just need to figure out the zaxis. How do I find that? I hope this is slightly familiar to you.


Thanks!

[edited by - crossbow on August 19, 2002 9:13:13 PM]
I''m trying to do a similar thing. I am trying to use this for a camera class so that you can call setTarget(vector); and have it look at that position. The information available is the camera''s position, previous right, up and target vectors as well as the new target vector.

Is this impossible?
-- Ian Kerr
Here''s my code that I''ve got so far...

CEGL_Void CEGL_Bone :: setTarget(CEGL_Vector &target)
{
CEGL_Float xRot, yRot, zRot;

// Normalize target
target = (target - m_position) | 1;

// Break the new target down into 3 rotations
if(target.m_xyzw[0] >= 0 && target.m_xyzw[2] >= 0)
yRot = asin(target.m_xyzw[0]) * 57.2957795f;
else if(target.m_xyzw[0] >= 0 && target.m_xyzw[2] < 0) {
yRot = asin(-target.m_xyzw[2]) * 57.2957795f;
yRot += 90.0f;
}
else if(target.m_xyzw[0] < 0 && target.m_xyzw[2] < 0) {
yRot = asin(-target.m_xyzw[0]) * 57.2957795f;
yRot += 180.0f;
}
else {
yRot = asin(target.m_xyzw[2]) * 57.2957795f;
yRot += 270.0f;
}

// Keep track of current settings
CEGL_Int originMode = getOriginMode();
setOriginMode(CEGL_BONE_NORMAL);

// Reset axes
m_right = CEGL_Vector(1.0f, 0.0f, 0.0f);
m_up = CEGL_Vector(0.0f, 1.0f, 0.0f);
m_target = CEGL_Vector(0.0f, 0.0f, 1.0f);

// Rotate around the y axis
if(yRot)
rotateY(yRot);

target.m_xyzw[2] = m_target.m_xyzw[2];

if(target.m_xyzw[1] >= 0 && target.m_xyzw[2] >= 0) {
xRot = acos(target.m_xyzw[1]) * 57.2957795f;
xRot -= 90.0f;
}
else if(target.m_xyzw[1] < 0 && target.m_xyzw[2] >= 0) {
xRot = asin(-target.m_xyzw[1]) * 57.2957795f;
}
else if(target.m_xyzw[1] < 0 && target.m_xyzw[2] < 0) {
xRot = acos(target.m_xyzw[1]) * 57.2957795f;
xRot -= 270.0f;
}
else {
xRot = asin(-target.m_xyzw[1]) * 57.2957795f;
xRot += 180.0f;
}

if(xRot)
rotateX(xRot);

m_target = m_target | 1;
m_right = m_right | 1;
m_up = m_up | 1;

// Restore settings
setOriginMode(originMode);
}
-- Ian Kerr

This topic is closed to new replies.

Advertisement