请帮我让相机跟随目标点。对于我公司的新原型项目,我已经 2 天无法完成。目前我有:
void Camera::followTargetPoint(CIwVec3 target, int32 distance, int32 height)
{
CIwVec3 viewSpaceLocation = (CIwVec3)IwGxGetModelViewMatrix().TransformVec(target);
IwTrace(SCOOTER, ("viewSpaceLocation: x: %d, y: %d, z: %d", viewSpaceLocation.x, viewSpaceLocation.y, viewSpaceLocation.z));
// set the viewspace origin to the camera location in viewspace
//IwGxSetViewSpaceOrg(&viewSpaceLocation);
CIwVec3 pos = CIwVec3(viewSpaceLocation.x, viewMatrix.t.y, viewSpaceLocation.z);
viewMatrix.SetTrans(pos);
//viewMatrix.LookAt(CIwVec3(0,0,-100), target, CIwVec3(0,-100,0));
IwGxSetViewMatrix(&viewMatrix);
}
这个方法在我的渲染器中调用,如:
p->Render();
cam->followTargetPoint(p->getModelMatrix().GetTrans(), 3, 100);
我需要的是第三人称视角相机,它位于由 followTargetPoint 方法指定的距离和高度。我只能使用此代码获得第一人称视图,因为当我尝试从目标向量的 z 坐标中减去距离时,我得到了一个闪烁的模型,我知道原因,但问题是我如何摆脱它?