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


C++ BoxCollider类代码示例

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


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

示例1: Fits

bool BoxCollider::Fits( const CylinderCollider &c ) const
{
	BoxCollider b;
	b.position = glm::vec3( c.end.x, c.end.y / c.height, c.end.z);
	b.SetRadius( glm::vec3( c.radius, c.height/2, c.radius ) );
	return Fits( b );
}
开发者ID:Ryokin,项目名称:CodeStudies,代码行数:7,代码来源:collider.cpp

示例2: Java_org_gearvrf_NativeBoxCollider_setHalfExtents

JNIEXPORT void JNICALL
Java_org_gearvrf_NativeBoxCollider_setHalfExtents(JNIEnv *env,
        jobject obj, jlong jcollider, jfloat x, jfloat y, jfloat z)
{
    BoxCollider *collider = reinterpret_cast<BoxCollider *>(jcollider);
    collider->set_half_extents(x, y, z);
}
开发者ID:NolaDonato,项目名称:GearVRf,代码行数:7,代码来源:box_collider_jni.cpp

示例3: BEGIN_STD_VECTOR_ITERATOR

//
// removes from the passed vector all the colliders which are outside of the frustum
//
void Frustum::CollidersInFrustum(std::vector<ColliderComponent*>& shapesToCheck) const {

	std::vector<ColliderComponent*> inFrustum;

	BEGIN_STD_VECTOR_ITERATOR( ColliderComponent*, shapesToCheck )
		if( currentItem->GetRTTI() == CylinderCollider::rtti ) {

			CylinderCollider* collider = static_cast<CylinderCollider*>(currentItem);

			CylinderShape* cylinder = static_cast<CylinderShape*>( collider->GetShape() );

			if ( CylinderInFrustum( *cylinder ) ) {
				inFrustum.push_back( collider );	
			}
		} else if ( currentItem->GetRTTI() == BoxCollider::rtti ) {

			BoxCollider* collider = static_cast<BoxCollider*>(currentItem);

			BoxShape* box = static_cast<BoxShape*>( collider->GetShape() );

			if ( BoxInFrustum( *box ) ) {
				inFrustum.push_back( collider );					
			}
		}
	END_STD_VECTOR_ITERATOR

	shapesToCheck.swap( inFrustum );
}
开发者ID:Mertank,项目名称:ToneArm,代码行数:31,代码来源:Frustum.cpp

示例4: ResolveCollisions

void Grid::ResolveCollisions(Entity* ent)
{
	RigidBody* rigid = ent->GetComponent<RigidBody>();

	if (rigid)
	{
		rigid->ResolveCollisions();

		BoxCollider* box = ent->GetComponent<BoxCollider>();

		if (box)
		{
			Vector3& max = box->GetMaxCoord();
			Vector3& min = box->GetMinCoord();

			if (min.x < 0 || min.y < 0 || max.x > GridWidth || max.y > GridHeight)
				ent->OnCollisionEnter(Collision());
		}
	}

	for (auto &child : ent->GetChildren())
	{
		ResolveCollisions(child);
	}
}
开发者ID:Dopelust,项目名称:SP4-10,代码行数:25,代码来源:Grid.cpp

示例5: CreatePlayer

// Creates a player
GameObject* GameManager::CreatePlayer( uint32_t index, const XMFLOAT3& position, const XMFLOAT3& scale )
{
    Scene* scene = Scene::GetInstance();
    GameObject* player = scene->AddGameObject( "Player_" + std::to_string( index ) );
    ID3D11Device* device = player->GetDevice();
    ID3D11DeviceContext* deviceContext = player->GetDeviceContext();

    // Set the player's transform info
    Transform* transform = player->GetTransform();
    transform->SetPosition( position );
    transform->SetScale( scale );

    // Add the collider to the player
    BoxCollider* collider = player->AddComponent<BoxCollider>();
    collider->SetSize( XMFLOAT3( 1, 1, 1 ) );

    // Add the rigid body to the player
    Rigidbody* rigidbody = player->AddComponent<Rigidbody>();
    rigidbody->SetMass( 0 );

    // Add the default material to the player
    DefaultMaterial* material = player->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\Rocks2.jpg" );
    material->LoadNormalMap( "Textures\\Rocks2Normals.jpg" );
    material->SetDirectionalLight( StageLight );

    // Add the mesh renderer to the player
    MeshRenderer* meshRenderer = player->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\cube.obj", device, deviceContext ) );

    return player;
}
开发者ID:TheCodeInside,项目名称:BowLand,代码行数:34,代码来源:GameManager.cpp

