Drakkhen Posted November 6, 2005 Posted November 6, 2005 Hi, I often noticed how external target tracking view can be a problem more than a solution when you totally loose view of your own plane and since I'm working on my own game engine, and my tracking camera doesn't loose neither own plane nor tracked target, even when changing focal (it was my job for eight years to code AIs and VG cams), I give you my own engine's camera ext-tracking behaviour routine source (do whatever you want with it, I'll make the engine GNU): (Alpha is cam elevation angle from [plane to target] line) (Gamma is angle between cam sight and [cam to plane] line) void DrKkCameraman::EvolveTargetTracking() { if(!(SelectedObject && SelectedObject->Target[0])) { // Here I switch cam back to plane pursuit behaviour CameraEvolve=EvolveFollowObject; return; } Vec3D LngCmp=SelectedObject->Pos-SelectedObject->Target[0]->Entity->Pos; float Dist=LngCmp.Magn(); if(Dist!=0.f) LngCmp/=Dist; Vec3D OrtCmp=(LngCmp^(Vec3D(0.f,0.f,1.f)^LngCmp)).Unit(); // ^ stands for vectorial product // Unit makes the vector magnitude 1 float Gamma=Fov*.6f; // Fov in Rad float Alpha=Gamma+Gamma/(1.f+Dist); Pos=SelectedObject->Pos+(LngCmp*cosf(Alpha)+OrtCmp*sinf(Alpha))*30.f; // The camera moves on a 30m radius circle around own plane float Delta=Alpha+Pi-Gamma*.5f; Dir.OrientateYZ(LngCmp*cosf(Delta)+OrtCmp*sinf(Delta),Vec3D(0.f,0.f,1.f)); // Dir is cameraman's orientation matrix // OrientateYZ forces dir's Y (sight) to the first vector // and brings Z as close to second as it can (two vectorial products behind) } It works with ]0;Pi[ focal angles. Never looses sight on both plane and target. The routine may be a bit heavier than yours to compute but it's only once a frame... so... "Heroism is the only way to get famous when you got no talent" Pierre Desproges "Whether fifty millions people say a stupid thing, it's still a stupid thing." Anatole France
Recommended Posts