Original Post
Hi guys,
Hoping you guys can help me understand my 3D camera better.
I have it implemented and it works perfectly.
But there is just one section of code that I do not fully understand, and I hope you guys can clarify for me.
I have followed the code from "http://www.toymaker.info/Games/html/camera.html"
Now I understand that the dot product of 2 vectors will return a scalar value that tells me how similar the 2 vectors are.
And that the subtraction is there because basically I need to get the position of the camera to be at the origin. (eg 5 - 5 = 0, ok np's this makes sense)
I just do not know how the scalar value relates to the camera's position though?
Many thanks for the assistance guys :)
[Edited by - tenpoundbear on August 6, 2010 4:41:02 AM]
Hoping you guys can help me understand my 3D camera better.
I have it implemented and it works perfectly.
But there is just one section of code that I do not fully understand, and I hope you guys can clarify for me.
I have followed the code from "http://www.toymaker.info/Games/html/camera.html"
// ======= CAMERA HEADER ======== //#ifndef CAMERA_H#define CAMERA_H#include <d3dx9.h>class Camera{public: Camera(); void updateViewMatrix( IDirect3DDevice9** D3DDevice ); void lookAtPos( D3DXVECTOR3* Position, D3DXVECTOR3* LookAt, D3DXVECTOR3* Up ); void setPosition( float x, float y, float z ); void setCamView( IDirect3DDevice9** D3DDevice, D3DXVECTOR3, D3DXVECTOR3, D3DXVECTOR3 ); void setCamProj( IDirect3DDevice9** D3DDevice, float w, float h ); D3DXVECTOR3 getPosition(); void roll( float angle ); void yaw( float angle ); void pitch( float angle ); void strafe( float amount ); void fly( float amount ); void mouseStrafe( float xAmount, float yAmount ); void mouseLook( float xAmount, float yAmount ); void moveForward( float amount );protected: D3DXVECTOR3 position; // Represent camera position. D3DXVECTOR3 lookAt; // Represent camera lookAt orientation. D3DXVECTOR3 right; // Represent camera right orientation. D3DXVECTOR3 up; //Represent camera up orientation. float pitchAmount; // Rotate around the X axis. float yawAmount; // Rotate arounf the Y axis. float rollAmount; // Rotate around the Z axis. D3DXMATRIX viewTransformMatrix;};#endif// ========= HEADER END ========== //// ========= updateViewMatrix() function ============= //......float x = -D3DXVec3Dot( &right, &position );float y = -D3DXVec3Dot( &up, &position );float z = -D3DXVec3Dot( &lookAt, &position );viewTransformMatrix._11 = right.x;viewTransformMatrix._12 = up.x;viewTransformMatrix._13 = lookAt.x;viewTransformMatrix._21 = right.y;viewTransformMatrix._22 = up.y;viewTransformMatrix._23 = lookAt.y;viewTransformMatrix._31 = right.z;viewTransformMatrix._32 = up.z;viewTransformMatrix._33 = lookAt.z;// ===== I DON'T FULLY UNDERSTAND THIS PART ========= //viewTransformMatrix._41 = x;viewTransformMatrix._42 = y;viewTransformMatrix._43 = z;Now I understand that the dot product of 2 vectors will return a scalar value that tells me how similar the 2 vectors are.
And that the subtraction is there because basically I need to get the position of the camera to be at the origin. (eg 5 - 5 = 0, ok np's this makes sense)
I just do not know how the scalar value relates to the camera's position though?
Many thanks for the assistance guys :)
[Edited by - tenpoundbear on August 6, 2010 4:41:02 AM]