本文整理汇总了C++中BoundingSphere::normal方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingSphere::normal方法的具体用法?C++ BoundingSphere::normal怎么用?C++ BoundingSphere::normal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundingSphere
的用法示例。
在下文中一共展示了BoundingSphere::normal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resolve_Sphere_AABB_collision_event
void Physics::resolve_Sphere_AABB_collision_event( RigidBody* sphere_body, RigidBody* aabb_body ) {
BoundingSphere* bsphere = static_cast<BoundingSphere*>( sphere_body->bv() );
AABB* aabb = static_cast<AABB*>( aabb_body->bv() );
bsphere->center = sphere_body->pose.position;
aabb->center = aabb_body->pose.position;
if( aabb_body->rigidbody_type == RIGIDBODY_STATIC ) {
Vector3 aabbpt;
BoundingVolume::ClosestPtPointAABB( bsphere->center, *aabb, aabbpt );
Vector3 sphere_normal, aabb_normal;
sphere_normal = bsphere->normal( aabbpt );
aabb_normal = aabb->normal( aabbpt );
Vector3 dir_sphere = sphere_body->linear_velocity;
dir_sphere.normalize();
Vector3 axis = Vector3::cross( -dir_sphere, aabb_normal );
axis.normalize();
double theta = acos( Vector3::dot( -dir_sphere, aabb_normal ) );
const double EPSILON = 1e-5;
// Note: theta != theta -> theta = NaN
if( theta != theta || theta < EPSILON ) {
// reflection backward toward incoming direction so just flip incoming vector
sphere_body->linear_momentum = -sphere_body->linear_momentum;
// Note: in continuous contact with multiple contact points, this will ultimately be
// unstable, but sphere has one point of contact with rigid bodies, so this is
// basically an impulse away of the same momentum that was applied to incoming so
// there is equilibrium in this particular configuration
sphere_body->linear_momentum *= sphere_body->coefficient_of_restitution;
sphere_body->angular_momentum *= sphere_body->coefficient_of_restitution;
} else {
// otherwise use axis angle to reflect by 2 * theta
// Note: 2 * theta -> q terms are theta not theta/2
Quaternion q = Quaternion( cos(theta), axis.x() * sin(theta), axis.y() * sin(theta), axis.z() * sin(theta) );
Matrix3 R = q.matrix3();
sphere_body->linear_momentum = R * -sphere_body->linear_momentum;
sphere_body->linear_momentum *= sphere_body->coefficient_of_restitution;
sphere_body->angular_momentum *= sphere_body->coefficient_of_restitution;
}
} else if( aabb_body->rigidbody_type == RIGIDBODY_DYNAMIC ) {
// to be determined. Not essential for lab3
}
}