本文整理汇总了C++中Float3类的典型用法代码示例。如果您正苦于以下问题:C++ Float3类的具体用法?C++ Float3怎么用?C++ Float3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Float3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: XMVectorGetX
float Float3::Distance(const Float3& a, const Float3& b)
{
XMVECTOR x = a.ToSIMD();
XMVECTOR y = b.ToSIMD();
XMVECTOR length = XMVector3Length(XMVectorSubtract(x, y));
return XMVectorGetX(length);
}
示例2: GetTransform
void Blast::OnTriggerStay(EDGameCore::ICollider* thisCollider, EDGameCore::ICollider* otherCollider, const EDCollision::Contact& contact)
{
if( otherCollider->GetAttachedRigidBody() != 0 )
{
EDCollision::Contact contact2 = contact;
Float3 delta = otherCollider->GetTransform()->GetWorldMatrix().WAxis - GetTransform()->GetWorldMatrix().WAxis;
if( DotProduct( delta, contact.Normal ) < 0.0f )
contact2.negate();
float mag = delta.magnitude();
if( mag == 0.0f )
{
delta = Float3(0.0f, 1.0f, 0.0f);
mag = 1.0f;
}
else
delta *= (1.0f / mag);
delta *= 15000.0f / (mag*mag);
delta *= (1.0f / EDGameCore::Game::GetDeltaTime());
otherCollider->GetAttachedRigidBody()->ApplyForceAtPoint( delta, contact2.Point[0] );
}
}
示例3: objSpaceRay
Air::U1 MeshEntity::RayCast( const Ray& ray ,float* pOutDistance)
{
#if 1
if(!GetWorldBoundingBox().RayCast(ray.GetOrigin(),ray.GetDirection())){//.Intersect(GetWorldBoundingBox())){
return false;
}
#endif
Matrix matWorld = *GetWorldMatrix();
Matrix matWorldInv = matWorld;
matWorldInv.Inverse();
Float3 vStart = ray.m_vStart;
Float3 vLookAt = vStart + ray.m_vDirection;
vStart = matWorldInv*vStart;
vLookAt = matWorldInv*vLookAt;
Float3 vDir = (vLookAt - vStart);
vDir.Normalize();
Ray objSpaceRay(vStart,vDir);
float fDistance = 999999.0f;
U1 bHit = m_pMesh->RayCast(objSpaceRay,&fDistance);
if(bHit && pOutDistance!=NULL){
Float3 vObjSpaceHitPostion = vStart + vDir*fDistance;
Float3 vWorldSpaceHiPosition = matWorld*vObjSpaceHitPostion;
*pOutDistance = (vWorldSpaceHiPosition - ray.m_vStart).Length();
}
return bHit;
}
示例4: GetGameObject
void LookAt::LateUpdate() {
Transform* looker_transform = GetGameObject()->GetTransform();
Transform* target_transform = nullptr;
// Finds the target based on its instance id each update
// to avoid having a dangling pointer
// to an object that might have been destroyed.
target = GameObject::GetGameObjectInstance(targetId);
// TODO - comment this out and write your own solution
target_transform = target->GetTransform();
Float4x4 lookerMatrix = looker_transform->GetLocalMatrix();
Float4x4 targetMatrix = target_transform->GetLocalMatrix();
Float3 lookerPos = Float3(lookerMatrix.WAxis);
Float3 targetPos = Float3(targetMatrix.WAxis);
Float3 xAxis = ZERO_VECTOR;
Float3 yAxis = ZERO_VECTOR;
Float3 zAxis = (targetPos - lookerPos).normalize();
CrossProduct(xAxis, zAxis, Float3(0.0f, 1.0f, 0.0f));
xAxis.normalize();
CrossProduct(yAxis, zAxis, xAxis);
yAxis.normalize();
Float4x4 localMatrix = Float4x4(
xAxis.x, xAxis.y, xAxis.z, lookerMatrix.padX,
yAxis.x, yAxis.y, yAxis.z, lookerMatrix.padY,
zAxis.x, zAxis.y, zAxis.z, lookerMatrix.padZ,
lookerMatrix.WAxis.x, lookerMatrix.WAxis.y, lookerMatrix.WAxis.z, lookerMatrix.padW
);
looker_transform->SetLocalMatrix(localMatrix);
//LookAtSolution();
}
示例5: dir3
void SpotLight::ApplyLight()
{
// Set spot light position and direction
Float3 dir3(GetWorldMatrixPtr()->_31, GetWorldMatrixPtr()->_32, GetWorldMatrixPtr()->_33);
dir3.normalize();
XMFLOAT3 pos(&GetWorldMatrixPtr()->_41);
cBufferData.spotLight.direction = XMFLOAT3(dir3.x, dir3.y, dir3.z);
cBufferData.spotLight.position = pos;
D3D11_MAPPED_SUBRESOURCE edit;
Renderer::theContextPtr->Map(cBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &edit);
memcpy(edit.pData, &cBufferData, sizeof(cBufferData));
Renderer::theContextPtr->Unmap(cBuffer, 0);
Renderer::theContextPtr->VSSetConstantBuffers(cBufferData.SPOT_LIGHT_REGISTER_SLOT, 1, &cBuffer.p);
Renderer::theContextPtr->PSSetConstantBuffers(cBufferData.SPOT_LIGHT_REGISTER_SLOT, 1, &cBuffer.p);
// Check if the camera is inside the lit area
Float3 toCamera = ViewPortManager::GetReference().GetActiveViewPosition()
- *(Float3 *)&pos.x;
toCamera.normalize();
if(toCamera.dotProduct(dir3) > cBufferData.spotLight.cutoff)
techniqueNameOverride = "RenderSpotLightInside";
else
techniqueNameOverride = "RenderSpotLightOutside";
AddToContextSet();
}
示例6:
Air::U1 Actor::Move(float fTimeDelta)
{
if(m_MoveState==enAMS_NoMove){
return false;
}
Float3 vMoveDir = m_vMoveDir;
vMoveDir.y=0.0f;
vMoveDir.Normalize();
Float3 vOldPos = m_pNode->GetPosition();
Float3 vCurrentPos = m_pNode->GetPosition();
//vCurrentPos += vMoveDir*fSensitivity;
Float3 vNewVelocity = vMoveDir*m_fMoveVelocity;
vNewVelocity.y = m_vMoveDir.y;
PhysicsSystem::GetSingleton()->Silumation(vCurrentPos,0.5,1,vNewVelocity,fTimeDelta);
m_vMoveDir.y = vNewVelocity.y;
if(vCurrentPos.y<-1){
vCurrentPos.y=1;
m_vMoveDir.y = 0;
}
m_pNode->SetPosition(vCurrentPos);
return true;
}
示例7: RayCastTriangle
bool RayCastTriangle(const Float3& vStart,const Float3& vDir,const Float3& v0,const Float3& v1,const Float3& v2,float& fMaxDistance)
{
Float3 edge1 = v1 - v0;
Float3 edge2 = v2 - v0;
Float3 pvec = vDir.Cross(edge2);
float det = edge1.Dot( pvec );
float u, v, t;
Float3 tvec;
if(det > 0){
tvec = vStart - v0;
}else{
tvec = v0 - vStart;
det = -det;
}
u = tvec.Dot(pvec);
if(u<0.0f||u>det)
return false;
Float3 qvec = tvec.Cross(edge1);
v = vDir.Dot(qvec);
if(v<0.0f||u+v>det)
return false;
t = edge2.Dot(qvec)/det;
if(t<0.0f||t>fMaxDistance)
return false;
fMaxDistance = t;
//nor = cross(edge1,edge2);
return true;
};
示例8:
Float3<T> Float3<T>::slerp(const Float3 &end, T percent) const
{
T theta = static_cast<T>(std::acos(this->dot(end) / (this->length() * end.length())));
T sinThetaRecip = static_cast<T>(1.0 / std::sin(theta));
T beginScale = static_cast<T>(std::sin((1.0 - percent) * theta) * sinThetaRecip);
T endScale = static_cast<T>(std::sin(percent * theta) * sinThetaRecip);
return this->scaledBy(beginScale) + end.scaledBy(endScale);
}
示例9: _update
void PS_Light::_update(Particle * p)
{
Float3 Position = p->Position;
if (mParent->IsLocalSpace())
Position.TransformA(mParent->GetParent()->GetWorldTM());
mLight->SetPosition(Position);
mLight->SetDirection(p->Direction);
mLight->SetDiffuse(Float3(p->Color.r, p->Color.g, p->Color.b));
}
示例10: Float3
Air::Ray Frustum::BuildRay( Real x,Real y )
{
#if 0
POINT point;
point.x = x;
point.y = y;
Common::Matrix mInverseView = m_matView;
mInverseView.Inverse();
// Compute the vector of the pick ray in screen space
Float3 v;
v.x = ( ( ( 2.0f * point.x ) / m_iScreenWidth ) - 1 ) /m_matProj.m00;
v.y = -( ( ( 2.0f * point.y ) / m_iScreenHeight ) - 1 ) /m_matProj.m11;
//如果是右手坐标系 Z必须为-1 左手坐标系为1 切需注意
v.z = 1;//-m_ShaderParam.m_matProj[3][2];
Ray ray;
// Transform the screen space pick ray into 3D space
ray.m_vDirection.x = v.x * mInverseView.m00 + v.y * mInverseView.m10 + v.z * mInverseView.m20;
ray.m_vDirection.y = v.x * mInverseView.m01 + v.y * mInverseView.m11 + v.z * mInverseView.m21;
ray.m_vDirection.z = v.x * mInverseView.m02 + v.y * mInverseView.m12 + v.z * mInverseView.m22;
// //origin = m_vCurrentPosition;
ray.m_vStart = Float3(mInverseView.m30,mInverseView.m31,mInverseView.m32);
//Ray ray;
ray.m_vDirection.Normalize();
return ray;
#else
Matrix inverseVP = m_matViewProj;
inverseVP.Inverse();
Real nx = (2.0f * x) - 1.0f;
Real ny = 1.0f - (2.0f * y);
// Use midPoint rather than far point to avoid issues with infinite projection
Float3 midPoint (nx, ny, 0.0f);
// Get ray origin and ray target on near plane in world space
Float3 rayTarget;
rayTarget = inverseVP * midPoint;
Float3 rayDirection = rayTarget - GetPosition();
rayDirection.Normalize();
return Ray(GetPosition(),rayDirection);
#endif
}
示例11: Float3
void PS_Mesh::_update(Particle * p)
{
Float3 Position = p->Position;
if (mParent->IsLocalSpace())
Position.TransformA(mParent->GetParent()->GetWorldTM());
mMesh->SetPosition(Position);
mMesh->SetOpacity(p->Color.a);
mMesh->SetRotationEx(p->Rotation);
mMesh->SetScale(p->Size);
mMesh->_updateTM();
int blendMode = mParent->GetBlendMode();
for (int i = 0; i < mMesh->GetSubMeshCount(); ++i)
{
SubMesh * submesh = mMesh->GetSubMesh(i);
Material * mtl = submesh->GetMaterial();
mtl->diffuse = Float3(p->Color.r, p->Color.g, p->Color.b);
if (mParent->_getTexture() != NULL)
{
mtl->maps[eMapType::DIFFUSE] = mParent->_getTexture();
}
if (mParent->GetShaderEnable())
{
mtl->depthMode = eDepthMode::N_LESS_EQUAL;
if (blendMode == PS_BlendMode::ADD)
{
mtl->blendMode = eBlendMode::ADD;
}
else if (blendMode == PS_BlendMode::ALPHA_BLEND)
{
mtl->blendMode = eBlendMode::ALPHA_BLEND;
}
else if (blendMode == PS_BlendMode::COLOR_BLEND)
{
mtl->blendMode = eBlendMode::COLOR_BLEND;
}
else
{
mtl->blendMode = eBlendMode::OPACITY;
mtl->depthMode = eDepthMode::LESS_EQUAL;
}
submesh->SetShaderFX(mParent->_getShaderFX());
submesh->SetRenderCallBack(eRenderCallBack::SHADER, mParent->GetShader().c_ptr());
}
}
}
示例12: com
void Physics::OnUpdate(IBehavior* invokingBehavior, IMessage* message)
{
Physics* pPhysics = (Physics*)invokingBehavior;
const Aabb& objLocalAabb = pPhysics->gameObject->GetLocalAabb();
for(unsigned int i = 0; i < 3; ++i)
{
if( pPhysics->localAabb.min.v[i] != objLocalAabb.min.v[i] ||
pPhysics->localAabb.max.v[i] != objLocalAabb.max.v[i] )
{
pPhysics->Initialize();
return;
}
}
if( pPhysics->physicsFlags & GRAVITY )
{
Attribute<bool>* groundedAttrib = (Attribute<bool>*)pPhysics->GetAttribute(
PhysicsAttributes::GROUNDED_ATTRIB);
if( groundedAttrib->value == false )
pPhysics->ApplyGravity();
}
Float3 com(0.0f, 0.0f, 0.0f);
for(unsigned int i = 0; i < pPhysics->m_X.size(); ++i)
com += pPhysics->m_X[i];
com *= (1.0f / pPhysics->m_X.size());
pPhysics->ApplyVerlet();
pPhysics->ApplyConstraints();
Float3 newcom(0.0f, 0.0f, 0.0f);
for(unsigned int i = 0; i < pPhysics->m_X.size(); ++i)
newcom += pPhysics->m_X[i];
newcom *= (1.0f / pPhysics->m_X.size());
Float3 delta = newcom - com;
if( delta.magnitude() > 0.25f )
{
delta.normalize();
delta *= 0.25f;
}
pPhysics->gameObject->TranslateGlobal( delta );
}
示例13: SetMoveDirection
void Actor::SetMoveDirection( const Float3& v )
{
m_vMoveDir.x = v.x;
m_vMoveDir.z = v.z;
if(v.Length() <0.00001){
if(m_MoveState!=enAMS_NoMove){
m_pModel->SetActionState("stand.CAF");
m_MoveState = enAMS_NoMove;
}
}else{
float fRun = m_vMoveDir.Dot(m_vFaceDir);
if(fRun > 0){
if(m_MoveState!=enAMS_CustomRun){
m_MoveState = enAMS_CustomRun;
m_pModel->SetActionState("run.CAF");
}
}else{
if(m_MoveState!=enAMS_CustomBack){
m_MoveState = enAMS_CustomBack;
m_pModel->SetActionState("runback.CAF");
}
}
}
}
示例14: vMin
void BoundingVolume::GetSplitAxis(const float *pointsPtr, unsigned int numPoints,
Float3 &splitAxis, float &_min, float &_max)
{
Float3 vMin( FLT_MAX, FLT_MAX, FLT_MAX );
Float3 vMax( -FLT_MAX, -FLT_MAX, -FLT_MAX );
for(unsigned int i = 0; i < numPoints; i +=3 )
for(unsigned int j = 0; j < 3; ++j)
{
vMin.v[j] = min( vMin.v[j], pointsPtr[i+j] );
vMax.v[j] = max( vMax.v[j], pointsPtr[i+j] );
}
unsigned int axis = 0;
if( vMax.v[axis] - vMin.v[axis] < vMax.v[1] - vMin.v[1] )
axis = 1;
if( vMax.v[axis] - vMin.v[axis] < vMax.v[2] - vMin.v[2] )
axis = 2;
splitAxis.makeZero();
splitAxis.v[axis] = 1.0f;
_min = vMin.v[axis];
_max = vMax.v[axis];
}
示例15: viewMatrix
Float4x4 MatrixHelper::viewMatrix( const Float3 &pos, const Float3 &target, const Float3 &up ) {
Float3 vz = ( target - pos ).normalizeND();
Float3 vx = up.cross( vz ).normalizeND();
Float3 vy = vz.cross( vx ).normalizeND();
float px = -pos.dot( vx );
float py = -pos.dot( vy );
float pz = -pos.dot( vz );
return Float4x4(
vx.x, vy.x, vz.x, 0.0f,
vx.y, vy.y, vz.y, 0.0f,
vx.z, vy.z, vz.z, 0.0f,
px, py, pz, 1.0f
);
}