本文整理汇总了C++中vec3f::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3f::normalize方法的具体用法?C++ vec3f::normalize怎么用?C++ vec3f::normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec3f
的用法示例。
在下文中一共展示了vec3f::normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:
vec3f vec3f::random(){
static vec3f rnd;
rnd.x=random_double()*2-1;
rnd.y=random_double()*2-1;
rnd.z=random_double()*2-1;
rnd.normalize();
return rnd;
}
示例3: accumulateForce
bool Entity::accumulateForce(vec3f steeringToAdd)
{
float forceUsed = mSteeringForce.getLength();
float forceRemaining = mMaxForce - forceUsed;
if (forceRemaining <= 0)
return false;
float forceToAdd = steeringToAdd.getLength();
if (forceToAdd < forceRemaining)
{
mSteeringForce += steeringToAdd;
}
else
{
steeringToAdd.normalize();
mSteeringForce += steeringToAdd * forceRemaining;
}
return true;
}
示例4: setVelocity
void Entity::setVelocity(vec3f velocity)
{
velocity.normalize();
mVelocity = velocity * mMaxSpeed;
}