本文整理汇总了C++中MeshRenderer::SetMesh方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshRenderer::SetMesh方法的具体用法?C++ MeshRenderer::SetMesh怎么用?C++ MeshRenderer::SetMesh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshRenderer
的用法示例。
在下文中一共展示了MeshRenderer::SetMesh方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: main
int main(int argc, char** argv)
{
// Create freeglut window
GlutWindowManager* windowMgr = GlutWindowManager::GetInstance();
//StaticData::SetWindowManager(windowManager);
windowMgr->Init(argc, argv);
Window* window = windowMgr->NewWindow(1, 500, 500, 200, 200, "Window 1");
// Create mesh renderer (init openGL)
MeshRenderer* meshRenderer = new MeshRenderer(WINDOW_WIDTH, WINDOW_HEIGHT);
//StaticData::SetMeshRenderer(meshRenderer);
meshRenderer->Init();
// Load mesh
Mesh* mesh = NULL;
Rendering::Operators::ObjReader::LoadMesh("Models\\cube.obj", mesh, true);
Rendering::Operators::MeshTransformation::Triangulate(mesh);
mesh->ComputeNormals();
mesh->color = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f);
meshRenderer->SetMesh(mesh);
meshRenderer->SetRenderMode((RenderMode)(RenderMode::VERTICES | RenderMode::WIREFRAME));
meshRenderer->SetLightType(LightType::POINT_LIGHT);
meshRenderer->SetLightColor(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
//Operators::MeshTransformation::Inflate(mesh, 0.1f);
//meshRenderer->UpdateMeshConnectivity();
// Create a WindowRenderer and link it to the window
WindowRenderer winRenderer(meshRenderer);
window->Attach(&winRenderer);
// Create manipulators
MouseManipulator mouseManip(meshRenderer);
Mouse* mouse = windowMgr->GetMouse();
mouse->Attach(&mouseManip);
// Start main loop
windowMgr->Display();
//delete windowManager;
delete meshRenderer;
return 0;
}
示例3: 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;
}
示例4: Render
void Scene::Render( RenderPass renderPass, Viewport* viewport )
{
static Mesh* skyboxMesh = ResourceManager::GetGenMesh(GenMeshes::Cube);
std::string viewportName = viewport != NULL ? viewport->GetName() : "";
bool ignoreShadowCast = true;
if (renderPass == RenderPass::ShadowPass)
{
ignoreShadowCast = false;
}
for (uint rank = 0; rank < m_layers.size(); rank++)
{
if ( !m_layers[rank]->IsEnabled() ) continue;
RenderManager::UseNewLayer(renderPass);
if (rank == 0)
{
if ( m_skyboxMaterial != NULL && renderPass != RenderPass::PickingPass )
{
Transform transform(NULL);
transform.SetPositionWorld( RenderManager::GetRenderCamera()->GetComponent<Transform>()->GetPositionWorld() );
transform.SetScaleWorld( Vector3(m_skyboxSize) );
MeshRenderer renderer;
renderer.SetMaterial(m_skyboxMaterial);
renderer.SetMesh(skyboxMesh);
renderer.SetFaceCulling( FaceCulling::CULL_FRONT );
RenderManager::ObjectToRender objectToRender;
objectToRender.transform = &transform;
objectToRender.meshRenderer = &renderer;
objectToRender.renderPass = renderPass;
RenderManager::RenderObject( objectToRender );
}
GizmoManager::RenderGrid( renderPass );
}
#if (ME3D_SHADING_MODE == ME3D_CLASSIC_SHADING)
if (viewport != NULL && viewport->HasEnableLights() && renderPass != RenderPass::PickingPass)
{
for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
{
GameObject* obj = m_layers[rank]->GetObjectAt(j);
if (obj->IsFullyActive())
{
Light* lightComp = obj->GetComponent<Light>();
if (lightComp != NULL && lightComp->IsEnabled())
{
RenderManager::ActiveLight activeLight;
activeLight.light = lightComp;
activeLight.transform = obj->GetComponent<Transform>();
RenderManager::AddActiveLight( activeLight );
}
}
}
}
#endif
for (uint j = 0; j < m_layers[rank]->GetObjectsCount(); j++)
{
GameObject* obj = m_layers[rank]->GetObjectAt(j);
if ( !obj->IsIgnoringViewport(viewportName)
&& obj->IsFullyActive() )
{
GizmoManager::RenderFollower( obj, renderPass );
MeshRenderer* renderer = obj->GetComponent<MeshRenderer>();
GuiTexture* guiTexture = obj->GetComponent<GuiTexture>();
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (renderer != NULL &&
renderer->GetMaterial() != NULL &&
renderer->GetMesh() != NULL &&
(ignoreShadowCast || renderer->IsCastingShadows()) )
{
RenderManager::ObjectToRender objectToRender;
objectToRender.uniqueIndex = obj->GetUniqueIndex();
objectToRender.transform = obj->GetComponent<Transform>();
objectToRender.meshRenderer = renderer;
objectToRender.renderPass = renderPass;
RenderManager::RenderObject( objectToRender );
}
//.........这里部分代码省略.........