• Advertisement
Sign in to follow this  

Anyone guess what exactly all these mean?

This topic is 1274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got the book AI Programming Wisdom 3, in the CD-ROM, I've got Bourne and Sattar source code on Autonomous Camera Control, when I see these 2 lines and having not any comments, I am not sure if mvFacing actually means look at vector or look at target, and not sure what mvView and mvCross means? Does anyone here have the same book with me know what these are all about? Thanks Jack

// Autonomous camera class.
class Camera
{
public:
	Vector3		mvPosition, mvView, mvUp;
	Vector3		mvFacing, mvCross;

Update:

I dug a little bit deeper, but found out that mvFacing is actually the lookat vector, but mvCross and mvView has no idea what that is.

Thanks

Jack

Share this post


Link to post
Share on other sites
Advertisement

Assuming that mvFacing is the look direction, then mvCross is probably the right (or left) vector because it can be calculated by calculating the cross product of mvUp and mvFacing.

 

I'm not sure about mvView. My guess about mvView is that it is the position the camera is looking at. So mvFacing = mvView - mvPosition.

 

Can you post the code where those vectors are initialized? 

Edited by TiagoCosta

Share this post


Link to post
Share on other sites

mvCross is most likely the right or left vector of the camera that represents its x-axis. mvCross is obtained by a cross-product between the camera's direction vector and the up vector; that's why it's called mvCross. By moving along this vector you can create the so called strafe effect of a camera.

 

To create the lookAt matrix (most cameras calculate this matrix) you need a direction vector and a target vector. The direction vector is the vector that's pointing in the direction your camera is facing and this one is usually obtained from subtracting the position vector from the target vector. Based on the way the variables are set up I assume the first 3 vectors are the user-supplied vectors thus mvView is most likely the target vector (e.g. the coordinate a camera is looking at like (0,0,0)) while the mvFacing and mvCross are then later calculated thus mvFacing is then probably the camera's direction vector.

Share this post


Link to post
Share on other sites

I found this old interactive tutorial (written in Java, you will proably have to lower your security settings from Control Panel -> Java -> Security tab in order to execute it) to be very useful in understanding how cross products work and how two vectors form a plane (the cross product is always perpendicular to that plane).

 

You can click on the plane to move it around, or you can click on the arrows A and B to see how the cross product is affected.

Share this post


Link to post
Share on other sites


Can you post the code where those vectors are initialized?
This is really the only way to know for sure - the names could be misleading, so unless you check the code that is using these objects then you are really only guessing!

Share this post


Link to post
Share on other sites

I don't know if the original authors are willing to let me disclose the source code...
But here is the constructor method

 

//
//    Camera::Camera()
//
//    Default constructor.
//
Camera::Camera()
{
    mnCurrentProfile = 0;
    mnNumOfProfiles = 0;

    mvPosition = Vector3::origin;
    mvView = Vector3::origin;
    mvUp = Vector3::yAxis;
    mvFacing = Vector3::origin;
    mvCross = Vector3::origin;
    
    mfSecondsUntilEnd = 1.0f;

    mnRayCastingMethod = kCameraCurrent;
    mnSafePointMethod = kSafePoint_targetrelative;

    mfFrameTime = 0.0f;

}


//
//    Camera::~Camera()
//
//    Default destructor.
//
Camera::~Camera()
{
}

Share this post


Link to post
Share on other sites

Hello friends,
I've tried to connect the camera from the book to an Ogre camera, this's what I got so far

Ogre::Vector3 BourneVec3ToOgreVec3(Dolly_Cam::Vector3 vec) {
    Ogre::Vector3 vec3;
    vec3.x = vec.x;
    vec3.y = vec.y;
    vec3.z = vec.z;
    return vec3;
}

Dolly_Cam::Vector3 OgreVec3ToBourneVec3(Ogre::Vector3 vec) {
    Dolly_Cam::Vector3 vec3;
    vec3.x = vec.x;
    vec3.y = vec.y;
    vec3.z = vec.z;
    return vec3;
}
cam.mvPosition = OgreVec3ToBourneVec3(mSceneMgr->getSceneNode("Worker00001Node")->getPosition() + Ogre::Vector3(0, 5, 5));
cam.mvFacing = cam.mvPosition - OgreVec3ToBourneVec3(mSceneMgr->getSceneNode("Worker00001Node")->getPosition());
changeDollyCam(cam);
void OgreRecastApplication::changeDollyCam(const Dolly_Cam::Camera& cam) {  
  
        Ogre::Camera* camera = mSceneMgr->createCamera("Dolly_Cam");
        mWindow->removeViewport(0);
        camera->setPosition(BourneVec3ToOgreVec3(cam.mvPosition));
        camera->lookAt(BourneVec3ToOgreVec3(cam.mvView));
        Ogre::Radian R = Ogre::Math::ATan(Ogre::Math::Tan(Ogre::Degree((float)45/2))/mCamera->getAspectRatio())*2;
        camera->setFOVy(R);
    

        mViewport = mWindow->addViewport( camera );
        mViewport->setCamera(camera);

        delete mCameraMan;
        mCameraMan = new OgreBites::SdkCameraMan(camera);
    

}
 

But it looks perhaps at the opposite direction. But I have tried to reverse the order of subtraction to no avail.
To my understanding of vectors, the look at vector should be camera's position substracting the position of look at target.
Correct me if I am any wrong.

Update:

Notice I've got a typo for mCamera => camera in addViewport line, but the result is same
Thanks
Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

To my understanding of vectors, the look at vector should be camera's position substracting the position of look at target.


That's incorrect. The look at vector should (position of look at target) - (camera's position).
 
The vector AB = B - A.
 
So:
cam.mvFacing = OgreVec3ToBourneVec3(mSceneMgr->getSceneNode("Worker00001Node")->getPosition()) - cam.mvPosition;

But it looks perhaps at the opposite direction. But I have tried to reverse the order of subtraction to no avail.

 
What exactly happens when you reverse the order of subtraction?
 
Does Ogre and Dolly use the same coordinate systems? Maybe you are mixing Left hand and Right Hand coordinates... Edited by TiagoCosta

Share this post


Link to post
Share on other sites

Wait a second. I just pop some figures out

Character Pos: x=-20.0 y=0.0 z=-50.0

Dolly Cam Pos: x=-20.0 y=5.0 z=-45.0

look at vector: x=0.0 y= -0.707 z= -0.707

Anything wrong with these figures?

 

 

 

It seems the look at vector is mirrored in the y axis, from looking down toward negative z to looking down toward positive z

 

 

 

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

From the Camera::Update methods (I mean those from the CD-ROM) it can be seen that

a) mvView is set to a world position which is targeted by the camera (mvTargetPosition, vGoadViewpoint, or similar), and

b) mvFacing is set to the direction to that target (normalized difference from mvPosition to mvView).

Later on in Camera::Look() one can see that mvVew is directly used as center argument for gluLookAt, which again means a target position (see e.g. manual page for gluLookAt).

 

The difference between 2 positions is calculated by subtracting the start position from the end position; TiagoCosta has mentioned it. However, the view direction of an unrotated camera is convention. It may look along any positive or negative axis! Since you adapt the source code for Ogre, you have to pick the convention as is used by Ogre, and compare that with the convention used in the article's source code; perhaps you have to adapt this part, too.

Edited by haegarr

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement