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


C++ TransformComponent类代码示例

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


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

示例1: addModel

Actor* addModel(string filename, vec3 pos = vec3(0), vec3 s = vec3(1))
{

	Actor* sphere = new Actor;

	TransformComponent* trans = new TransformComponent();
	trans->setPos(pos);

	trans->setScale(s);
	sphere->addComponent(trans);
	glDebug();
	sphere->addComponent(new StaticMeshStaticPhysicsComponent(AssetManager::getBasePath() + filename));
	glDebug();
	MeshGraphicComponent* mesh = new MeshGraphicComponent(AssetManager::getBasePath() + filename);
	glDebug();
	mesh->setTextureMatrix(mat2(scale(mat4(1), vec3(10))));
	glDebug();
	Material *mat = new Material();
	glDebug();
	mat->setDiffuse(AssetManager::getBasePath() + "Data/Texture/floor1_d.png");
	mat->setNormal(AssetManager::getBasePath() + "Data/Texture/floor1_n.png");
	mat->setSpecular(AssetManager::getBasePath() + "Data/Texture/floor1_s.png");
	mat->setShininess(20);
	glDebug();
	mesh->addMaterial(mat);
	glDebug();
	sphere->addComponent(mesh);
	glDebug();
	return sphere;
}
开发者ID:ennioquaglia,项目名称:GameEngine,代码行数:30,代码来源:main.cpp

示例2:

	math::Vec3 TransformComponent::getPosition()
	{
		// Go trough parents and add transform from those to this.

		// Current entity
		Entity *ent = (Entity*)getParent();

		if (ent == NULL)
			return position;

		// Get current entities parent
		Entity *parent = ent->getParentEntity();

		if (parent == NULL)
			return position;

		TransformComponent *parentTransform = parent->findComponent<TransformComponent>();

		if (parentTransform == NULL)
			return position;

		//TODO: Add parenting to the rotation

		return parentTransform->getPosition() + position;
	}
开发者ID:LauriM,项目名称:PropellerEngine,代码行数:25,代码来源:TransformComponent.cpp

示例3: addMap

Actor* addMap()
{
	Actor* sphere = new Actor;

	TransformComponent* trans = new TransformComponent();

	trans->setPos(vec3(0, -0.01, 0));
	Rotation rot;
	rot.setEulerAngles(vec3(0, 0.785, 0));
	trans->setRotation(rot);
	sphere->addComponent(trans);
	glDebug();
	sphere->addComponent(new StaticMeshStaticPhysicsComponent(AssetManager::getBasePath() + "Data/Model/mappa4.obj"));
	glDebug();
	MeshGraphicComponent* mesh = new MeshGraphicComponent(AssetManager::getBasePath() + "Data/Model/mappa4.obj");
	glDebug();
	mesh->setTextureMatrix(mat2(scale(mat4(1), vec3(10))));
	glDebug();
	Material *mat = new Material();
	glDebug();
	mat->setDiffuse(AssetManager::getBasePath() + "Data/Texture/floor1_d.png");
	mat->setNormal(AssetManager::getBasePath() + "Data/Texture/floor1_n.png");
	mat->setSpecular(AssetManager::getBasePath() + "Data/Texture/floor1_s.png");
	mat->setShininess(20);
	glDebug();
	mesh->addMaterial(mat);
	glDebug();
	sphere->addComponent(mesh);
	glDebug();
	return sphere;
}
开发者ID:ennioquaglia,项目名称:GameEngine,代码行数:31,代码来源:main.cpp

示例4: PxMatrixToMat4x4

void PhysXPhysics::VSyncVisibleScene()
{
	for (ActorIdToPysXRigidBodyTable::const_iterator it = m_actorRigidBodyMap.begin(); it != m_actorRigidBodyMap.end(); it++)
	{
		ActorId const id = it->first;

		PxTransform pxLoc = it->second->getGlobalPose();
		Mat4x4 loc;
		PxMatrixToMat4x4(PxMat44(pxLoc), &loc);
		
		Actor* pActor = g_pApp->m_pGame->VGetActor(id);
		if (pActor)
		{
			TransformComponent* pTransformComponent = pActor->GetComponent<TransformComponent>(TransformComponent::g_Name);

			if (pTransformComponent)
			{
				if (pTransformComponent->GetTransform() != loc)
				{
					Vec3 rot = loc.GetYawPitchRoll();
					pTransformComponent->SetPosition(loc.GetPosition());
					pTransformComponent->SetRotation(Vec3(XMConvertToDegrees(rot.x), XMConvertToDegrees(rot.y), XMConvertToDegrees(rot.z)));
					EventDataPtr pEvent(BE_NEW EvtData_Move_Actor(id, loc));
					IEventManager::Get()->VQueueEvent(pEvent);
				}
			}
		}
	}
}
开发者ID:jel-massih,项目名称:BombastEngine,代码行数:29,代码来源:PhysXPhysics.cpp

