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


C++ PhysicsObject类代码示例

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


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

示例1: MovePhysicsObject

void MovePhysicsObject(PhysicsObject &obj)
{   obj.Model.Coordinate.y = FindYPos(obj);
    obj.Model.Coordinate += glm::length(obj.Velocity) * obj.Direction;
    obj.AddForce(glm::abs(obj.Velocity - obj.ObjectTile.Normal) * MU );
    obj.VelocityZero();
    cout << obj.Velocity.x << " " << obj.Velocity.y << " " << obj.Velocity.z << endl;
}
开发者ID:JessicaCheung,项目名称:EpiHalvedMinigolf,代码行数:7,代码来源:Physics.cpp

示例2: while

void Physics::Work(Window *W, EventParams *E)
{
	if (E->Param1 != TimerID) return;
	
	PhysicsObject *curObj;
	while (curObj = env->GetNextObject())
	{
		
		if (curObj->FixedObject) continue;
		Coord3D Force(0, nDim == 2 ? curObj->mass * env->gravity : 0, nDim == 3 ? curObj->mass * env->gravity : 0);
		int nHits = 0;

		int i = 0;
		for (PhysicsObject *chkObj = env->GetNextObject(0); chkObj != 0; chkObj=env->GetNextObject(++i))
		{
			if (curObj == chkObj) continue;
			if (curObj->CheckHit(chkObj, nDim))
			{
				nHits++;

				Coord3D Fraction = curObj->getHitFraction(chkObj, nDim);
				if (!chkObj->FixedObject) curObj->NewVelocity = (chkObj->Velocity / chkObj->mass) * curObj->mass;
				else curObj->NewVelocity = curObj->NewVelocity - Fraction * curObj->Velocity * 2;
			}
		}
		if (nHits == 0) curObj->NewVelocity = curObj->Velocity;
		curObj->NewPosition = curObj->Position + curObj->Velocity;
	}
	env->update();
}
开发者ID:si2dharth,项目名称:Windows-Library,代码行数:30,代码来源:Physics.cpp

示例3: lock

void PhysicsWorld::cleanupMarkedForDeletion()
{
	LockGuard<Mutex> lock(m_mtx);

	while(!m_forDeletion.isEmpty())
	{
		auto it = m_forDeletion.getBegin();
		PhysicsObject* obj = *it;

		// Remove from objects marked for deletion
		m_forDeletion.erase(m_alloc, it);

		// Remove from player controllers
		if(obj->getType() == PhysicsObjectType::PLAYER_CONTROLLER)
		{
			auto it2 = m_playerControllers.getBegin();
			for(; it2 != m_playerControllers.getEnd(); ++it2)
			{
				PhysicsObject* obj2 = *it2;
				if(obj2 == obj)
				{
					break;
				}
			}

			ANKI_ASSERT(it2 != m_playerControllers.getEnd());
			m_playerControllers.erase(m_alloc, it2);
		}

		// Finaly, delete it
		m_alloc.deleteInstance(obj);
	}
}
开发者ID:,项目名称:,代码行数:33,代码来源:

示例4: getCollisionForObject

PhysicsObjectId WorldTestUnitAi :: getCollisionForObject (const PhysicsObject& object) const
{
	double radius = object.getRadius();

	// check for collision with moon
	if(object.getPosition().isNormLessThan(MOON_RADIUS + radius))
		return ID_MOON;

	// check for collision with target
	if(object.getId() != ID_TARGET &&
	   m_target_disappear_time <= 0.0 &&
	   object.getPosition().isDistanceLessThan(m_target.getPosition(),
	                                           m_target.getRadius() + radius))
	{
		return ID_TARGET;
	}

	// don't check against agent
	// don't check against bullets

	// check for collision with ring particles
	for(unsigned int i = 0; i < m_ring_particle_count; i++)
	{
		assert(i < RING_PARTICLE_COUNT_MAX);
		const RingParticleData& rp = ma_ring_particles[i];
		if(object.getPosition().isDistanceLessThan(rp.m_position, rp.m_radius + radius))
			return PhysicsObjectId(TYPE_RING_PARTICLE, PhysicsObjectId::FLEET_NATURE, i);
	}

	// no collisions
	return PhysicsObjectId::ID_NOTHING;
}
开发者ID:streibeb,项目名称:cs409,代码行数:32,代码来源:WorldTestUnitAi.cpp

示例5: PlayerWorldCollision

//This function checks for collision against all objects in the world
void Game::PlayerWorldCollision()
{
	for (GameObjectCollection::iterator cdtr = GameStorage->Begin(); cdtr != GameStorage->End(); cdtr++)
	{
		PhysicsObject *collidee = dynamic_cast<PhysicsObject*>(cdtr->get());
		collidee->PlayerCollision(&player);
	}
}
开发者ID:chrislewisdev,项目名称:Spectrum,代码行数:9,代码来源:Game.cpp

示例6: GetOwningApp

/**
 * @brief Helper function to parse a file and make a GameObject.
 * @param aObject
 * @param aParser
 */
