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


C++ TransformComponent::setPosition方法代码示例

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


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

示例1: update

void PhysComponent::update()
{
	if (m_Obj->hasComponent("Transform")) {
		TransformComponent* tc = (TransformComponent*)m_Obj->getComponent("Transform");
		b2Vec2 pos = m_Body->GetPosition();
		tc->setPosition((double)pos.x, (double)pos.y);
		tc->setRotation( m_Body->GetAngle() * (180.0f / (float)Gosu::pi));
	}
}
开发者ID:ChadyG,项目名称:MUGE,代码行数:9,代码来源:SceneObject.cpp

示例2: size

PongField::PongField(Scene& scene) :
	Entity(scene)
{
	Vector2f size(800.f, 600.f);
	Engine& engine = m_Scene.getEngine();

	// Add Component
	TransformComponent* transform = new TransformComponent(*this);
	add<TransformComponent>(transform);

	RectangleColliderComponent* collider = new RectangleColliderComponent(*this, engine);
	add<RectangleColliderComponent>(collider);

	// Init
	collider->setSize(size);
	transform->setPosition(0, 0);
}
开发者ID:Dragnalith,项目名称:Nawp,代码行数:17,代码来源:PongField.cpp

示例3: processEntity

void MovementSystem::processEntity( Entity& e )
{
	TurnFactorComponent* turnFactorComponent = turnFactorComponentMapper.get(e);
	TransformComponent* transformComponent = transformComponentMapper.get(e);

	float dt = world->getDelta();

	if (turnFactorComponent != NULL)
	{
		float previousAngle = turnFactorComponent->getAngleInDegrees();
		turnFactorComponent->setAngleInDegrees(previousAngle + dt * 100.0f);
	}

	Vector2 previousPosition = transformComponent->getPosition();
	Vector2 position = previousPosition.add(Vector2(dt*60.0f, dt*20.0f));
	if (position.getX() > 1024) position.setX(512);
	if (position.getX() < 0) position.setX(512);
	if (position.getY() < 0) position.setY(384);
	if (position.getY() > 768) position.setY(384);
	transformComponent->setPosition(position);

	SpatialComponent* spatialComponent = spatialComponentMapper.get(e);
	if ((spatialComponent->needToRemoveTurnFactor) == true)
	{
		e.removeComponent<TurnFactorComponent>();
		spatialComponent->needToRemoveTurnFactor = false;
		spatialComponent->isTurnFactorRemoved = true;
		spatialComponent->needToSetToAddTurnFactor = true;
	}
	if ((spatialComponent->needToAddTurnFactor) == true)
	{
		e.addComponent(new TurnFactorComponent());
		spatialComponent->needToAddTurnFactor = false;
		spatialComponent->isTurnFactorSetToRemove = false;
	}
}
开发者ID:XoDeR,项目名称:RioEngine,代码行数:36,代码来源:MovementSystem.cpp