示例6: ClosestPtToAABB

void ClosestPtToAABB( glm::vec3& p, const BoxCollider& AABB )
{
	glm::vec3 min = AABB.Min();
	glm::vec3 max = AABB.Max();
	glm::clamp( p.x, min.x, max.x );
	glm::clamp( p.y, min.y, max.y );
	glm::clamp( p.z, min.z, max.z );
}
开发者ID:Ryokin,项目名称:CodeStudies,代码行数:8,代码来源:collider.cpp

示例7: QuadTree

void GameScreen::BuildQuadTree(){
	if (m_quadTree){
		delete m_quadTree;
		m_quadTree = NULL;
	}

	m_quadTree = new QuadTree();

	m_quadTree->buildFullTree(NBR_LEVELS, (m_width + 0.1f) / 2, (m_height + 0.1f) / 2, 0.5f, m_width + 0.1f, m_height + 0.1f, 1);

	for (int i = 0; i < m_land->size(); i++){
		BoxCollider* temp = new BoxCollider;
		temp->setDimension(m_landCube->getScale(), m_landCube->getScale(), m_landCube->getScale());
		temp->setPos(m_land->at(i));
		m_quadTree->addObject(temp);
	}
}
开发者ID:,项目名称:,代码行数:17,代码来源:

示例8: SqrDistPointAABB

float SqrDistPointAABB( glm::vec3 &point, const BoxCollider &AABB )
{
	float sqrDist( 0.0f);
	glm::vec3 min = AABB.Min();
	glm::vec3 max = AABB.Max();

	if (point.x < min.x) sqrDist += ( min.x - point.x) * ( min.x - point.x);
	if (point.x > max.x) sqrDist += ( point.x - max.x) * ( point.x - max.x);

	if (point.y < min.y) sqrDist += ( min.y - point.y) * ( min.y - point.y);
	if (point.y > max.y) sqrDist += ( point.y - max.y) * ( point.y - max.y);

	if (point.z < min.z) sqrDist += ( min.z - point.z) * ( min.z - point.z);
	if (point.z > max.z) sqrDist += ( point.z - max.z) * ( point.z - max.z);

	return sqrDist;
}
开发者ID:Ryokin,项目名称:CodeStudies,代码行数:17,代码来源:collider.cpp

示例9: PopulateCells

void Grid::PopulateCells(Entity* ent)
{
	BoxCollider* box = ent->GetComponent<BoxCollider>();

	if (box)
	{
		box->cell = cell;

		box->part.clear();
		
		Vector3 min = box->GetMinCoord();
		Vector3 max = box->GetMaxCoord();

		min.x /= GridWidth;
		min.x *= NumberOfPartitionsX;

		max.x /= GridWidth;
		max.x *= NumberOfPartitionsX;

		min.y /= GridHeight;
		min.y *= NumberOfPartitionsY;

		max.y /= GridHeight;
		max.y *= NumberOfPartitionsY;


		for (int i = min.x; i <= max.x; ++i)
			for (int j = min.y; j <= max.y; ++j)
			{
				Partition* c = GetPartition(i, j);

				if (c)
				{
					c->Add(ent);
					box->part.push_back(c);
				}
			}
	}

	for (auto &child : ent->GetChildren())
	{
		if (child->IsActive())
			PopulateCells(child);
	}
}
开发者ID:Dopelust,项目名称:SP4-10,代码行数:45,代码来源:Grid.cpp

示例10: collidesWithWalls

bool World::collidesWithWalls(const BoxCollider &collider) const {
  for (const Entity &e : scene->entities) {
    if (e.hasComponent<AACollisionBox>()) {
      if (collider.collidesWith(e.getComponent<AACollisionBox>().box)) {
        return true;
      }
    }
  }
  return false;
}
开发者ID:nonconforme,项目名称:glPortal,代码行数:10,代码来源:World.cpp

