本文整理汇总了C++中GameObject::GetBody方法的典型用法代码示例。如果您正苦于以下问题:C++ GameObject::GetBody方法的具体用法?C++ GameObject::GetBody怎么用?C++ GameObject::GetBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject::GetBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PhysicsObject
SeeSaw::SeeSaw(PlatformerScene* scenePtr, const float32 x, const float32 y) : PhysicsObject(x, y) {
b2Vec2 vertices[3];
vertices[0].Set(16, 32);
vertices[1].Set(0, 64);
vertices[2].Set(64, 64);
scenePtr->CreateTriangleGameObject(this, "res/textures/seesawrock.png", x, y, vertices, b2_staticBody);
body->SetFixedRotation(true);
GameObject* beam = new Log(scenePtr, x, y);
// Store the joint so it can be destroyed.
b2RevoluteJointDef jointDef;
jointDef.bodyA = body;
jointDef.bodyB = beam->GetBody();
jointDef.collideConnected = false;
joint = scenePtr->CreateRevoluteJoint(jointDef);
}
示例2: Render
void Minimap::Render(IDirect3DDevice9* pd3dDevice)
{
if (!m_Ok)
{
// Only render if initialization succeeded.
return;
}
// Find where the player is and which direction she is looking.
GameObject* goPlayer = g_database.Find(g_objectIDPlayer);
D3DXVECTOR3 const playerPos = goPlayer->GetBody().GetPos();
D3DXVECTOR3 const playerDir = goPlayer->GetBody().GetDir();
// Calculate the player position in minimap space.
// World space has one unit per square of the map, and is 25x25.
// Texture space is 0..1 for any texture.
// Minimap space is just texture space in the minimap texture.
// So we divide by 25 to world space to get minimap space.
//
// We also need to invert the Z coordinate because texture coordinates grow downwards.
float const px = playerPos.x / float(m_WorldFile.GetWidth());
float const py = 1.0f - playerPos.z / float(m_WorldFile.GetHeight());
// Figure out the vectors that point forward and right in minimap space.
//
// From a position in the center of the minimap, we reach the edge with a displacement of 0.5,
// so we'll divide by 2 (playerDir is a normalized vector, so the coordinates are [-1,1]).
// Also, we don't want to show the entire minimap, so we divide another 2 on top of that.
float const ZoomFactor = 4.0f; // Combined divisors.
float const forwardX = playerDir.x / ZoomFactor;
float const forwardY = -playerDir.z / ZoomFactor;
float const rightX = -forwardY; // 90 degree rotation.
float const rightY = forwardX;
// For the NPC, position will be enough.
GameObject* goNPC = g_database.FindByName("NPC1");
D3DXVECTOR3 const npcPos = goNPC->GetBody().GetPos();
// Find the dimensions of the viewport,
// so we can render the minimap in the correct location.
D3DVIEWPORT9 viewport = { 0 };
pd3dDevice->GetViewport(&viewport);
float const minimapX1 = float(viewport.X) + float(viewport.Width) * ( 1.0f / 32.0f);
float const minimapX2 = minimapX1 + float(viewport.Width) * ( 1.0f / 8.0f);
float const minimapY2 = float(viewport.Y) + float(viewport.Height) * (23.0f / 24.0f);
float const minimapY1 = minimapY2 - float(viewport.Height) * ( 1.0f / 6.0f);
float const minimapCenterX = (minimapX1 + minimapX2) / 2.0f;
float const minimapCenterY = (minimapY1 + minimapY2) / 2.0f;
float const minimapHalfSizeX = (minimapX2 - minimapX1) / 2.0f; //float(viewport.Width) * ( 1.0f / 16.0f);
float const minimapHalfSizeY = (minimapY2 - minimapY1) / 2.0f; //float(viewport.Height) * ( 1.0f / 12.0f);
// Save all of D3D's state.
m_pMinimapSaveStateBlock->Capture();
// Set some initial states that we'll want.
pd3dDevice->SetVertexShader(NULL);
pd3dDevice->SetPixelShader(NULL);
pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
{
// First, render the minimap itself. We'll use three simultaneous textures:
// 0 = minimap
// 1 = alpha mask
// 2 = beautifying frame
//
// The pixel pipeline formula will be:
//
// color = lerp(minimap.rgb, frame.rgb, frame.a)
// alpha = lerp(mask.a, 1, frame.a)
pd3dDevice->SetTexture (0, m_pMinimapTexture);
pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
pd3dDevice->SetTextureStageState(0, D3DTSS_RESULTARG, D3DTA_CURRENT);
pd3dDevice->SetSamplerState (0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
//.........这里部分代码省略.........
示例3: States
bool Example::States( State_Machine_Event event, MSG_Object * msg, int state, int substate )
{
BeginStateMachine
//Global message response section
OnMsg( MSG_Reset )
ResetStateMachine();
OnMsg( MSG_MouseClick )
m_owner->GetMovement().SetTarget( msg->GetVector3Data() );
///////////////////////////////////////////////////////////////
DeclareState( STATE_Initialize )
OnEnter
m_owner->GetMovement().SetIdleSpeed();
ChangeStateDelayed( 1.0f, STATE_Idle );
//m_owner->GetTiny().SetDiffuse(1.0f, 0.0f, 0.0f); //Color Tiny (Example)
///////////////////////////////////////////////////////////////
DeclareState( STATE_PickPlayerToChase )
OnEnter
m_owner->GetMovement().SetWalkSpeed();
m_curTarget = GetFarthestAgent();
if( m_curTarget == 0 ) {
ChangeState( STATE_MoveToRandomTarget );
}
SendMsgToStateMachineNow( MSG_SetTargetPosition );
OnMsg( MSG_SetTargetPosition )
GameObject* go = g_database.Find( m_curTarget );
if( go ) {
D3DXVECTOR3 target = go->GetBody().GetPos();
m_owner->GetMovement().SetTarget( target );
}
SendMsgToState( MSG_SetTargetPosition );
OnMsg( MSG_Arrived )
ChangeState( STATE_Idle );
///////////////////////////////////////////////////////////////
DeclareState( STATE_Idle )
OnEnter
m_owner->GetMovement().SetIdleSpeed();
if( rand()%2 == 0 ) {
ChangeStateDelayed( RandDelay( 1.0f, 2.0f ), STATE_MoveToRandomTarget );
}
else {
ChangeStateDelayed( RandDelay( 1.0f, 2.0f ), STATE_PickPlayerToChase );
}
///////////////////////////////////////////////////////////////
DeclareState( STATE_MoveToRandomTarget )
OnEnter
m_owner->GetMovement().SetJogSpeed();
D3DXVECTOR3 target( 0, 0, 0 );
target.x = (float) ( rand() % 256 ) / 256.f;
target.z = (float) ( rand() % 256 ) / 256.f;
m_owner->GetMovement().SetTarget( target );
OnMsg( MSG_Arrived )
ChangeState( STATE_Idle );
EndStateMachine
}