本文整理汇总了C++中PerspectiveCamera::GetDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ PerspectiveCamera::GetDistance方法的具体用法?C++ PerspectiveCamera::GetDistance怎么用?C++ PerspectiveCamera::GetDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerspectiveCamera
的用法示例。
在下文中一共展示了PerspectiveCamera::GetDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: forceGroundedView
void GridSystem::forceGroundedView(PerspectiveCamera &pc) {
float lookAt_distance = offset/2;
float old_distance = pc.GetDistance(); //need?
Vector3f _p = pc.getCameraLocation(); Vector3f p = _p - Vector3f(0, _p.y(), 0); //xz only
Vector3f _vec = pc.GetCenter() - p; Vector3f vec = _vec - Vector3f(0, _vec.y(), 0);
Vector3f lookAt = p + ((offset*2) * vec.normalized()); //from camera to lookAt direction (xz only)
Vector3f p_ground = Vector3f(p.x(), getYLevel(p.x(), p.z()) + 0.5f, p.z());
Vector3f lookAt_ground = Vector3f(lookAt.x(), getYLevel(lookAt.x(), lookAt.z()) + 0.5f, lookAt.z());
Vector3f nvec = (lookAt_ground - p_ground); //new camera location to new camera center
Vector3f lookAt_final = p_ground + (lookAt_distance * nvec.normalized());
//force distance to be at ground
pc.SetCenter(lookAt_final); //apply new camera center
//pc.SetCenter(lookAt_ground); //apply new camera center
/*if (pc.GetCenter().y() < lookAt_ground.y() - 0.2){
pc.SetCenter(lookAt_ground - Vector3f(0, 0.2, 0)); //apply new camera center
}
else if (pc.GetCenter().y() > lookAt_ground.y() + 0.2) {
pc.SetCenter(lookAt_ground + Vector3f(0, 0.2, 0));
}*/
//float lookAt_distance = sqrt(pow(nvec.x(), 2) + pow(nvec.y(), 2) + pow(nvec.z(), 2));
pc.SetDistance(lookAt_distance);
Vector3f rotaxis = Vector3f::cross(nvec, Vector3f::UP);
float angle_cur = atan((lookAt.y() - p_ground.y())/old_distance);
float angle_new = atan((lookAt_ground.y() - p_ground.y())/lookAt_distance);
float angle = angle_new - angle_cur;
pc.SetViewRotation(RotationMatrixOnAxis(angle, rotaxis.x(), rotaxis.y(), rotaxis.z()));
////set view to correct Z axis
//pc.SetCenter(lookAt_ground); //apply new camera center
//Vector3f nvec = (lookAt_ground - p_ground); //new camera location to new camera center (alrd applied)
////float lookAt_distance = sqrt(pow(nvec.x(), 2) + pow(nvec.y(), 2) + pow(nvec.z(), 2));
//float lookAt_distance = lookAtDistance;
//pc.SetDistance(lookAt_distance);
cout << "p:" << p_ground.x() << " " << p_ground.y() << " " << p_ground.z() << endl;
cout << "lookAt:" << lookAt_ground.x() << " " << lookAt_ground.y() << " " << lookAt_ground.z() << endl;
//cout << "test:" << test.x() << " " << test.y() << " " << test.z() << endl;
//cout << p.x() << " " << p.z() << " " << getYLevel(0.758, 0.875) << endl;
}