示例11: wallCollider

bool World::collidesWithWalls(BoxCollider collider) {
  for (unsigned int i = 0; i < scene->walls.size(); i++) {
    Entity wall = scene->walls[i];
    BoxCollider wallCollider(wall.position, wall.scale);

    if (collider.collidesWith(wallCollider)) {
      return true;
    }
  }
  return false;
}
开发者ID:Kaperstone,项目名称:glPortal,代码行数:11,代码来源:World.cpp

示例12: CreateArrow

// Creates an arrow game object
GameObject* GameManager::CreateArrow( const XMFLOAT3& position, const XMFLOAT3& force )
{
    static const XMFLOAT3 ArrowSize = { 1, 0.1f, 1.0f };

    Scene* scene = Scene::GetInstance();
    ID3D11Device* device = _gameObject->GetDevice();
    ID3D11DeviceContext* deviceContext = _gameObject->GetDeviceContext();

    // Create the arrow object
    GameObject* arrow = scene->AddGameObject( _gameObject->GetName() + "_Arrow_" + std::to_string( _arrowCount++ ) );
    
    // Set some transform info
    Transform* transform = arrow->GetTransform();
    transform->SetPosition( position );

    // Add the arrow's collider
    BoxCollider* collider = arrow->AddComponent<BoxCollider>();
    collider->SetSize( ArrowSize );

    // Add the arrow's rigidbody
    Rigidbody* rigidbody = arrow->AddComponent<Rigidbody>();
    rigidbody->SetMass( 1.0f );

    // Set the arrow's collision callback
    GameObject::CollisionCallback callback = std::bind( &GameManager::OnArrowCollide, this, _1 );
    arrow->AddEventListener( "OnArrowCollide", callback );

    // Add a default material
    DefaultMaterial* material = arrow->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\SolidWhite.png" );
    material->SetDirectionalLight( StageLight );

    // Add a mesh renderer
    MeshRenderer* meshRenderer = arrow->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\arrow.obj", device, deviceContext ) );

    return arrow;
}
开发者ID:TheCodeInside,项目名称:BowLand,代码行数:40,代码来源:GameManager.cpp

示例13: addCollider

void CompositeCollider::addCollider(const BoxCollider& collider)
{
    mBoxColliders.push_back(collider);
    std::vector<Wall2f> walls = collider.getWalls();
    mWalls.insert(mWalls.end(), walls.begin(), walls.end());
}
开发者ID:TheGovernorsJunk,项目名称:CaulsCastle,代码行数:6,代码来源:composite_collider.cpp

