本文整理汇总了C++中Mat4x4::SetPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat4x4::SetPosition方法的具体用法?C++ Mat4x4::SetPosition怎么用?C++ Mat4x4::SetPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat4x4
的用法示例。
在下文中一共展示了Mat4x4::SetPosition方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateTrigger
void BulletPhysics::CreateTrigger(WeakGameObjectPtr pGameObject, const Vec3& position, const float dim)
{
StrongGameObjectPtr pStrongObject = MakeStrongPtr(pGameObject);
if (!pStrongObject)
{
CB_ERROR("Must attach a game object to the trigger");
return;
}
// create the collision body
btBoxShape* boxShape = new btBoxShape(Vec3_to_btVector3(Vec3(dim, dim, dim)));
// 0 mass, this trigger is not moveable
const btScalar mass = 0;
// set the initial position of the trigger from the object
Mat4x4 triggerTransform = Mat4x4::Identity;
triggerTransform.SetPosition(position);
ObjectMotionState* motionState = CB_NEW ObjectMotionState(triggerTransform);
// create the rigid body
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, boxShape, btVector3(0, 0, 0));
btRigidBody* body = new btRigidBody(rbInfo);
// add the body to the world
m_DynamicsWorld->addRigidBody(body);
// mark the body as a trigger so it does not physically collide with object
body->setCollisionFlags(body->getCollisionFlags() | btRigidBody::CF_NO_CONTACT_RESPONSE);
// update the maps
m_ObjectIdToRigidBody[pStrongObject->GetId()] = body;
m_RigidBodyToObjectId[body] = pStrongObject->GetId();
}
示例2: VOnUpdate
//
// TeapotWarsGame::VOnUpdate - Chapter 19, page 709
//
void CometConquestGame::VOnUpdate(float time, float elapsedTime)
{
int deltaMilliseconds = int(elapsedTime * 1000.0f);
m_Lifetime += elapsedTime;
unsigned int currentTime = timeGetTime();
BaseGameLogic::VOnUpdate(time, elapsedTime);
if (m_bProxy)
return;
switch(m_State)
{
case BGS_LoadingGameEnvironment:
break;
case BGS_MainMenu:
break;
case BGS_WaitingForPlayers:
if (m_ExpectedPlayers + m_ExpectedRemotePlayers == m_HumanPlayersAttached )
{
VChangeState(BGS_LoadingGameEnvironment);
}
break;
case BGS_Running:
if(currentTime > (m_data.m_lastCometTime + 5000))
{
Vec4 at = -g_Right4 * 2.0f;
Vec4 atWorld = Mat4x4::g_Identity.Xform(at);
int randVertical = m_random.Random(115) + 1 - 60;
Vec3 normalDir(atWorld);
normalDir.Normalize();
Mat4x4 temp = Mat4x4::g_Identity;
temp.SetPosition(Vec3(110,10,randVertical));
CometParams cp;
cp.m_Pos = temp.GetPosition() + Vec3(atWorld);
cp.m_Radius = 6.0f;
cp.m_Color = g_Cyan;
cp.m_NormalDir = normalDir;
cp.m_Force = 40000.0f;
const EvtData_Request_New_Actor cannonBallEvt( &cp );
safeTriggerEvent( cannonBallEvt );
m_data.m_lastCometTime = currentTime;
}
break;
default:
assert(0 && _T("Unrecognized state."));
}
// look in Chapter 15, page 563 for more on this bit of code
if(m_pPhysics)
{
m_pPhysics->VOnUpdate(elapsedTime);
m_pPhysics->VSyncVisibleScene();
}
}
示例3: VPreRender
//
// SkyNode::VPreRender - Chapter 14, page 502
//
HRESULT SkyNode::VPreRender(Scene *pScene)
{
Vec3 cameraPos = m_camera->VGet()->ToWorld().GetPosition();
Mat4x4 mat = m_Props.ToWorld();
mat.SetPosition(cameraPos);
VSetTransform(&mat);
return SceneNode::VPreRender(pScene);
}
示例4: PreRender
HRESULT SkyNode::PreRender(Scene* pScene)
{
// get the camera position in world space
Vec3 cameraPos = m_Camera->Get()->ToWorld().GetPosition();
// get the sky node's world matrix
Mat4x4 mat = m_Properties.ToWorld();
// set the matrix's position to the camera position
mat.SetPosition(cameraPos);
SetTransform(&mat);
return SceneNode::PreRender(pScene);
}
示例5: SetPosition
void PhysicsComponent::SetPosition(float x, float y, float z)
{
shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
if (pTransformComponent)
{
Mat4x4 transform = pTransformComponent->GetTransform();
Vec3 position = Vec3(x, y, z);
transform.SetPosition(position);
KinematicMove(transform);
}
else
GCC_ERROR("Attempting to call RotateY() on actor with no trnasform component");
}
示例6: RotateY
void PhysicsComponent::RotateY(float angleRadians)
{
shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
if (pTransformComponent)
{
Mat4x4 transform = pTransformComponent->GetTransform();
Vec3 position = transform.GetPosition();
Mat4x4 rotateY;
rotateY.BuildRotationY(angleRadians);
rotateY.SetPosition(position);
KinematicMove(rotateY);
}
else
GCC_ERROR("Attempting to call RotateY() on actor with no transform component");
}
示例7: VOnUpdate
void WatchMeProcess::VOnUpdate(unsigned long deltaMs)
{
StrongActorPtr pTarget = MakeStrongPtr(g_pApp->m_pGame->VGetActor(m_target));
StrongActorPtr pMe = MakeStrongPtr(g_pApp->m_pGame->VGetActor(m_me));
shared_ptr<TransformComponent> pTargetTransform = MakeStrongPtr(pTarget->GetComponent<TransformComponent>(TransformComponent::g_Name));
shared_ptr<TransformComponent> pMyTransform = MakeStrongPtr(pMe->GetComponent<TransformComponent>(TransformComponent::g_Name));
if (!pTarget || !pMe || !pTargetTransform || !pMyTransform)
{
GCC_ERROR("This shouldn't happen");
Fail();
}
Vec3 targetPos = pTargetTransform->GetPosition();
Mat4x4 myTransform = pMyTransform->GetTransform();
Vec3 myDir = myTransform.GetDirection();
myDir = Vec3(0.0f, 0.0f, 1.0f);
Vec3 myPos = pMyTransform->GetPosition();
Vec3 toTarget = targetPos - myPos;
toTarget.Normalize();
float dotProduct = myDir.Dot(toTarget);
Vec3 crossProduct = myDir.Cross(toTarget);
float angleInRadians = acos(dotProduct);
if (crossProduct.y < 0)
angleInRadians = -angleInRadians;
Mat4x4 rotation;
rotation.BuildRotationY(angleInRadians);
rotation.SetPosition(myPos);
pMyTransform->SetTransform(rotation);
}
示例8: CreateGameObject
// create a game object from lua
int LuaInternalScriptExports::CreateGameObject(const char* objectArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{
// lua position must be a table
if (!luaPosition.IsTable())
{
CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaPosition.TypeName()));
return INVALID_GAMEOBJECT_ID;
}
// lua yawPitchRoll must be a table
if (!luaYawPitchRoll.IsTable())
{
CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaYawPitchRoll.TypeName()));
return INVALID_GAMEOBJECT_ID;
}
Vec3 position(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
Vec3 yawPitchRoll(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());
// build the transform for the object
Mat4x4 transform;
transform.BuildYawPitchRoll(yawPitchRoll.x, yawPitchRoll.y, yawPitchRoll.z);
transform.SetPosition(position);
// create the object
TiXmlElement* overloads = nullptr;
StrongGameObjectPtr pObject = g_pApp->m_pGame->CreateGameObject(objectArchetype, overloads, &transform);
// fire the new object created event
if (pObject)
{
shared_ptr<Event_NewGameObject> pNewObjectEvent(CB_NEW Event_NewGameObject(pObject->GetId()));
IEventManager::Get()->QueueEvent(pNewObjectEvent);
return pObject->GetId();
}
return INVALID_GAMEOBJECT_ID;
}
示例9: HandleEvent
//.........这里部分代码省略.........
m_CometConquest->redTeamScore();
}
}
if(AT_Ring == typeB && AT_Goal == typeA)
{
RingParams rp;
rp.m_StartPosition == static_cast<RingParams *>(pGameActorB->VGetParams().get())->m_StartPosition;
rp.m_Mat = rp.m_StartPosition;
const EvtData_Request_New_Actor requestRing (&rp);
safeTriggerEvent (requestRing);
m_CometConquest->VRemoveActor(pGameActorB->VGetID());
if(0 == static_cast<GoalParams*>(pGameActorA->VGetParams().get())->m_Team)
{
m_CometConquest->blueTeamScore();
}
else
{
m_CometConquest->redTeamScore();
}
}
}
else if ( EvtData_Thrust::sk_EventType == event.VGetEventType() )
{
const EvtData_Thrust & castEvent = static_cast< const EvtData_Thrust & >( event );
shared_ptr<IActor> pActor = m_CometConquest->VGetActor(castEvent.m_id);
if( pActor )
{
static const float newtonForce = 1.f;
float thrustForce = castEvent.m_throttle * newtonForce;
Mat4x4 rotation = pActor->VGetMat();
rotation.SetPosition(Vec3(0,0,0));
Vec3 dir = rotation.Xform(g_Forward);
dir.Normalize();
m_CometConquest->m_pPhysics->VApplyForce(dir, thrustForce, castEvent.m_id);
}
}
else if ( EvtData_Steer::sk_EventType == event.VGetEventType() )
{
static const float newtonForce = -.25 * 1.8f;
const EvtData_Steer & castEvent = static_cast< const EvtData_Steer & >( event );
float steerForce = -castEvent.m_dir * newtonForce;
m_CometConquest->m_pPhysics->VApplyTorque(Vec3(0,1,0), steerForce, castEvent.m_id);
}
else if ( EvtData_Fire_Weapon::sk_EventType == event.VGetEventType() )
{
if(!this->m_CometConquest->m_bProxy)
{
const EvtData_Fire_Weapon & castEvent = static_cast< const EvtData_Fire_Weapon & >( event );
ActorId gunnerId = castEvent.m_id;
shared_ptr<IActor> pGunner = m_CometConquest->VGetActor(gunnerId);
if (pGunner)
{
//Calculate depth offset from the controller
Vec4 at = g_Forward4 * 3.0f;
Vec4 atWorld = pGunner->VGetMat().Xform(at);
Vec3 normalDir(atWorld);
normalDir.Normalize();
BulletParams sp;
示例10: CreateActor
int InternalScriptExports::CreateActor(const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{
if (!luaPosition.IsTable())
{
GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaPosition.TypeName()));
return INVALID_ACTOR_ID;
}
if (!luaYawPitchRoll.IsTable())
{
GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaYawPitchRoll.TypeName()));
return INVALID_ACTOR_ID;
}
Vec3 pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
Vec3 ypr(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());
Mat4x4 initialTransform;
initialTransform.BuildYawPitchRoll(ypr.x, ypr.y, ypr.z);
initialTransform.SetPosition(pos);
TiXmlElement *overloads = NULL;
StrongActorPtr pActor = g_pApp->m_pGame->VCreateActor(actorArchetype, overloads, &initialTransform);
if (pActor)
{
shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId()));
IEventManager::Get()->VQueueEvent(pNewActorEvent);
return pActor->GetId();
}
return INVALID_ACTOR_ID;
}