本文整理匯總了C++中Collision函數的典型用法代碼示例。如果您正苦於以下問題:C++ Collision函數的具體用法?C++ Collision怎麽用?C++ Collision使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Collision函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Collision
Collision CollisionManager::collideWithMapPieceAndMovableObjects( Entity *e )
{
dFloat contacts[16] = {0.0f};
dFloat normals[16] = {0.0f};
dFloat penetration[16] = {0.0f};
Collision col = Collision(false,normals,contacts,penetration);
Vector3 pos = e->getParentSceneNode()->_getFullTransform().getTrans();
Entity* ents[5];
mp->getEntitiesForCollisionFromAPosition( &pos, ents );
for( int i = 0; i < 5; i++ )
{
if( ents[i] != NULL)
{
col = cd->staicAndDynamicCollision( e, ents[i], false );
if( col.isCollided ) return col;
}
}
for(std::vector<Entity*>::const_iterator it=movableObj.begin();it!=movableObj.end(); ++it)
{
col = cd->staicAndDynamicCollision( e, *it, true);
if( col.isCollided ) return col;
}
return col;
}
示例2: Collision
void CWeaponProjectile::Collision(CFeature* feature)
{
if(gs->randFloat()>weaponDef->fireStarter)
feature->StartFire();
Collision();
}
示例3: mapCollision
//only to be used with map pieces where the second element is not transformed
Collision CollisionDetection::staicAndDynamicCollision(Entity *e1, Entity *e2, bool dynamic)
{
dFloat e1Matrix[16];
dFloat e2Matrix[16];
NewtonCollision *e1Collision;
NewtonCollision *e2Collision;
std::map<Entity *,NewtonCollision *>::const_iterator iter =
collisionsMap.find(e1);
if(iter != collisionsMap.end()) {
e1Collision=iter->second;
} else {
cout<<"in mapCollision(e1,e2) the collision mesh for enitiy e1 could not be found in (C++)map"<< endl;
dFloat contacts[16] = {0.0f};
dFloat normals[16] = {0.0f};
dFloat penetration[16] = {0.0f};
return Collision(false,normals,contacts,penetration);
}
iter = collisionsMap.find(e2);
if(iter != collisionsMap.end()) {
e2Collision=iter->second;
} else {
cout<<"in mapCollision(e1,e2) collision mesh for mapEnitiy e2 could not be found in (C++)map"<<endl;
dFloat contacts[16] = {0.0f};
dFloat normals[16] = {0.0f};
dFloat penetration[16] = {0.0f};
return Collision(false,normals,contacts,penetration);;
}
getMatrix(e1,e1Matrix, true); //allwarys transform
getMatrix(e2,e2Matrix, dynamic); //transfrom second entity only if not static
dFloat contacts[16];
dFloat normals[16];
dFloat penetration[16];
int numCollisionPoints = NewtonCollisionCollide (newtonWorld, 1,
e1Collision, &e1Matrix[0],
e2Collision, &e2Matrix[0],
&contacts[0], &normals[0], &penetration[0], 0);
if (numCollisionPoints > 0) {
return Collision(true,normals,contacts,penetration);
} else {
return Collision(false,normals,contacts,penetration);
}
}
示例4: while
void CParticles::Update(float TimePassed)
{
static float FrictionFraction = 0;
FrictionFraction += TimePassed;
if(FrictionFraction > 2.0f) // safty messure
FrictionFraction = 0;
int FrictionCount = 0;
while(FrictionFraction > 0.05f)
{
FrictionCount++;
FrictionFraction -= 0.05f;
}
for(int g = 0; g < NUM_GROUPS; g++)
{
int i = m_aFirstPart[g];
while(i != -1)
{
int Next = m_aParticles[i].m_NextPart;
//m_aParticles[i].vel += flow_get(m_aParticles[i].pos)*time_passed * m_aParticles[i].flow_affected;
m_aParticles[i].m_Vel.y += m_aParticles[i].m_Gravity*TimePassed;
for(int f = 0; f < FrictionCount; f++) // apply friction
m_aParticles[i].m_Vel *= m_aParticles[i].m_Friction;
// move the point
vec2 Vel = m_aParticles[i].m_Vel*TimePassed;
Collision()->MovePoint(&m_aParticles[i].m_Pos, &Vel, 0.1f+0.9f*frandom(), NULL);
m_aParticles[i].m_Vel = Vel* (1.0f/TimePassed);
m_aParticles[i].m_Life += TimePassed;
m_aParticles[i].m_Rot += TimePassed * m_aParticles[i].m_Rotspeed;
// check particle death
if(m_aParticles[i].m_Life > m_aParticles[i].m_LifeSpan)
{
// remove it from the group list
if(m_aParticles[i].m_PrevPart != -1)
m_aParticles[m_aParticles[i].m_PrevPart].m_NextPart = m_aParticles[i].m_NextPart;
else
m_aFirstPart[g] = m_aParticles[i].m_NextPart;
if(m_aParticles[i].m_NextPart != -1)
m_aParticles[m_aParticles[i].m_NextPart].m_PrevPart = m_aParticles[i].m_PrevPart;
// insert to the free list
if(m_FirstFree != -1)
m_aParticles[m_FirstFree].m_PrevPart = i;
m_aParticles[i].m_PrevPart = -1;
m_aParticles[i].m_NextPart = m_FirstFree;
m_FirstFree = i;
}
i = Next;
}
}
}
示例5: clamp
void CControls::ClampMousePos()
{
if(m_pClient->m_Snap.m_SpecInfo.m_Active && !m_pClient->m_Snap.m_SpecInfo.m_UsePosition)
{
m_MousePos[g_Config.m_ClDummy].x = clamp(m_MousePos[g_Config.m_ClDummy].x, 200.0f, Collision()->GetWidth()*32-200.0f);
m_MousePos[g_Config.m_ClDummy].y = clamp(m_MousePos[g_Config.m_ClDummy].y, 200.0f, Collision()->GetHeight()*32-200.0f);
}
else
{
float CameraMaxDistance = 200.0f;
float FollowFactor = g_Config.m_ClMouseFollowfactor/100.0f;
float MouseMax = min(CameraMaxDistance/FollowFactor + g_Config.m_ClMouseDeadzone, (float)g_Config.m_ClMouseMaxDistance);
if(length(m_MousePos[g_Config.m_ClDummy]) > MouseMax)
m_MousePos[g_Config.m_ClDummy] = normalize(m_MousePos[g_Config.m_ClDummy])*MouseMax;
}
}
示例6: Collision
void player::update(float time)
{
rect.left +=dx*time;
Collision(0);
rect.top += dy*time;
Collision(1);
Regeneration(time);
frame++;
if(frame > 2) frame -= 2;
if(dx>0) playerSp.setTextureRect(IntRect(32*(int)frame, 96, 32, 48));
if(dx<0) playerSp.setTextureRect(IntRect(32*(int)frame, 48, 32, 48));
if(dy<0) playerSp.setTextureRect(IntRect(32*(int)frame, 146, 32, 48));
if(dy>0) playerSp.setTextureRect(IntRect(32*(int)frame, 2, 32, 48));
playerSp.setPosition(rect.left, rect.top);
dx = 0;
dy = 0;
}
示例7: add
void CollisionPack::load(Core::File& pFile)
{
const int collisionSize = pFile.readInt32();
for(int i = 0; i < collisionSize; ++i)
{
add(Collision(pFile));
}
}
示例8: ObjectsCollision
bool ObjectsCollision(SDL_Rect *rect)
{
for (int i = 0; i < object_number; i++)
if (objects[i].solid &&
Collision(objects[i].sprite->rect, rect) != NONE)
return true;
return false;
}
示例9: Collision
void CExplosiveProjectile::Update()
{
pos+=speed;
speed.y+=gs->gravity;
if(!--ttl)
Collision();
}
示例10: if
void FGame::Process()
{
// 키보드 입력 처리
if(game.m_Input.GetKeyState(VK_LEFT))
{
character.Move(0);
}
if(game.m_Input.GetKeyState(VK_RIGHT))
{
character.Move(2);
}
if(!character.m_use && game.m_Input.GetKeyState(VK_SPACE) == KEY_PRESS)
{
game.StartState(Game::STATE_GAME);
}
// 고구마 생성 처리
static int iRapid = 0;
if(game.GetFrameTime() < Game.FPS * 20)
{
iRapid = 6;
}
else if(game.GetFrameTime() < Game.FPS * 40)
{
iRapid = 10;
}
else if(game.GetFrameTime() < Game.FPS * 60)
{
iRapid = 14;
}
else if(game.GetFrameTime() < Game.FPS * 80)
{
iRapid = 20;
}
else if(game.GetFrameTime() < Game.FPS * 100)
{
iRapid = 30;
}
if(game.GetFrameTime() % (Game::FPS / iRapid) == 0)
{
MakeGogooma();
}
Collision();
character.Process();
int i;
for(i = 0; i < GOGOOMA_COUNT; i++)
{
gogoomas[i].Process();
if(gogoomas[i].m_frame == 1 && character.m_use)
{
iScore++;
}
}
}
示例11: while
CollisionEvents& PhysicsEngine::getCollisionEvents() {
const uint32_t CONTINUE_EVENT_FILTER_FREQUENCY = 10;
_collisionEvents.clear();
// scan known contacts and trigger events
ContactMap::iterator contactItr = _contactMap.begin();
while (contactItr != _contactMap.end()) {
ContactInfo& contact = contactItr->second;
ContactEventType type = contact.computeType(_numContactFrames);
if(type != CONTACT_EVENT_TYPE_CONTINUE || _numSubsteps % CONTINUE_EVENT_FILTER_FREQUENCY == 0) {
ObjectMotionState* motionStateA = static_cast<ObjectMotionState*>(contactItr->first._a);
ObjectMotionState* motionStateB = static_cast<ObjectMotionState*>(contactItr->first._b);
glm::vec3 velocityChange = (motionStateA ? motionStateA->getObjectLinearVelocityChange() : glm::vec3(0.0f)) +
(motionStateB ? motionStateB->getObjectLinearVelocityChange() : glm::vec3(0.0f));
if (motionStateA && motionStateA->getType() == MOTIONSTATE_TYPE_ENTITY) {
QUuid idA = motionStateA->getObjectID();
QUuid idB;
if (motionStateB && motionStateB->getType() == MOTIONSTATE_TYPE_ENTITY) {
idB = motionStateB->getObjectID();
}
glm::vec3 position = bulletToGLM(contact.getPositionWorldOnB()) + _originOffset;
glm::vec3 penetration = bulletToGLM(contact.distance * contact.normalWorldOnB);
_collisionEvents.push_back(Collision(type, idA, idB, position, penetration, velocityChange));
} else if (motionStateB && motionStateB->getType() == MOTIONSTATE_TYPE_ENTITY) {
QUuid idB = motionStateB->getObjectID();
glm::vec3 position = bulletToGLM(contact.getPositionWorldOnA()) + _originOffset;
// NOTE: we're flipping the order of A and B (so that the first objectID is never NULL)
// hence we must negate the penetration.
glm::vec3 penetration = - bulletToGLM(contact.distance * contact.normalWorldOnB);
_collisionEvents.push_back(Collision(type, idB, QUuid(), position, penetration, velocityChange));
}
}
if (type == CONTACT_EVENT_TYPE_END) {
ContactMap::iterator iterToDelete = contactItr;
++contactItr;
_contactMap.erase(iterToDelete);
} else {
++contactItr;
}
}
return _collisionEvents;
}
示例12: Update
void Tank::Handle()
{
Update();
CheckFlags();
if (m_iTimeFiring > BULLET_CREATION_TIME && m_bShoot)
{
m_oBulletHandle->New(
m_fPosX + (30 * cos((m_glSurfaceTurret.rotation - 90) * (PI / 180.0f))),
m_fPosY + (30 * sin((m_glSurfaceTurret.rotation - 90) * (PI / 180.0f))),
m_glSurfaceTurret.rotation);
m_iTimeFiring = 0;
}
m_oBulletHandle->Handle();
Collision();
if (m_iTimeTraveled > TREAD_CREATION_TIME)
{
//at some point we will meet a condition where we need
//to spawn a treadmark
//after we spawn a treadmark
//that new object that is created
//will be linked to the tank because it was created by it
//but the object would "turn itself off" given a condition it would
//meet internally
//ie: tank is moving and gains a total distance of 100 units
//the tank then spawns a treadmark
//the tank keeps moving and will continue to spawn a treadmark every 100 units
//the treadmark itself on creation would begin it's own internal "counter/timer/distancetraveled"
//then undraw itself once it meets that condition
//usage example:
//tank.move();
//if(tank.distance > 100)
//for i 10 x
//{
//tank.spawntreadmark(initial + offset);
//}
//do other stuff
//tank.spawntreadmark()
//{ if(this->timer > 0)
//draw(treadmarkTexture)
//}
m_oTreadMarks->New(
m_fPosX + ((m_glSurfaceBase.w - 35) * cos((m_glSurfaceBase.rotation + 45) * (PI / 180.0f))),
m_fPosY + ((m_glSurfaceBase.h - 33) * sin((m_glSurfaceBase.rotation + 45) * (PI / 180.0f))),
m_glSurfaceBase.rotation);
m_oTreadMarks->New(
m_fPosX + ((m_glSurfaceBase.w - 35) * cos((m_glSurfaceBase.rotation - 225) * (PI / 180.0f))),
m_fPosY + ((m_glSurfaceBase.h - 33) * sin((m_glSurfaceBase.rotation - 225) * (PI / 180.0f))),
m_glSurfaceBase.rotation);
m_iTimeTraveled = 0;
}
}
示例13: temp
//-----------------------------------------------------------------
// Name: RotateTet()
// Desc: Rotates the tetrad by 90 degrees CCW or CW
//-----------------------------------------------------------------
void CTetris::RotateCurrTet( int angle )
{//Have to take the current position move it to the origan, rotate, then move it back
int i=0, tempX = 0, tempY = 0,
nOrgX = m_CurrentTet.iX, nOrgY = m_CurrentTet.iY;
Tetrad temp(m_CurrentTet);
//x'= xcos(angle) - ysin(angle);
//y'= xsin(angle) + ycos(angle);
if( m_nCurrentTetName == SALLY )
return;
//pre do the rotation then check bounds and if it works store in currentTet
if( angle == CW )//
{
TranslateTet(temp,0,0);
for(i=0; i<BLOCKS_PER_TET; i++)
{
tempX = 0*temp.tet[i].iX + -1*(temp.tet[i].iY);
tempY = 1*temp.tet[i].iX + 0*(temp.tet[i].iY);
temp.tet[i].iX = tempX;
temp.tet[i].iY = tempY;
}
TranslateTet(temp,nOrgX,nOrgY);
for(i=0; i<BLOCKS_PER_TET; i++)
if( !Collision(temp.tet[i].iX, temp.tet[i].iY) )
return;
m_CurrentTet = temp;
}
else if( angle == CCW )
{
TranslateTet(temp,0,0);
for(i=0; i<BLOCKS_PER_TET; i++)
{
tempX = 0*temp.tet[i].iX + 1*temp.tet[i].iY;
tempY = (-1*temp.tet[i].iX + 0*temp.tet[i].iY);
temp.tet[i].iX = tempX;
temp.tet[i].iY = tempY;
}
TranslateTet(temp,nOrgX,nOrgY);
for(i=0; i<BLOCKS_PER_TET; i++)
if( !Collision(temp.tet[i].iX, temp.tet[i].iY) )
return;
m_CurrentTet = temp;
}
}
示例14: Collision
Collision State::hitBy(Collidable* other) {
if(!collisionsEnabled || !enabled || this == other || !m_map) {
return Collision();
}
// Test collisions with the map
Collision c = m_map->hitBy(other);
return c;
}
示例15: Movement
void Enemy::Update()
{
Movement();
Collision();
if (m_timer > m_duration)
Destroy();
m_timer += Time::DeltaTime();
}