示例14: translateChildProperty

	//-----------------------------------------------------------------------
	bool BoxColliderTranslator::translateChildProperty(ScriptCompiler* compiler, const AbstractNodePtr &node)
	{
		PropertyAbstractNode* prop = reinterpret_cast<PropertyAbstractNode*>(node.get());
		ParticleAffector* af = any_cast<ParticleAffector*>(prop->parent->context);
		BoxCollider* affector = static_cast<BoxCollider*>(af);
		if (prop->name == token[TOKEN_BOX_WIDTH])
		{
			if (passValidateProperty(compiler, prop, token[TOKEN_BOX_WIDTH], VAL_REAL))
			{
				// Property: box_width
				Real val = 0.0f;
				if(getReal(prop->values.front(), &val))
				{
					affector->setWidth(val);
					return true;
				}
			}
		}
		else if (prop->name == token[TOKEN_BOXCOLL_WIDTH])
		{
			// Property: box_collider_width (deprecated and replaced by 'box_width')
			if (passValidateProperty(compiler, prop, token[TOKEN_BOXCOLL_WIDTH], VAL_REAL))
			{
				Real val = 0.0f;
				if(getReal(prop->values.front(), &val))
				{
					affector->setWidth(val);
					return true;
				}
			}
		}
		else if (prop->name == token[TOKEN_BOX_HEIGHT])
		{
			// Property: box_height
			if (passValidateProperty(compiler, prop, token[TOKEN_BOX_HEIGHT], VAL_REAL))
			{
				Real val = 0.0f;
				if(getReal(prop->values.front(), &val))
				{
					affector->setHeight(val);
					return true;
				}
			}
		}
		else if (prop->name == token[TOKEN_BOXCOLL_HEIGHT])
		{
			// Property: box_collider_height (deprecated and replaced by 'box_height')
			if (passValidateProperty(compiler, prop, token[TOKEN_BOXCOLL_HEIGHT], VAL_REAL))
			{
				Real val = 0.0f;
				if(getReal(prop->values.front(), &val))
				{
					affector->setHeight(val);
					return true;
				}
			}
		}
		else if (prop->name == token[TOKEN_BOX_DEPTH])
		{
			// Property: box_depth
			if (passValidateProperty(compiler, prop, token[TOKEN_BOX_DEPTH], VAL_REAL))
			{
				Real val = 0.0f;
				if(getReal(prop->values.front(), &val))
				{
					affector->setDepth(val);
					return true;
				}
			}
		}
		else if (prop->name == token[TOKEN_BOXCOLL_DEPTH])
		{
			// Property: box_collider_depth (deprecated and replaced by 'box_depth')
			if (passValidateProperty(compiler, prop, token[TOKEN_BOXCOLL_DEPTH], VAL_REAL))
			{
				Real val = 0.0f;
				if(getReal(prop->values.front(), &val))
				{
					affector->setDepth(val);
					return true;
				}
			}
		}
		else if (prop->name == token[TOKEN_INNER_COLLISION])
		{
			// Property: inner_collision
			if (passValidateProperty(compiler, prop, token[TOKEN_INNER_COLLISION], VAL_BOOL))
			{
				bool val;
				if(getBoolean(prop->values.front(), &val))
				{
					affector->setInnerCollision(val);
					return true;
				}
			}
		}
		else
		{
			// Parse the BaseCollider
//.........这里部分代码省略.........
开发者ID:Humungo,项目名称:particleuniverse,代码行数:101,代码来源:ParticleUniverseBoxColliderTokens.cpp

示例15: while

void GameScreen::placeUnit(Unit* unit){
	bool done = false, regen = false;
	int attempts = 0;

	while (!done){
		unit->setPosition(random::rnd.number(m_width), random::rnd.number(m_height), 1);

		for (int i = 0; i < m_land->size(); i++){
			Vector point1, point2;
			point1 = unit->getPosition().x - (unit->getModel()->getCollider().getWidth() / 2);
			point2 = unit->getPosition().x + (unit->getModel()->getCollider().getWidth() / 2);

			BoxCollider tempBCol;
			tempBCol = m_landCube->getCollider();
			tempBCol.setPos(m_land->at(i));

			if ((point1.x <= tempBCol.getPos().x + (tempBCol.getWidth() / 2) && point1.x >= tempBCol.getPos().x - (tempBCol.getWidth() / 2)) || (point2.x <= tempBCol.getPos().x + (tempBCol.getWidth() / 2) && point2.x >= tempBCol.getPos().x - (tempBCol.getWidth() / 2))){
				unit->setPosition(m_land->at(i).x, m_land->at(i).y + m_landCube->getCollider().getHeight(), 1);

				for (int j = 0; j < m_land->size(); j++){
					if (unit->getPosition().x == m_land->at(j).x){
						if (unit->getPosition().y < m_land->at(j).y){
							float temp;

							temp = m_land->at(j).y - unit->getPosition().y;

							if (temp <= 0.1f){
								unit->setPosition(m_land->at(j).x, m_land->at(j).y + m_landCube->getCollider().getHeight(), 1);
							}
						}
					}
				}

				if (unit->getPosition().y < m_height){
					done = true;
				}

				for (int k = 0; k < NBR_TEAMS; k++){
					for (int l = 0; l < NBR_UNITS; l++){
						if (m_teams[k]->getUnit(l) == unit){
							continue;
						}

						if (m_teams[k]->getUnit(l)->getPosition() == unit->getPosition()){
							done = false;
						}
					}
				}

				break;
			}
		}

		if (attempts >= 100){
			done = true;
			regen = true;
		}

		attempts++;
	}

	if (regen){
		createGame(m_tGen.getCurrentType());
	}

	unit->setPosition(unit->getPosition().x, unit->getPosition().y + m_landCube->getCollider().getHeight(), 1);
}
开发者ID:,项目名称:,代码行数:67,代码来源:


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