示例5: draw

void RenderSystem::draw(GameObject* gameObject)
{
	RenderComponent* render = gameObject->getComponent<RenderComponent>();
	if (render != nullptr)
	{
		RectangleShape shape = *render->getDrawable();

		TransformComponent* transform = gameObject->getComponent<TransformComponent>();
		if (transform != nullptr)
		{
			shape.setPosition(transform->getPosition());
		}
		else
		{
			BoardComponent* boardComp = gameObject->getComponent<BoardComponent>();
			if (boardComp != nullptr && mBoard != nullptr)
			{
				Vector2i boardPos = boardComp->getPosition();
				shape.setPosition(mBoard->getTilePosition(boardPos.x, boardPos.y));
			}
		}

		mWindow->draw(shape);
	}
}
开发者ID:tuomoO,项目名称:Ristinolla,代码行数:25,代码来源:RenderSystem.cpp

示例6:

//Busca enemigos
void CameraController3rd::lookForEnemies()
{
	std::map<Entity*,Component*>* entitiesWithED = EntityManager::get().getAllEntitiesPosessingComponent<EnemyDataComponent>();
	if(!entitiesWithED) return;

	float distance = FLT_MAX;
	float min_distance = distance;

	std::map<Entity*,Component*>::iterator iter;
	for (iter = entitiesWithED->begin(); iter != entitiesWithED->end(); ++iter)
	{
		if( iter->second->enabled ) 
		{
			Entity* entity = iter->first;
			TransformComponent* transformEnemy = EntityManager::get().getComponent<TransformComponent>(entity);
			
			float angle = _front.angle(transformEnemy->getPosition() - _camera->getPosition());

			//dbg("angle: %f\n", angle);
		
			if( angle < 1.0f )
			{		
				distance = transformEnemy->getPosition().distance2(_camera->getTarget());
				//dbg("distance: %f\n", distance);
				
				if(distance < 30.0f && distance < min_distance)
				{	
					_lockedEntity = entity;
					min_distance = distance;
				}
			}			
		}
	}
}
开发者ID:xDavidLeon,项目名称:pathofshadowsprototype,代码行数:35,代码来源:camera_controller_3rd.cpp

示例7: addAxis3

Actor* addAxis3()
{
	Actor* actor = new Actor;

	TransformComponent* trans = new TransformComponent();
	trans->setPos(vec3(-5, 0, 5));

	Rotation rot;
	rot.setNormalDirection(vec3(1, 0, 0));
	trans->setRotation(rot);

	actor->addComponent(trans);
	MeshGraphicComponent* mesh = new MeshGraphicComponent(AssetManager::getBasePath() + "Data/Model/axis.obj");
	Material *mat = new Material();
	mat->setDiffuse("#FF0000");
	mesh->addMaterial(mat);
	Material *mat1 = new Material();
	mat1->setDiffuse("#00FF00");
	mesh->addMaterial(mat1);
	mesh->addMaterial(mat1);
	Material *mat2 = new Material();
	mat2->setDiffuse("#0000FF");
	mesh->addMaterial(mat2);
	actor->addComponent(mesh);
	return actor;
}
开发者ID:ennioquaglia,项目名称:GameEngine,代码行数:26,代码来源:main.cpp

示例8: Update