void ObjectManager::ParseDictionary(GameObject *aObject, Parser &aParser)
{
  if(aParser.Find("Name"))
  {
    std::string name = aParser.Find("Name", "Value")->GetValue().ToString();
    aObject->SetName(name);
  }
  if(aParser.Find("PhysicsObject"))
  {
    PhysicsObject *object = GetOwningApp()->GET<PhysicsWorld>()->CreateObject();
    aObject->AddComponent(object);
    object->Deserialize(aParser);
  }
  if(aParser.Find("Transform"))
  {
    // Get Position, Scale, and Size
    Transform *transform = new Transform();
    transform->Deserialize(aParser);
    aObject->AddComponent(transform);
  }
  if(aParser.Find("Surface"))
  {
#if !defined(ANDROID) && !defined(IOS)
    PCSurface *surface = nullptr;
#else
    Surface *surface = nullptr;
#endif
    if(aParser.Find("Surface", "UIElement") && aParser.Find("Surface", "UIElement")->GetValue().ToBool())
    {
#if !defined(ANDROID) && !defined(IOS)
      surface = (PCSurface*)GetOwningApp()->GET<GraphicsManager>()->CreateUISurface();
#else
      surface = GetOwningApp()->GET<GraphicsManager>()->CreateUISurface();
#endif
    }
    else
    {
#if !defined(ANDROID) && !defined(IOS)
      surface = (PCSurface*)GetOwningApp()->GET<GraphicsManager>()->CreateSurface();
#else
      surface = GetOwningApp()->GET<GraphicsManager>()->CreateSurface();
#endif
    }

    surface->Deserialize(aParser);
    aObject->AddComponent(surface);
  }
  if(aParser.Find("Focus"))
  {
    bool isTarget = aParser.Find("Focus", "IsFocus")->GetValue().ToBool();

    if(isTarget)
    {
      GetOwningApp()->GET<GraphicsManager>()->GetScreen()->GetView().SetTarget(aObject);
    }
  }
}
开发者ID:,项目名称:,代码行数:62,代码来源:

示例7: collectBoostFromObject

void Mammut::collectBoostFromObject(const PhysicsObject & object)
{
    if (object.containsBoost())
    {
        object.collectBoost();
        if (m_collectedBoosts < s_maxNumBoosts)
            ++m_collectedBoosts;
    }
}
开发者ID:mjendruk,项目名称:mammut,代码行数:9,代码来源:Mammut.cpp

示例8: fireWeapon

Projectile AnchorLauncher::fireWeapon(PhysicsObject& origin)
{
	SphereCollisionObject projectilePhysics = SphereCollisionObject(75, 1, origin.position());
	projectilePhysics.velocity(origin.velocity() + origin.heading() * 4000);
	projectilePhysics.orientation(origin.orientation());

	resetShotCounter();
	return Projectile(projectilePhysics, ObjectType::ANCHOR_PROJECTILE, 0, 120, memoryManager());
}
开发者ID:MikeShire,项目名称:OreWar,代码行数:9,代码来源:GameObjects.cpp

示例9: PhysicsObject

PhysicsObject* Physics::CreateStaticObject()
{
    PhysicsObject* obj = new PhysicsObject(INFINITY, INFINITY, this, true);
    objects.push_back(obj);
    cpBody* body = obj->GetBody();
    if (body) {
        assert(!findObjectByBody(body));
        body_to_object[body] = obj;
    }
    return obj;
}
开发者ID:keestux,项目名称:tuxcap,代码行数:11,代码来源:Physics.cpp

示例10: assert

PhysicsObject* Physics::CreateObject(cpFloat mass, cpFloat inertia)
{
    assert(IsInitialized());
    PhysicsObject* obj = new PhysicsObject(mass, inertia, this);
    objects.push_back(obj);
    cpBody* body = obj->GetBody();
    if (body) {
        assert(!findObjectByBody(body));
        body_to_object[body] = obj;
    }
    return obj;
}
开发者ID:keestux,项目名称:tuxcap,代码行数:12,代码来源:Physics.cpp

示例11: SexyVector2

PhysicsObject* Board::MakeBox(const SexyVector2& position) 
{
  int num = 4;
  SexyVector2 verts[] = {
    SexyVector2(-15,-7),
    SexyVector2(-15, 7),
    SexyVector2( 15, 7),
    SexyVector2( 15,-7)
  };

  PhysicsObject* obj;
  obj = physics->CreateObject(1.0f, physics->ComputeMomentForPoly(1.0f, num, verts, SexyVector2(0.0f,0.0f)));
  obj->AddPolyShape(num, verts, SexyVector2(0.0f,0.0f),0.0f,1.0f);
  obj->SetPosition(position);

  return obj;
}
开发者ID:keestux,项目名称:tuxcap,代码行数:17,代码来源:Board.cpp

示例12: Behavior

