本文整理汇总了C++中vec3f::cross方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3f::cross方法的具体用法?C++ vec3f::cross怎么用?C++ vec3f::cross使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec3f
的用法示例。
在下文中一共展示了vec3f::cross方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lookTowards
/**
* LookTowards
*
* Note 1: Function will exit if front_vec is (close to) parallel to the Y-axis; supply your own up_vec if this is the case.
* Note 2: Not fully tested, use at own risk...
*
* Example:
* Make camera look at 'my_node'. Note that world space positions are used.
* camera->lookAt( my_node->getWorldPosition() - camera->getWorldPosition() );
*/
void Transformable::lookTowards(
vec3f front_vec,
vec3f up_vec
)
{
vec3f right;
vec3f up;
vec3f prev_up;
front_vec.normalize();
up_vec.normalize();
if (abs(up_vec.dot(front_vec)) > 0.99999f) {
return;
}
if (parent && parent->is_transformable) {
mat3f mat;
R = ((Transformable *) parent)->getWorldMatrix().rotationMatrix();
R.inv();
prev_up = up_vec;
right = front_vec.cross(prev_up);
up = right.cross(front_vec);
right.normalize();
up.normalize();
mat.setCol(0, right);
mat.setCol(1, up);
mat.setCol(2, -front_vec);
R = R * mat;
} else {
prev_up = up_vec;
right = front_vec.cross(prev_up);
up = right.cross(front_vec);
right.normalize();
up.normalize();
R.setCol(0, right);
R.setCol(1, up);
R.setCol(2, -front_vec);
}
}
示例2: setCamera
void DepthBuffer::setCamera(const mat44f& viewProjection,float znear,float zfar,float fov,vec3f cameraPos,vec3f cameraDir,vec3f cameraUp){
viewProjection_ = viewProjection;
znear_ = znear;
zfar_ = zfar;
fov_ = fov;
float aspect = float(size_.x)/float(size_.y);
cameraPos_ = cameraPos;
cameraDir_ = cameraDir;
vec3f cameraRight = cameraDir.cross(cameraUp).normalize();
cameraUp = cameraRight.cross(cameraDir);
//
auto upLength = tanf(fov/2.0f)*znear;
auto rightLength = upLength * (aspect);
cameraRight = cameraRight*rightLength;
cameraUp = cameraUp*upLength;
cameraRight_ = vec4f(cameraRight.x,cameraRight.y,cameraRight.z,1);
cameraUp_ = vec4f(cameraUp.x,cameraUp.y,cameraUp.z,1);
aabbFrontFaceMask = calculateBoxVisibleFaceMask(cameraDir);
}