本文整理汇总了C++中Collision类的典型用法代码示例。如果您正苦于以下问题:C++ Collision类的具体用法?C++ Collision怎么用?C++ Collision使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collision类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Gravitation
void Physics::Gravitation(Collision theCollision, PlayerObject *theCharacter)
{
if (theCharacter->jumping == true)
{
this->upforce = this->upforce * 1.30;
}
if (this->upforce >0.8)
{
theCharacter->jumping = false;
}
if(theCollision.isGrounded())
{
this->onPlatform = true;
this->downforce = 0.1;
}
if (!theCollision.isGrounded() || this->upforce > 0)
{
if (!theCollision.isGrounded())
{
this->downforce = this->downforce * 1.02;
}
theCharacter->Translate(0.0, (this->upforce - this->downforce)/2, 0.0);
theCharacter->yPos += (this->upforce - this->downforce)/2;
}
if (this->upforce > 0)
{
this->upforce -= this->downforce / 9;
}
}
示例2: while
/*
When we resolve a collision involving a sprite other collisions
involving it are then obsolete, so this method removes them.
*/
void Physics::removeActiveCOCollisions(CollidableObject *co)
{
list<Collision*>::iterator coIt = activeCollisions.begin();
while (coIt != activeCollisions.end())
{
// WE'LL NEED THIS TO REMOVE THE ELEMENT
list<Collision*>::iterator tempIt = coIt;
// BUT WE'LL MOVE THE ITERATOR ALONG NOW FOR THE NEXT LOOP
coIt++;
// GET THE COLLISION WE MAY NEED TO REMOVE
if (tempIt != activeCollisions.end())
{
Collision *c = (*tempIt);
// AND TEST IT
if ((co == c->getCO1()) || (co == c->getCO2()))
{
// RECYCLE THE COLLIDABLE OBJECTS IF NECESSARY
if (c->isCollisionWithTile())
{
recycledCollidableObjectsList.push_back(c->getCO2());
}
// PUT IT BACK IN THE RECYCLING BIN
recycledCollisions.push_back(c);
// AND REMOVE IT FROM THE LIST
activeCollisions.erase(tempIt);
}
}
}
}
示例3: if
bool World::makeCollision(const b2Fixture& fix, Collision& c) const
{
if (!mBounds) return false;
if (fix.GetBody() != mBounds) return false;
if (fix.GetUserData() == BOUNDS_LEFT_PTR) c.setToWorldBounds(Collision::LEFT);
else if (fix.GetUserData() == BOUNDS_TOP_PTR) c.setToWorldBounds(Collision::TOP);
else if (fix.GetUserData() == BOUNDS_RIGHT_PTR) c.setToWorldBounds(Collision::RIGHT);
else if (fix.GetUserData() == BOUNDS_BOTTOM_PTR) c.setToWorldBounds(Collision::BOTTOM);
else return false;
return true;
}
示例4: Collision
void Scene::checkCollisions()
{
for (std::vector<RigidBody *>::iterator itA = _bodies.begin() ; itA != _bodies.end(); ++itA) {
for (std::vector<RigidBody *>::iterator itB = itA + 1 ; itB != _bodies.end(); ++itB) {
Collision *collision = new Collision(*itA, *itB);
CollisionPair *cp = collision->dispatcher();
if (cp != NULL) {
_collisions.push_back(cp);
}
}
}
}
示例5: hitBy
Collision ScriptTrigger::hitBy(Collidable* other) {
Collision c;
c = GameObject::hitBy(other);
if(!script()->isRunning()) {
if(c.collided()) {
// Call onHit via the script engine.
script()->callFunction(*this, (char*)"onHit", "o", (ScriptableObject*)other);
}
}
// No collision if script is running
return c;
}
示例6: calculateTimeUntilCollision
void Physics::addCollisionSpriteSprite(CollidableObject *dynamicObjectA, CollidableObject *dynamicObjectB)
{
// IF WE'VE ALREADY HANDLED A COLLISION BETWEEN THESE TWO OBJECTS THIS
// FRAME THEN IGNORE IT
//PAULO- MAYBE IMPORTANT***********************
/*set<CollidableObject*> doSprite = spriteToSpriteCollisionsThisFrame[dynamicObjectB];
if (doSprite.find(dynamicObjectB) != doSprite.end())
return;*/
// FIRST WE'RE GOING TO DO A MORE NARROW CHECK TO SEE IF THE dynamicObject
// REALLY DOES COLLIDE WITH THE TILE. TO DO SO WE'LL CALCULATE THE TIME
// OF COLLISION. IF IT HAPPENS AFTER THIS FRAME IS OVER (> 1), THEN WE
// WILL IGNORE IT
unsigned int co1Edge, co2Edge;
float timeUntilCollision = calculateTimeUntilCollision(dynamicObjectA,dynamicObjectB, co1Edge, co2Edge, 0.0f);
if (timeUntilCollision > 1.0f)
return;
//// NOW LET'S MAKE A COLLISION FOR THE SPRITE-SPRITE
Collision *collisionToAdd = recycledCollisions.back();
collisionToAdd->setCO1(dynamicObjectA);
collisionToAdd->setCO2(dynamicObjectB);
collisionToAdd->setCO1Edge(co1Edge);
collisionToAdd->setCO2Edge(co2Edge);
collisionToAdd->setCollisionWithSprite(true);
collisionToAdd->setCollisionWithTile(false);
collisionToAdd->setTimeOfCollision(timeUntilCollision);
//collisionToAdd->setTile(tile);
recycledCollisions.pop_back();
activeCollisions.push_back(collisionToAdd);
}
示例7: Render
void Tile::Render(Textures* textures, SDL_Rect* clips, SDL_Renderer* Renderer, SDL_Rect* camera)
{
if(collision.CheckCollision(TileBox, *camera))
{
textures->Render(Renderer, TileBox.x - camera->x, TileBox.y - camera->y, &clips[TileType]);
}
}
示例8: makeFence
void makeFence(Level* level, const NewtonWorld* newtonWorld)
{
CollisionSet fencePartsCollisions;
fencePartsCollisions.insert(level->getCollision("fence"));
//fencePartsCollisions.insert(level->getCollision("fenceClip1"));
//fencePartsCollisions.insert(level->getCollision("fenceClip2"));
fencePartsCollisions.insert(level->getCollision("fenceTop"));
Collision* heightMap = level->getCollision("level");
for (size_t fencesVectorIdx = 0; fencesVectorIdx < level->m_fences.size(); fencesVectorIdx++)
{
const vector<Vector>& fence = level->m_fences[fencesVectorIdx];
for (size_t i = 0; i < fence.size() - 1; i++)
{
const Vector startPoint = fence[i];
const Vector endPoint = fence[i + 1];
Vector delta(endPoint - startPoint);
const Vector rotation(0, - delta.getRotationY(), 0);
float howMany = delta.magnitude() / fenceSpacing;
delta /= howMany;
for (int j = 0; j < howMany; j++)
{
const string bodyID = "fence" + cast<string>(fencesVectorIdx) + "_" + cast<string>(i) + "_" + cast<string>(j);
Body* body = new Body(bodyID, level, fencePartsCollisions);
if (Network::instance->m_isSingle == false)
{
NewtonBodySetMassMatrix(body->m_newtonBody, 0, 0, 0, 0);
}
body->m_soundable = true;
Vector position = Vector(startPoint + delta * static_cast<float>(j));
position.y = fenceHeight / 2 + heightMap->getHeight(position.x, position.z) + 0.05f;
body->setTransform(position, rotation);
NewtonWorldFreezeBody(newtonWorld, body->m_newtonBody);
NewtonBodySetAutoFreeze(body->m_newtonBody, 1);
level->m_bodies[bodyID] = body;
}
}
}
}
示例9: addCollision
void GameWindow::addCollision(const Vector3d& p, const Vector3d& n)
{
Collision* c = 0;
for(unsigned int i = 0; i < cMaxCollisions; ++i)
if(mCollisions[i]->isDone())
{ c = mCollisions[i]; break; }
if(c)
{
Matrix4d m;
m.setTranslation(toPoint(p));
c->setTransformationToGlobal(m);
double a = atan2(n.getY(), n.getX());
c->setAngle(a);
c->setNormal(n);
c->animate();
}
}
示例10: IwGetModelBuilder
void Physics::BuildCollision( const char* pUserString, CIwModel* pModel )
{
// Check user string to test whether to affect this asset
if( strcmp( pUserString, "collision" ) != 0 )
{
return;
}
// Create a new collision resource and name it after its model partner
Collision* pCollision = new Collision;
pCollision->SetName( pModel->DebugGetName() );
for( uint32 i = 0; i < IwGetModelBuilder()->GetNumFaces(); ++i )
{
pCollision->AddFace( IwGetModelBuilder()->GetFace( i ), pModel );
}
// Add the collision resource to IwResManager - it will be serialised as part of the current group.
IwGetResManager()->AddRes( "Collision", pCollision );
}
示例11: RenderFrame
void Engine::RenderFrame()
{
Collision checker; //DELETE
//Camera offsets
int camOffsetX, camOffsetY;
Tile* tile;
window->clear();
//Get the tile bounds we need to draw
sf::IntRect bounds = camera->GetTileBounds(tileSize);
//Figure out how much to offset each tile
camOffsetX = camera->GetTileOffset(tileSize).x;
camOffsetY = camera->GetTileOffset(tileSize).y;
//Loop through and draw each tile
//We're keeping track of two variables in each loop. How many tiles
//we've drawn (x and y), and which tile on the map we're drawing (tileX
//and tileY)
player->ground = false;
for(int y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
{
for(int x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
{
tile = new Tile(TextureManager.GetTexture(0)); // background!
tile->Draw((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, window);
//Get the tile
tile = currentLevel->GetTile(tileX, tileY);
if(tile){
tile->Draw((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, window);
if(checker.RectCollide(sf::FloatRect((x * tileSize), (y * tileSize), tileSize, tileSize), sf::FloatRect((player->getPosition().left), (player->getPosition().top), tileSize, tileSize)) && tile->baseSprite.getTexture() == Tile(TextureManager.GetTexture(2)).baseSprite.getTexture()){
player->ground = true;
}
}
}
}
player->Draw(camOffsetX, camOffsetY, window);
window->display();
}
示例12: Entity
Entity* StaticBlock::prepareEntity(PropertyManager& parameters) {
Entity* entity = new Entity();
Collision* colli = new Collision();
sf::Vector2f pos = parameters.Get<sf::Vector2f>("Position");
Position* position = new Position();
position->updatePosition(pos.x, pos.y);
sf::Transformable transform = position->getPosition();
colli->update(transform);
colli->setArrayVertex(parameters.Get<sf::VertexArray*>("Vertex"));
colli->applyRatio(parameters.Get<sf::Vector2f>("Ratio"));
colli->setType(TypeCollision::STATIC);
position->setPosition(colli->getTransform());
entity->Add<Position*>("Position", position);
entity->Add<Collision*>("Collision", colli);
entity->Add<Collision*>("Debug", colli);
OnCollision* onCollision = new OnCollision();
makeOnCollision(entity->getId(), onCollision);
entity->Add<OnCollision*>("OnCollision", onCollision);
return entity;
}
示例13: main
int Program::main(const std::vector<CL_String> &args)
{
try
{
// Initialize ClanLib base components
CL_SetupCore setup_core;
// Initialize the ClanLib display component
CL_SetupDisplay setup_display;
#ifdef USE_SOFTWARE_RENDERER
CL_SetupSWRender setup_swrender;
#endif
#ifdef USE_OPENGL_1
CL_SetupGL1 setup_gl1;
#endif
#ifdef USE_OPENGL_2
CL_SetupGL setup_gl;
#endif
// Start the Application
Collision app;
int retval = app.start(args);
return retval;
}
catch(CL_Exception &exception)
{
// Create a console window for text-output if not available
CL_ConsoleWindow console("Console", 80, 160);
CL_Console::write_line("Exception caught: " + exception.get_message_and_stack_trace());
console.display_close_message();
return -1;
}
}
示例14: checkAABBCollision
bool RoundCollision::checkAABBCollision(Collision other) {
if (loc.getX() + raduis >= other.getLocation().getX() + other.getwidth() && loc.getX() - raduis <= other.getLocation().getX() - other.getwidth()) {
if (loc.getZ() + raduis >= other.getLocation().getZ() + other.getlength() && loc.getZ() - raduis <= other.getLocation().getZ() - other.getlength()) {
if (loc.getY() + raduis >= other.getLocation().getY() + other.getheight() && loc.getY() - raduis <= other.getLocation().getY() - other.getheight()) {
return true;
}
}
}
return false;
}
示例15: makeCollision
void ContactListener::makeCollision(const ContactKey& key, Collision& collision) const
{
collision.mContactOne = mWorld.box2CiTranslation(key.mContactPointOne, nullptr); // nullptr for sprite will make contacts in world space
collision.mContactTwo = mWorld.box2CiTranslation(key.mContactPointTwo, nullptr); // so assume that all contacts are world space position
collision.mNormal = ci::Vec2f(key.mNormal.x, key.mNormal.y);
// I *think* the sprite in the key can be ignored, because technically it should
// always be the object receiving the callback (although I bet I have some details
// to work out when it comes to sprites colliding with each other).
// That means it's the fixture I care about.
if (!key.mFixture) return;
if (mWorld.makeCollision(*key.mFixture, collision)) return;
const b2Body* b = key.mFixture->GetBody();
ds::ui::Sprite* sprite = reinterpret_cast<ds::ui::Sprite*>(b ? b->GetUserData() : nullptr);
if (sprite) collision.setToSprite(sprite->getId());
}