void BulletScript::Update(GameEngine *game)
{
	TransformComponent *transform = this->gameObject->GetComponent<TransformComponent*>();
	transform->move(20, 0);	
	for (std::vector<GameObject*>::iterator it = this->gameObject->gameScene->gameObjects.begin(); it != this->gameObject->gameScene->gameObjects.end(); it++)
	{
		ColliderComponent *thisObject = this->gameObject->GetComponent<ColliderComponent*>();
		if ((*it)->getName() == "enemy")
		{			
			ColliderComponent *anotherObject = (*it)->GetComponent<ColliderComponent*>();			
			if (anotherObject != NULL && thisObject != anotherObject)
			{			
				//std::cout << anotherObject->getX();
				if (thisObject->getX() + thisObject->getWidth() >= anotherObject->getX() && thisObject->getX() <= anotherObject->getX() + anotherObject->getWidth()
					&& thisObject->getY() + thisObject->getHeight() >= anotherObject->getY() && thisObject->getY() <= anotherObject->getY() + anotherObject->getHeight())
				{					
					(*it)->setEnable(false);
					//BulletScript::SCORE++;
					//std::cout << BulletScript::SCORE++;
					/*
					score_ = db->load_int_data("pontos");
					db->save_data("pontos", score_++, 0, 0);					
					TextComponent * text = this->gameObject->GetComponent<TextComponent*>();					
					text->set_string(std::string("score: " + score_));*/
					(*score)++;
				}
			}

		}
	}
}
开发者ID:runewather,项目名称:SFMLGameFramework,代码行数:31,代码来源:BulletScript.cpp

示例9:

	void
	CollisionComponent::Update(GameObject& gameObject, double)
	{
		TransformComponent *transform = static_cast<TransformComponent*>(gameObject.FilterComponent("Transform").front().get());
		SDL_Rect pos = transform->GetPosition();

		this->_collider->SetPosition(Vector2D((float)pos.x, (float)pos.y));
	}
开发者ID:teemitzitrone,项目名称:Chase-the-Shadow,代码行数:8,代码来源:CollisionComponent.cpp

示例10: while

void PlayerControllerSubsystem::process(unsigned int dt)
{
    ALLEGRO_EVENT ev;
    while (events.get(&ev))
    {
        if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
        {
            switch (ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_W: button_states[MOVE_FORWARD] = true; break;
                case ALLEGRO_KEY_A: button_states[ROTATE_LEFT] = true; break;
                case ALLEGRO_KEY_S: button_states[MOVE_BACKWARD] = true; break;
                case ALLEGRO_KEY_D: button_states[ROTATE_RIGHT] = true; break;
            }
        }
        else if (ev.type == ALLEGRO_EVENT_KEY_UP)
        {
            switch (ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_W: button_states[MOVE_FORWARD] = false; break;
                case ALLEGRO_KEY_A: button_states[ROTATE_LEFT] = false; break;
                case ALLEGRO_KEY_S: button_states[MOVE_BACKWARD] = false; break;
                case ALLEGRO_KEY_D: button_states[ROTATE_RIGHT] = false; break;
            }
        }
    }

    for (std::set<Entity>::const_iterator iter = active.begin(); iter != active.end(); iter++)
    {
        TransformComponent *tc = world->get<TransformComponent>(*iter);

        static const float max_speed = 0.3;
        if (tc->velocity.squaredNorm() > max_speed * max_speed)
        {
            tc->velocity *= 1 / tc->velocity.norm() * max_speed;
        }

        if (button_states[MOVE_FORWARD])
        {
            tc->acceleration(0) += cos(tc->rotation) / 1000;
            tc->acceleration(1) += sin(tc->rotation) / 1000;
        }
        if (button_states[MOVE_BACKWARD])
        {
            tc->acceleration(0) -= cos(tc->rotation) / 1000;
            tc->acceleration(1) -= sin(tc->rotation) / 1000;
        }

        if (button_states[ROTATE_LEFT])
        {
            tc->rotation += 0.1;
        }
        if (button_states[ROTATE_RIGHT])
        {
            tc->rotation -= 0.1;
        }
    }
}
开发者ID:raphtown,项目名称:sputnik,代码行数:58,代码来源:player_controller_subsystem.cpp

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

示例12: JunctionQueue

JunctionQueue *GraphicSystem::Process(Entity *entity) {
	TransformComponent *transform = (TransformComponent*)(entity->GetComponent(Component::ComponentType::Transform));
	GraphicsComponent *graphics = (GraphicsComponent*)(entity->GetComponent(Component::ComponentType::Graphics));
	
	graphics->SetPos(transform->GetX(), transform->GetY());
	graphics->SetRotation(transform->GetRotation());
	graphics->Draw(_window);

	return new JunctionQueue();
}
开发者ID:ScottWe,项目名称:Component-Engine,代码行数:10,代码来源:GraphicSystem.cpp

示例13: update

	void update() {

		if(win->inputManager->isKeyPressed(GLFW_KEY_F2)) {
			scene->addActor(addSphereLight());
		}
		if(win->inputManager->isKeyPressed(GLFW_KEY_F3)) {
			TransformComponent* trans = mainchar->getComponent<TransformComponent>(ComponentId::Transform);
			Debug(trans->getPos());
		}

	}
