当前位置: 首页>>代码示例>>C++>>正文


C++ Collision::setCO1Edge方法代码示例

本文整理汇总了C++中Collision::setCO1Edge方法的典型用法代码示例。如果您正苦于以下问题:C++ Collision::setCO1Edge方法的具体用法?C++ Collision::setCO1Edge怎么用?C++ Collision::setCO1Edge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collision的用法示例。


在下文中一共展示了Collision::setCO1Edge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addCollisionSpriteSprite

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);
}
开发者ID:jphmf,项目名称:hw4_game_programming,代码行数:35,代码来源:Physics.cpp

示例2: addTileCollision

/*
	Called when a collision is detected between a world tile
	and a sprite, this records that collision so that it
	can be resolved later if needed.
*/
void Physics::addTileCollision(CollidableObject *dynamicObject, Tile *tile, float tileX, float tileY, float tileWidth, float tileHeight)
{

	// IF WE'VE ALREADY HANDLED A COLLISION BETWEEN THESE TWO OBJECTS THIS
	// FRAME THEN IGNORE IT
	set<Tile*> doTiles = spriteToTileCollisionsThisFrame[dynamicObject];
	if (doTiles.find(tile) != doTiles.end())
		return;

	// GET A DUMMY COLLIABLE OBJECT TO USE FOR THE TILE
	CollidableObject *tileInfoForCollision = recycledCollidableObjectsList.back();

	// FILL IT WITH DATA
	AABB *bv = tileInfoForCollision->getBoundingVolume();
	bv->setCenterX(tileX + (tileWidth/2));
	bv->setCenterY(tileY + (tileHeight/2));
	bv->setWidth(tileWidth);
	bv->setHeight(tileHeight);

	// 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(dynamicObject, tileInfoForCollision, co1Edge, co2Edge, 0.0f);
	if (timeUntilCollision > 1.0f)
		return;

	// IF IT MADE IT HERE, A COLLISION IS HAPPENING
	// AND REMOVE IT FROM THE RECYCLING CENTER
	recycledCollidableObjectsList.pop_back();

	// NOW LET'S MAKE A COLLISION FOR THE TILE-SPRITE
	Collision *collisionToAdd = recycledCollisions.back();
	collisionToAdd->setCO1(dynamicObject);
	collisionToAdd->setCO2(tileInfoForCollision);
	collisionToAdd->setCO1Edge(co1Edge);
	collisionToAdd->setCO2Edge(co2Edge);
	collisionToAdd->setCollisionWithTile(true);
	collisionToAdd->setTimeOfCollision(timeUntilCollision);
	collisionToAdd->setTile(tile);
	recycledCollisions.pop_back();
	activeCollisions.push_back(collisionToAdd);
}
开发者ID:DavidLui,项目名称:-CSE380-Balloon-Escape,代码行数:49,代码来源:Physics.cpp


注:本文中的Collision::setCO1Edge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。