ProjectileArrowBehavior::ProjectileArrowBehavior( Actor* actor, World* world, float speed ) : Behavior(actor, world)
{
	this->zSpeed = speed;
	this->zVelocity = actor->GetDir();
	this->zDamping = 0.99f;
	this->zMoving = true;
	//this->zLength = 16.396855f;

	PhysicsObject* pObj = actor->GetPhysicsObject();
	if( pObj )
	{
		Vector3 center = pObj->GetBoundingSphere().center;
		center = pObj->GetWorldMatrix() * center;
		this->zLength = ( ( center - actor->GetPosition() ) * 2).GetLength();
	}

	this->zNearByRadius = 370.0f;
	this->zHitTarget = NULL;
}
开发者ID:Crant,项目名称:Game_Project,代码行数:19,代码来源:ProjectileArrowBehavior.cpp

示例13: construct_support_mappings

//#################### PRIVATE METHODS ####################
void NarrowPhaseCollisionDetector::construct_support_mappings(const PhysicsObject& objectA, const PhysicsObject& objectB,
															  SupportMapping_CPtr& mapping, SupportMapping_CPtr& mappingA,
															  SupportMapping_CPtr& mappingS, Vector3d& interiorPoint,
															  Vector3d& relativeMovement) const
{
	// Construct the support mapping in the reference frame of A. (In that frame, A is centred at the origin.)
	// We'll be colliding a relative, swept version of B (called S) against a stationary A and then transforming
	// the result back into world space.

	Vector3d aPos0 = objectA.previous_position() ? *objectA.previous_position() : objectA.position();
	Vector3d aPos1 = objectA.position();
	Vector3d bPos0 = objectB.previous_position() ? *objectB.previous_position() : objectB.position();
	Vector3d bPos1 = objectB.position();

	Vector3d bRelPos0 = bPos0 - aPos0;
	Vector3d bRelPos1 = bPos1 - aPos1;
	relativeMovement = bRelPos1 - bRelPos0;

	// Construct the support mapping for the stationary A.
	Bounds_CPtr aBounds = objectA.bounds(m_boundsManager);
	mappingA.reset(new BoundsSupportMapping(aBounds));

	// Construct the support mapping for S (the relative, swept B).
	Bounds_CPtr bBounds = objectB.bounds(m_boundsManager);
	SupportMapping_CPtr mappingB(new BoundsSupportMapping(bBounds));
	SupportMapping_CPtr mappingL(new SegmentSupportMapping(bRelPos0, bRelPos1));
	mappingS.reset(new SweptSupportMapping(mappingB, mappingL));

	// Construct the support mapping for their Minkowski difference (S - A).
	mapping.reset(new MinkDiffSupportMapping(mappingS, mappingA));

	// Find a point interior to S - A. Note that the midpoint of B's relative movement
	// vector will do because it's definitely inside S (which is the relative sweep of
	// B as it moves), whilst A is centred at the origin and symmetrical about it, so
	// subtracting A won't move the overall shape.
	interiorPoint = (bRelPos0 + bRelPos1) / 2;

	// Ensure that the interior point isn't too near the origin. If it is, any point
	// right next to the origin can be substituted instead.
	if(interiorPoint.length_squared() < EPSILON*EPSILON) interiorPoint = Vector3d(EPSILON, 0, 0);
}
开发者ID:galek,项目名称:hesperus,代码行数:42,代码来源:NarrowPhaseCollisionDetector.cpp

示例14: collidesWith

ShurikenCollisionEvent Shuriken::collidesWith(PhysicsObject& obj) {
	ShurikenContactResultCallback callback;
	ShurikenCollisionEvent result = HIT_NOTHING;
        btDiscreteDynamicsWorld* world = physicsEngine->getPhysicsWorld();
	btRigidBody* me = physicsObject.getRigidBody();

	world->contactPairTest(me, obj.getRigidBody(), callback);
	if (callback.hit) {	
		result = HIT_NINJA;
	}
	return result;
}
开发者ID:chooper9,项目名称:cs354r-assignment4,代码行数:12,代码来源:Shuriken.cpp

示例15: sizeof

		PhysicsObject * PhysicsScene::AddStaticObject(const glm::vec3 * const convexVertices, unsigned int verticesCount, const physx::PxVec3 & position, const physx::PxReal & staticFriction, const physx::PxReal & dynamicFriction, const physx::PxReal & restitution)
		{
			physx::PxConvexMeshDesc convexDesc;
			convexDesc.points.count = verticesCount;
			convexDesc.points.stride = sizeof(glm::vec3);
			convexDesc.points.data = convexVertices;
			convexDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX;

			physx::PxDefaultMemoryOutputStream buffer;
			if(!m_cooking->cookConvexMesh(convexDesc, buffer))
			{
				return NULL;
			}

			physx::PxDefaultMemoryInputData input(buffer.getData(), buffer.getSize());
			physx::PxConvexMesh* convexMesh = m_physics->createConvexMesh(input);

			PhysicsObject * physicsObject = new PhysicsStaticObject(m_physics, convexMesh, position, staticFriction, dynamicFriction, restitution);
			m_physicObjects.push_back(physicsObject);

			m_scene->addActor(*(physicsObject->GetActor()));

			return physicsObject;
		}
开发者ID:Tetriste,项目名称:LudumDare29,代码行数:24,代码来源:PhysicsScene.cpp


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