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


C++ Collision函数代码示例

本文整理汇总了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;
}
开发者ID:jfyne,项目名称:Black-Comrade,代码行数:28,代码来源:collisionManager.cpp

示例2: Collision

void CWeaponProjectile::Collision(CFeature* feature)
{
	if(gs->randFloat()>weaponDef->fireStarter)
		feature->StartFire();

	Collision();
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:7,代码来源:WeaponProjectile.cpp

示例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);
    }
}
开发者ID:jfyne,项目名称:Black-Comrade,代码行数:48,代码来源:collisionDetection.cpp

示例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;
		}
	}
}
开发者ID:wthnonck,项目名称:tdtw,代码行数:59,代码来源:particles.cpp

示例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;
	}
}
开发者ID:ZAKDC00,项目名称:ddnet,代码行数:17,代码来源:controls.cpp

示例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;
}
开发者ID:BorisTopchiev,项目名称:Course_Work1_2D-RPG,代码行数:17,代码来源:player.cpp

示例7: add

	void CollisionPack::load(Core::File& pFile)
	{
		const int collisionSize = pFile.readInt32();
		for(int i = 0; i < collisionSize; ++i)
		{
			add(Collision(pFile));
		}
	}
开发者ID:cantidio,项目名称:gorgonCpp,代码行数:8,代码来源:gorgon_collisionpack.cpp

示例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;
}
开发者ID:maxweis,项目名称:game,代码行数:8,代码来源:collision.c

示例9: Collision

void CExplosiveProjectile::Update()
{	
	pos+=speed;
	speed.y+=gs->gravity;

	if(!--ttl)
		Collision();
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:8,代码来源:ExplosiveProjectile.cpp

示例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++;
		}
	}
}
开发者ID:MaybeS,项目名称:when_i_was_a_kid,代码行数:58,代码来源:FGame.cpp

示例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;
}
开发者ID:MarcelEdward,项目名称:hifi,代码行数:45,代码来源:PhysicsEngine.cpp

示例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;
	}
}
开发者ID:bennybroseph,项目名称:Assesments,代码行数:57,代码来源:Tank.cpp

示例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;
	}
}
开发者ID:scirelli,项目名称:testForDX7,代码行数:48,代码来源:CTetris_Impl.cpp

示例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;
}
开发者ID:Dustpup,项目名称:aurora-game-engine,代码行数:10,代码来源:state.cpp

示例15: Movement

void Enemy::Update()
{
	Movement();
	Collision();

	if (m_timer > m_duration)
		Destroy();

	m_timer += Time::DeltaTime();
}
开发者ID:kimcavalcanti,项目名称:Spaceships-2D,代码行数:10,代码来源:Enemy.cpp


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