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


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

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


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

示例1: 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

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