•      Sign In
• Create Account

## Anyone guess what exactly all these mean?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1lucky6969b  Members

1188
Like
0Likes
Like

Posted 21 July 2014 - 02:01 AM

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

### #2TiagoCosta  Members

3598
Like
3Likes
Like

Posted 21 July 2014 - 04:04 AM

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, 21 July 2014 - 04:07 AM.

### #3JoeyDewd  Members

1180
Like
1Likes
Like

Posted 21 July 2014 - 04:11 AM

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.

### #4Matias Goldberg  Members

9074
Like
0Likes
Like

Posted 21 July 2014 - 10:22 AM

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.

Twitter: @matiasgoldberg

### #5Jason Z  Members

6417
Like
0Likes
Like

Posted 21 July 2014 - 08:18 PM

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!

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #6lucky6969b  Members

1188
Like
0Likes
Like

Posted 22 July 2014 - 02:39 AM

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()
{
}

### #7lucky6969b  Members

1188
Like
0Likes
Like

Posted 25 July 2014 - 08:02 PM

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, 26 July 2014 - 06:36 AM.

### #8TiagoCosta  Members

3598
Like
1Likes
Like

Posted 26 July 2014 - 04:24 AM

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, 26 July 2014 - 04:25 AM.

### #9lucky6969b  Members

1188
Like
0Likes
Like

Posted 26 July 2014 - 07:06 AM

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, 28 July 2014 - 03:08 AM.

### #10lucky6969b  Members

1188
Like
0Likes
Like

Posted 30 July 2014 - 01:25 AM

Hello,
Are there anything that doesn't look right here?
Thanks
Jack

### #11haegarr  Members

7189
Like
0Likes
Like

Posted 30 July 2014 - 01:50 AM

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, 30 July 2014 - 01:54 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.