本文整理汇总了C++中AVector::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ AVector::Normalize方法的具体用法?C++ AVector::Normalize怎么用?C++ AVector::Normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AVector
的用法示例。
在下文中一共展示了AVector::Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Orthonormalize
//----------------------------------------------------------------------------
void AVector::Orthonormalize (AVector& vec0, AVector& vec1, AVector& vec2)
{
// If the input vectors are v0, v1, and v2, then the Gram-Schmidt
// orthonormalization produces vectors u0, u1, and u2 as follows,
//
// u0 = v0/|v0|
// u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
// u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1|
//
// where |A| indicates length of vector A and A*B indicates dot
// product of vectors A and B.
// Compute u0.
vec0.Normalize();
// Compute u1.
float dot0 = vec0.Dot(vec1);
vec1 -= dot0*vec0;
vec1.Normalize();
// Compute u2.
float dot1 = vec1.Dot(vec2);
dot0 = vec0.Dot(vec2);
vec2 -= dot0*vec0 + dot1*vec1;
vec2.Normalize();
}
示例2: GetPickRay
//----------------------------------------------------------------------------
bool Camera::GetPickRay(float posSizePercentWdith, float posSizePercentHeight,
APoint& origin, AVector& direction)
{
// Get the [0,1]^2-normalized coordinates of (x,y).
float r = posSizePercentWdith;
float u = posSizePercentHeight;
// Get the relative coordinates in [rmin,rmax]x[umin,umax].
float rBlend = (1.0f - r)*GetRMin() + r*GetRMax();
float uBlend = (1.0f - u)*GetUMin() + u*GetUMax();
if (IsPerspective())
{
origin = GetPosition();
direction = GetDMin()*GetDVector() +
rBlend*GetRVector() + uBlend*GetUVector();
direction.Normalize();
}
else
{
origin = GetPosition() + rBlend*GetRVector() +
uBlend*GetUVector();
direction = GetDVector();
direction.Normalize();
}
return true;
}
示例3: GetData
//----------------------------------------------------------------------------
void PhysicsModule::GetData (APoint& center, HMatrix& incrRot) const
{
// Position is a point exactly on the hill.
APoint position;
position[0] = (float)(A1*mState[0]);
position[1] = (float)(A2*mState[2]);
position[2] = (float)(A3 - mState[0]*mState[0] - mState[2]*mState[2]);
// Lift this point off the hill in the normal direction by the radius of
// the ball so that the ball just touches the hill. The hill is
// implicitly specified by F(x,y,z) = z - [a3 - (x/a1)^2 - (y/a2)^2]
// where (x,y,z) is the position on the hill. The gradient of F is a
// normal vector, Grad(F) = (2*x/a1^2,2*y/a2^2,1).
AVector normal;
normal[0] = 2.0f*position[0]/(float)mAux[0];
normal[1] = 2.0f*position[1]/(float)mAux[1];
normal[2] = 1.0f;
normal.Normalize();
center = position + ((float)Radius)*normal;
// Let the ball rotate as it rolls down hill. The axis of rotation is
// the perpendicular to hill normal and ball velocity. The angle of
// rotation from the last position is A = speed*deltaTime/radius.
AVector velocity;
velocity[0] = (float)(A1*mState[1]);
velocity[1] = (float)(A1*mState[3]);
velocity[2] = -2.0f*(velocity[0]*(float)mState[0] +
velocity[1]*(float)mState[2]);
float speed = velocity.Normalize();
float angle = speed*((float)mDeltaTime)/((float)Radius);
AVector axis = normal.UnitCross(velocity);
incrRot = HMatrix(axis, angle);
}
示例4: SetFace
//----------------------------------------------------------------------------
void Actor::SetFace(const AVector &dir, const AVector &uping)
{
AVector right = dir.Cross(uping);
right.Normalize();
AVector up = right.Cross(dir);
up.Normalize();
Matrix3f matRot(right, dir, up, true);
LocalTransform.SetRotate(matRot);
}
示例5: Binormal
//----------------------------------------------------------------------------
AVector CurveSegment::Binormal (float u) const
{
AVector velocity = PU(u);
AVector acceleration = PUU(u);
float VDotV = velocity.Dot(velocity);
float VDotA = velocity.Dot(acceleration);
AVector normal = VDotV*acceleration - VDotA*velocity;
normal.Normalize();
velocity.Normalize();
AVector binormal = velocity.Cross(normal);
return binormal;
}
示例6: GetFrame
//----------------------------------------------------------------------------
void CurveSegment::GetFrame (float u, APoint& position, AVector& tangent,
AVector& normal, AVector& binormal) const
{
position = P(u);
AVector velocity = PU(u);
AVector acceleration = PUU(u);
float VDotV = velocity.Dot(velocity);
float VDotA = velocity.Dot(acceleration);
normal = VDotV*acceleration - VDotA*velocity;
normal.Normalize();
tangent = velocity;
tangent.Normalize();
binormal = tangent.Cross(normal);
}
示例7: Flee
//----------------------------------------------------------------------------
AVector SteeringBehavior::Flee (APoint fromPosition)
{
AVector desiredVelocity = mActor->GetPosition() - fromPosition;
desiredVelocity.Normalize();
return (desiredVelocity - mActor->GetVelocity());
}
示例8: OnCtrlChanged
//----------------------------------------------------------------------------
void CurveCtrlFloat::OnCtrlChanged (bool updateCurve)
{
if (mIndex >= (int)(mCurveFloat->mCurve->Points.size()))
return;
float inVal = mCurveFloat->mCurve->Points[mIndex].InVal;
float outVal = mCurveFloat->mCurve->Points[mIndex].OutVal;
float arriveTangent = mCurveFloat->mCurve->Points[mIndex].ArriveTangent;
float leaveTangent = mCurveFloat->mCurve->Points[mIndex].LeaveTangent;
InterpCurveMode mode = mCurveFloat->mCurve->Points[mIndex].InterpMode;
mInVal = inVal;
mOutVal = Float3(inVal, 0.0f, outVal);
AVector at(1.0f, 0.0f, arriveTangent);
at.Normalize();
mArriveTangent = at;
AVector lt (1.0f, 0.0f, leaveTangent);
lt.Normalize();
mLeaveTangent = lt;
mInterpCurveMode = mode;
CurveCtrl::OnCtrlChanged(updateCurve);
}
示例9: _RolateCamera
//----------------------------------------------------------------------------
void EditRenderView_Scene::_RolateCamera(float horz, float vert)
{
Scene *scene = PX2_PROJ.GetScene();
CameraActor *camActor = scene->GetUseCameraActor();
if (VT_PERSPECTIVE == mViewType)
{
AVector rVector;
AVector dVector;
AVector uVector;
camActor->GetRDUVector(rVector, dVector, uVector);
// horz
HMatrix incrH(AVector::UNIT_Z, -horz*0.5f);
dVector = incrH * dVector;
uVector = incrH * uVector;
rVector = incrH * rVector;
// vert
Matrix3f kIncrV(rVector, -vert*0.5f);
dVector = kIncrV * dVector;
uVector = kIncrV * uVector;
dVector.Normalize();
float dVectorAdj = dVector.Dot(AVector::UNIT_Z);
float dVectorAdj1 = dVector.Dot(-AVector::UNIT_Z);
if (dVectorAdj > 0.9f || dVectorAdj1 > 0.9f)
return;
AVector::Orthonormalize(dVector, uVector, rVector);
camActor->LocalTransform.SetRotate(HMatrix(rVector, dVector,
uVector, AVector::ZERO, true));
}
}
示例10: Seek
AVector SteeringBehavior::Seek (APoint toPosition)
{
AVector desiredVelocity = mActor->GetPosition() - actorPosition;
desiredVelocity.Normalize();
desiredVelocity *= mActor->GetMaxSpeed();
return (desiredVelocity - mActor->GetVelocity());
}
示例11: _MoveCamera
//----------------------------------------------------------------------------
void EU_CanvasStage::_MoveCamera(float horz, float vert)
{
if (!Project::GetSingletonPtr()) return;
Scene *scene = PX2_PROJ.GetScene();
if (!scene) return;
if (mStageCameraNode)
{
APoint position = mStageCameraNode->LocalTransform.GetTranslate();
AVector rVector;
AVector dVector;
AVector uVector;
mStageCameraNode->LocalTransform.GetRDUVector(rVector, dVector, uVector);
if (mViewType == VT_PERSPECTIVE)
{
dVector.Z() = 0.0f;
dVector.Normalize();
rVector.Z() = 0.0f;
rVector.Normalize();
position += dVector * vert;
position -= rVector * horz;
}
else if (mViewType == VT_TOP)
{
position.Y() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
else if (mViewType == VT_LEFT)
{
position.Z() += vert * 1.0f;
position.Y() += horz * 1.0f;
}
else if (mViewType == VT_FRONT)
{
position.Z() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
mStageCameraNode->LocalTransform.SetTranslate(position);
}
}
示例12: _MoveCamera
//----------------------------------------------------------------------------
void EditRenderView_Scene::_MoveCamera(float horz, float vert)
{
Scene *scene = PX2_PROJ.GetScene();
if (!scene) return;
CameraActor *camActor = scene->GetUseCameraActor();
if (camActor)
{
APoint position = camActor->LocalTransform.GetTranslate();
AVector rVector;
AVector dVector;
AVector uVector;
camActor->GetRDUVector(rVector, dVector, uVector);
if (mViewType == VT_PERSPECTIVE)
{
dVector.Z() = 0.0f;
dVector.Normalize();
rVector.Z() = 0.0f;
rVector.Normalize();
position += dVector * vert;
position -= rVector * horz;
}
else if (mViewType == VT_TOP)
{
position.Y() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
else if (mViewType == VT_LEFT)
{
position.Z() += vert * 1.0f;
position.Y() += horz * 1.0f;
}
else if (mViewType == VT_FRONT)
{
position.Z() += vert * 1.0f;
position.X() -= horz * 1.0f;
}
camActor->LocalTransform.SetTranslate(position);
}
}
示例13: MoveCamera
//----------------------------------------------------------------------------
void GamePlayApp::MoveCamera (Camera *cam, const float &horz,
const float &vert)
{
if (!cam)
return;
Vector3f position = cam->GetPosition();
AVector dVector = cam->GetDVector();
AVector uVector = cam->GetUVector();
AVector rVector = cam->GetRVector();
dVector.Z() = 0.0f;
dVector.Normalize();
rVector.Z() = 0.0f;
rVector.Normalize();
position += dVector * vert;
position += rVector * horz;
cam->SetPosition(position);
}
示例14: GetFace
//----------------------------------------------------------------------------
AVector Actor::GetFace()
{
HMatrix matRot = LocalTransform.GetRotate();
HPoint dir;
matRot.GetColumn(1, dir);
AVector vecDir = AVector(dir[0], dir[1], dir[2]);
vecDir.Normalize();
return vecDir;
}
示例15: GetPickRay
//----------------------------------------------------------------------------
bool RenderStep::GetPickRay(float x, float y, APoint& origin, AVector& direction)
{
if (!mCamera) return false;
Rectf viewPort = mViewPort;
if (viewPort.IsEmpty())
viewPort = Rectf(0.0f, 0.0f, mSize.Width, mSize.Height);
if (viewPort.IsEmpty()) return false;
// Get the current viewport and test whether (x,y) is in it.
float viewX = viewPort.Left;
float viewY = viewPort.Bottom;
float viewW = viewPort.Width();
float viewH = viewPort.Height();
// Get the [0,1]^2-normalized coordinates of (x,y).
float r = ((float)(x - viewX)) / (float)viewW;
float u = ((float)(y - viewY)) / (float)viewH;
// Get the relative coordinates in [rmin,rmax]x[umin,umax].
float rBlend = (1.0f - r)*mCamera->GetRMin() + r*mCamera->GetRMax();
float uBlend = (1.0f - u)*mCamera->GetUMin() + u*mCamera->GetUMax();
if (mCamera->IsPerspective())
{
origin = mCamera->GetPosition();
direction = mCamera->GetDMin()*mCamera->GetDVector() +
rBlend*mCamera->GetRVector() + uBlend*mCamera->GetUVector();
direction.Normalize();
}
else
{
origin = mCamera->GetPosition() + rBlend*mCamera->GetRVector() +
uBlend*mCamera->GetUVector();
direction = mCamera->GetDVector();
direction.Normalize();
}
return true;
}