示例4: onSceneLoad

	// Example 2D physics scene.
	void PhysicsTestScene::onSceneLoad(GameInstance *instance)
	{
		ContextData *context = instance->getContextData();

		{
			Entity *entity = rtti::dynamicCast<Entity>(rtti::RTTI::generateSerializable("Entity", instance->getContextData()));;
			entity->setName("background");

			TransformComponent *transform = rtti::dynamicCast<TransformComponent>(rtti::RTTI::generateSerializable("TransformComponent", instance->getContextData()));

			transform->setPosition(math::Vec3(0.f, 0.f, LAYER_BACKGROUND_0));
			transform->setDirection(math::Vec3(0.0f, 0.0f, 1.f));
			transform->setScale(150.f);

			renderer::SpriteComponent *sprite = rtti::dynamicCast<renderer::SpriteComponent>(rtti::RTTI::generateSerializable("SpriteComponent", instance->getContextData()));
			sprite->setTexture("grass.png");
			sprite->setDisableCullCheck(true);

			entity->addComponent(transform);
			entity->addComponent(sprite);

			instance->getScene()->addEntity(entity);
		}

		{
			Entity *entity = rtti::dynamicCast<Entity>(rtti::RTTI::generateSerializable("Entity", instance->getContextData()));;
			entity->setName("block");

			TransformComponent *transform = rtti::dynamicCast<TransformComponent>(rtti::RTTI::generateSerializable("TransformComponent", instance->getContextData()));

			transform->setPosition(math::Vec3(0.f, 50.f, LAYER_BACKGROUND_0));
			transform->setDirection(math::Vec3(-0.5f, 0.5f, 1.f));
			transform->setScale(1.f);

			renderer::SpriteComponent *sprite = rtti::dynamicCast<renderer::SpriteComponent>(rtti::RTTI::generateSerializable("SpriteComponent", instance->getContextData()));
			sprite->setTexture("biggrass.png");

			physics::Box2DRigidBodyComponent *phys = rtti::dynamicCast<physics::Box2DRigidBodyComponent>(rtti::RTTI::generateSerializable("Box2DRigidBodyComponent", instance->getContextData()));

			phys->setMass(5);
			phys->setFriction(1.f);
			phys->setDensity(1.0f);
			phys->setRestitution(0.8f);
			phys->setKinematic(true);
			phys->setGroup(physics::BOX2D_GROUP_LEVEL);

			entity->addComponent(transform);
			entity->addComponent(sprite);
			entity->addComponent(phys);

			instance->getScene()->addEntity(entity);
		}


		for (unsigned i = 0; i < 2000; ++i)
		{
			Entity *entity = rtti::dynamicCast<Entity>(rtti::RTTI::generateSerializable("Entity", instance->getContextData()));;
			entity->setName("block");

			TransformComponent *transform = rtti::dynamicCast<TransformComponent>(rtti::RTTI::generateSerializable("TransformComponent", instance->getContextData()));

			transform->setPosition(math::Vec3(150.f + i * 250.f, 50.f, LAYER_BACKGROUND_0));
			transform->setDirection(math::Vec3(-0.5f, 0.5f, 1.f));
			transform->setScale(1.f);

			renderer::SpriteComponent *sprite = rtti::dynamicCast<renderer::SpriteComponent>(rtti::RTTI::generateSerializable("SpriteComponent", instance->getContextData()));
			sprite->setTexture("biggrass.png");

			physics::Box2DRigidBodyComponent *phys = rtti::dynamicCast<physics::Box2DRigidBodyComponent>(rtti::RTTI::generateSerializable("Box2DRigidBodyComponent", instance->getContextData()));

			phys->setMass(5);
			phys->setFriction(1.f);
			phys->setDensity(1.0f);
			phys->setRestitution(0.8f);
			phys->setKinematic(true);
			phys->setGroup(physics::BOX2D_GROUP_LEVEL);

			entity->addComponent(transform);
			entity->addComponent(sprite);
			entity->addComponent(phys);

			instance->getScene()->addEntity(entity);
		}

		unsigned l = 10;
		for (unsigned i = 0; i < 10; ++i)
		{
			Entity *entity = rtti::dynamicCast<Entity>(rtti::RTTI::generateSerializable("Entity", instance->getContextData()));;
			entity->setName("Object");

			TransformComponent *transform = rtti::dynamicCast<TransformComponent>(rtti::RTTI::generateSerializable("TransformComponent", instance->getContextData()));

			transform->setPosition(math::Vec3(0.f, 750.f + 150.f * i, LAYER_OBJECT_1));

			transform->setDirection(math::Vec3(0.f, 0.f, 1.f));
			transform->setScale(1.f);

			renderer::SpriteComponent *sprite = rtti::dynamicCast<renderer::SpriteComponent>(rtti::RTTI::generateSerializable("SpriteComponent", instance->getContextData()));
			sprite->setTexture("isopropelli.png");
//.........这里部分代码省略.........
开发者ID:LauriM,项目名称:PropellerEngine,代码行数:101,代码来源:PhysicsTestScene.cpp

示例5: onSceneLoad

	// instance provides access to the engine when the load is happening, all the changes should be loaded against it.
	void PhysicsTestScene::onSceneLoad(GameInstance *instance)
	{
		// Scopes are here just to make it easier to use the same name multiple times (entity, etc)
		{
			// creating a static ground with box2d physics
			Entity *entity = rtti::generate<Entity>(instance->getContextData());
			entity->setName("Ground");

			TransformComponent *transform = rtti::generate<TransformComponent>(instance->getContextData());

			// set position of the ground
			transform->setPosition(math::Vec3(50.f, 550.f, 0.f));
			transform->setDirection(math::Vec3(0.f, 0.f, 1.f));
			transform->setScale(1.f);

			// Create spritecomponent to display the image
			renderer::SpriteComponent *sprite = rtti::generate<renderer::SpriteComponent>(instance->getContextData());
			sprite->setTexture("hellknight.png"); // hellknight.png is automatically loaded and cached by the RendererSystem, etc on the background, no need to worry about it

			// Lets add 2D-physics
			physics::Box2DRigidBodyComponent *phys = rtti::generate<physics::Box2DRigidBodyComponent>(instance->getContextData());

			phys->setFriction(1.f);
			phys->setMass(5);
			phys->setDensity(1.0f);
			phys->setKinematic(true); // kinematic makes the object static. (useful for ground, etc)

			// Lets add all the components to the entity
			entity->addComponent(transform);
			entity->addComponent(sprite);
			entity->addComponent(phys);

			// aaand lets add the entity to the scene!
			instance->getScene()->addEntity(entity);
		}

		// And the lets create the player,
		{
			Entity *entity = rtti::generate<Entity>(instance->getContextData());
			entity->setName("Player"); // name can be checked  during the code, but string comparison is slow, so I would recommend to check against something else
			// for example if only the player has "PlayerInfoComponent" or something like that, you can try to find that component to 
			// detect the player.

			TransformComponent *transform = rtti::generate<TransformComponent>(instance->getContextData());

			transform->setPosition(math::Vec3(50.f, 750.f, 0.2f));
			transform->setDirection(math::Vec3(0.f, 0.f, 1.f));
			transform->setScale(1.f);

			renderer::SpriteComponent *sprite = rtti::generate<renderer::SpriteComponent>(instance->getContextData());
			sprite->setTexture("testcube.png");

			physics::Box2DRigidBodyComponent *phys = rtti::generate<physics::Box2DRigidBodyComponent>(instance->getContextData());

			phys->setMass(5);
			phys->setFriction(1.f);
			phys->setDensity(1.0f);
			phys->setKinematic(false);

			player::PlayerInputComponent *playerInput = rtti::generate<player::PlayerInputComponent>(instance->getContextData());

			// camera is used to center the camera to the player
			scene::CameraComponent *camera = rtti::generate<scene::CameraComponent>(instance->getContextData());

			renderer::LightComponent *light = rtti::generate<renderer::LightComponent>(instance->getContextData());
			light->setColor(math::Vec3(0.8f, 0.8f, 1.f));

			entity->addComponent(transform);
			entity->addComponent(sprite);
			entity->addComponent(phys);
			entity->addComponent(playerInput);
			entity->addComponent(light);
			entity->addComponent(camera);

			instance->getScene()->addEntity(entity);

			camera->setActive(true);
		}

		LOG_INFO("Physics test scene loaded!");
	}
开发者ID:LauriM,项目名称:PropellerEngine,代码行数:82,代码来源:ExampleScene.cpp


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