   Camera help
  I have a camera that I'm trying to rotate around a certain point.   D3DXVECTOR3 pos;double dx, dy, dz, radius;// Get radius (distance to target)dx = m_Pos.x - target.x;dy = m_Pos.y - target.y;dz = m_Pos.z - target.z;radius = sqrt(dx * dx + dy * dy + dz * dz);pos = m_Pos;// Move to target's positionMove(target.x, target.y, target.z);// Rotate cameraRotateRel(XAdd, YAdd, ZAdd);// Move camera away from target//Move(pos.x, pos.y, pos.z);The part I'm stuck on is moving the camera back away to its new position after being rotated at the target.  Can anyone help me?[edited by - TWild on February 10, 2004 10:49:06 PM]
  Any ideas? ;    You can create a vector pointing straight back in camera space (negative z if you''re using LH coords, out of the screen if not), then transform it by the inverse of your camera''s orientation to get the vector in world space.  Then scale the vector to the size of the radius and add it to the target position and you''ll have your new camera position. ;  The easiest way to explain it is to give you one.  Here''s my camera class.  It''s a first-person camera class so if you look up you can''t walk in that direction but if you look left and right you move in the direction your facing.To move the camera pass values to the "move" vectorThen every frame run the "UpdateCamera" function to move the cameraHere''s the ".h" file// BazCamera.h: interface for the CBazCamera class.////////////////////////////////////////////////////////////////////////#if !defined(AFX_BAZCAMERA_H__021BAB9A_FD9D_4EE8_BC43_A0045F19A226__INCLUDED_)#define AFX_BAZCAMERA_H__021BAB9A_FD9D_4EE8_BC43_A0045F19A226__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#include <d3d8.h>#include <d3dx8.h>#include "BazEngine.h"class CBazCamera : public CBazEngine  {public:float Version;float GetVersion();D3DXMATRIX *UpdateCamera();CBazCamera();virtual ~CBazCamera();D3DXVECTOR3 Position;D3DXVECTOR3 Move;D3DXVECTOR3 Look;};#endif // !defined(AFX_BAZCAMERA_H__021BAB9A_FD9D_4EE8_BC43_A0045F19A226__INCLUDED_)and here''s the ".cpp" file// BazCamera.cpp: implementation of the CBazCamera class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include <d3d8.h>#include <d3dx8.h>#include "BazEngine.h"#include "BazCan2Load.h"#include "BazCamera.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CBazCamera::CBazCamera(){Position.x = 0; Position.y = 0; Position.z = 0;Move.x = 0; Move.y = 0; Move.z = 0;Look.x = 0; Look.y = 0; Look.z = 0; //Version details////---------------Version = 1.00;}CBazCamera::~CBazCamera(){Position.x = 0; Position.y = 0; Position.z = 0;Move.x = 0; Move.y = 0; Move.z = 0;Look.x = 0; Look.y = 0; Look.z = 0;}//Build a camera matrix that represents the current angles and position//of the selected camera.D3DXMATRIX *CBazCamera::UpdateCamera(){//Build a camera matrixD3DXMATRIX mat = *D3DXMatrixIdentity(&mat;int pivot_distance = 250;Position.x = Position.x + ( Move.x * cos( D3DXToRadian(Look.x) ) );Position.y = Position.y + Move.y;Position.z = Position.z + ( Move.x * sin( D3DXToRadian(Look.x) ) );Position.x = Position.x + ( Move.z * sin( D3DXToRadian(Look.x) ) );Position.z = Position.z - ( Move.z * cos( D3DXToRadian(Look.x) ) );D3DXMatrixLookAtLH( &mat, &D3DXVECTOR3( Position.x + (pivot_distance * cos( D3DXToRadian(Look.x) ) * cos( D3DXToRadian(Look.y) ) ), Position.y + (pivot_distance * sin( D3DXToRadian(Look.y) ) ), Position.z + (pivot_distance * sin( D3DXToRadian(Look.x) ) * cos( D3DXToRadian(Look.y) ) ) ) ,  &D3DXVECTOR3( Position.x, Position.y, Position.z ),&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );D3DXMATRIX *pMat = &mat//Reset movement valuesMove.x = 0; Move.y = 0; Move.z = 0;return pMat;}float CBazCamera::GetVersion(){return Version;}There''s some stuff there that doesn''t need to be there but it works with it.If you want you can try it and get it working or just use it as a reference for yours.Hope it helpsmatt 