开发者ID:ennioquaglia,项目名称:GameEngine,代码行数:11,代码来源:main.cpp

示例14: BE_ASSERT

void PhysXPhysics::AddShape(Actor* pActor, PxGeometry* geometry, float density, const std::string& physicsMaterial, bool gravityEnabled, float linearDamping, float angularDamping, const std::string& bodyType)
{
	BE_ASSERT(pActor);
	ActorId actorId = pActor->GetId();
	BE_ASSERTf(m_actorRigidBodyMap.find(actorId) == m_actorRigidBodyMap.end(), "Actor with more than one rigidbody");

	Mat4x4 transform = Mat4x4::g_Identity;
	
	TransformComponent* pTransformComponent = pActor->GetComponent<TransformComponent>(TransformComponent::g_Name);

	if (pTransformComponent)
	{
		transform = pTransformComponent->GetTransform();
	}
	else 
	{
		//Doesnt work without transform
		BE_ERROR("Actor %s PhysicsComponent requires Shape to have Transform Component: %d", actorId);
		return;
	}

	PhysicsMaterialData material(LookupMaterialData(physicsMaterial));
	PxMaterial* mat = m_pPhysicsSdk->createMaterial(material.m_friction, material.m_friction, material.m_restitution);

	Vec3 translation, scale;
	Quaternion rotation;
	
	bool ok = transform.Decompose(translation, rotation, scale);
	PxQuat pxRot;
	PxVec3 pxLoc;
	Vec3ToPxVec(translation, &pxLoc);
	QuaternionToPxQuat(rotation, &pxRot);
	PxTransform t(pxLoc, pxRot);

	if (bodyType == "Dynamic")
	{
		PxRigidDynamic* body = PxCreateDynamic(*m_pPhysicsSdk, t, *geometry, *mat, density);
		body->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, !gravityEnabled);
		PxRigidBodyExt::updateMassAndInertia(*body, density);
		body->setLinearDamping(linearDamping);
		body->setAngularDamping(angularDamping);
		m_pScene->addActor(*body);

		m_actorRigidBodyMap[actorId] = body;
		m_rigidBodyActorMap[body] = actorId;
	}
	else
	{
		BE_ERROR("[Physics] BodyType not supported: %s", bodyType.c_str());
		return;
	}
}
开发者ID:jel-massih,项目名称:BombastEngine,代码行数:52,代码来源:PhysXPhysics.cpp

示例15: InitializeTransformComponent

    bool InitializeTransformComponent(IActorComponent* cmp, ICMStream* stream)
    {
        TransformComponent* transformation = (TransformComponent*)cmp;
        tinyxml2::XMLElement* pData = (tinyxml2::XMLElement*)stream;
        tinyxml2::XMLElement* trans = pData->FirstChildElement("Position");

        if(trans)
        {
            float x, y, z;
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != trans->QueryFloatAttribute("x", &x));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != trans->QueryFloatAttribute("y", &y));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != trans->QueryFloatAttribute("z", &z));
            transformation->GetTransformation()->Translate(x, y, z);
        }

        tinyxml2::XMLElement* rot = pData->FirstChildElement("Rotation");

        if(rot)
        {
            float x, y, z, w;
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("x", &x));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("y", &y));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("z", &z));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("w", &w));
            transformation->GetTransformation()->SetRotateQuat(x, y, z, w);
        }

        rot = pData->FirstChildElement("AxisAngle");

        if(rot)
        {
            float x, y, z, w;
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("x", &x));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("y", &y));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("z", &z));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != rot->QueryFloatAttribute("w", &w));
            transformation->GetTransformation()->SetRotation(util::Vec3(x, y, z), w);
        }

        tinyxml2::XMLElement* scale = pData->FirstChildElement("Scale");

        if(scale)
        {
            float x, y, z;
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != scale->QueryFloatAttribute("x", &x));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != scale->QueryFloatAttribute("y", &y));
            RETURN_IF_FAILED(tinyxml2::XML_NO_ATTRIBUTE != scale->QueryFloatAttribute("z", &z));
            transformation->GetTransformation()->SetScale(x, y, z);
        }
        
        return true;
    }
开发者ID:moresascha,项目名称:Chimera,代码行数:52,代码来源:ComponentInitializer.cpp


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