本文整理汇总了C++中MeshRenderer类的典型用法代码示例。如果您正苦于以下问题:C++ MeshRenderer类的具体用法?C++ MeshRenderer怎么用?C++ MeshRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MeshRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: XMFLOAT3
// 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: Vector2
//-----------------------------------------------------------------------------------
void Path::Render() const
{
MeshBuilder builder;
builder.Begin();
const float TILE_SIZE = 25.0f;
for (PathNode* node : m_openList)
{
Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE;
builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x0000FF7F));
Renderer::instance->DrawText2D(bottomLeft, std::to_string(node->f).substr(0, 4), 0.5f, RGBA::WHITE, false, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape"));
}
for (PathNode* node : m_closedList)
{
Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE;
builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0xFF00007F));
Renderer::instance->DrawText2D(bottomLeft, std::to_string(node->f).substr(0, 4), 0.5f, RGBA::WHITE, false, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape"));
}
for (PathNode* node : m_resultantPath)
{
Vector2 bottomLeft = Vector2(node->position) * TILE_SIZE;
builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x00FF007F));
}
Vector2 bottomLeft = (Vector2(m_currentGoal) * TILE_SIZE);
builder.AddTexturedAABB(AABB2(bottomLeft, bottomLeft + (Vector2::ONE * TILE_SIZE)), Vector2::ZERO, Vector2::ONE, RGBA(0x00FF007F));
builder.End();
Mesh* mesh = new Mesh();
builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
MeshRenderer* renderer = new MeshRenderer(mesh, Renderer::instance->m_defaultMaterial);
renderer->Render();
delete mesh;
}
示例3: Mesh
//-----------------------------------------------------------------------------------
void Renderer::DrawVertexArray(const Vertex_PCT* vertexes, int numVertexes, DrawMode drawMode /*= DrawMode::QUADS*/)
{
if (numVertexes == 0)
{
return;
}
MeshBuilder builder;
builder.Begin();
for (int i = 0; i < numVertexes; ++i)
{
builder.SetColor(vertexes[i].color);
builder.SetUV(vertexes[i].texCoords);
builder.SetTBN(Vector3::ZERO, Vector3::ZERO, Vector3::ZERO);
builder.AddVertex(vertexes[i].pos);
builder.AddIndex(i);
}
builder.End();
Mesh* mesh = new Mesh();
builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
mesh->m_drawMode = drawMode;
MeshRenderer* thingToRender = new MeshRenderer(mesh, m_defaultMaterial);
m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
GL_CHECK_ERROR();
thingToRender->Render();
delete mesh;
}
示例4: UNUSED
//-----------------------------------------------------------------------------------
void Renderer::DrawText2D(const Vector2& position, const std::string& asciiText, float scale, const RGBA& tint /*= RGBA::WHITE*/, bool drawShadow /*= false*/, const BitmapFont* font /*= nullptr*/, const Vector2& right /*= Vector3::UNIT_X*/, const Vector2& up /*= Vector3::UNIT_Z*/)
{
//To be used when I expand this method to 3D text
UNUSED(up);
UNUSED(right);
if (asciiText.empty())
{
return;
}
if (font == nullptr)
{
font = m_defaultFont;
}
int stringLength = asciiText.size();
Vector2 cursorPosition = position + (Vector2::UNIT_Y * (float)font->m_maxHeight * scale);
const Glyph* previousGlyph = nullptr;
MeshBuilder builder;
builder.Begin();
for (int i = 0; i < stringLength; i++)
{
unsigned char currentCharacter = asciiText[i];
const Glyph* glyph = font->GetGlyph(currentCharacter);
float glyphWidth = static_cast<float>(glyph->width) * scale;
float glyphHeight = static_cast<float>(glyph->height) * scale;
if (previousGlyph)
{
const Vector2 kerning = font->GetKerning(*previousGlyph, *glyph);
cursorPosition += (kerning * scale);
}
Vector2 offset = Vector2(glyph->xOffset * scale, -glyph->yOffset * scale);
Vector2 topRight = cursorPosition + offset + Vector2(glyphWidth, 0.0f);
Vector2 bottomLeft = cursorPosition + offset - Vector2(0.0f, glyphHeight);
AABB2 quadBounds = AABB2(bottomLeft, topRight);
AABB2 glyphBounds = font->GetTexCoordsForGlyph(*glyph);
if (drawShadow)
{
float shadowWidthOffset = glyphWidth / 10.0f;
float shadowHeightOffset = glyphHeight / -10.0f;
Vector2 shadowOffset = Vector2(shadowWidthOffset, shadowHeightOffset);
AABB2 shadowBounds = AABB2(bottomLeft + shadowOffset, topRight + shadowOffset);
builder.AddTexturedAABB(shadowBounds, glyphBounds.mins, glyphBounds.maxs, RGBA::BLACK);
}
builder.AddTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, tint);
cursorPosition.x += glyph->xAdvance * scale;
previousGlyph = glyph;
}
builder.End();
Mesh* mesh = new Mesh();
builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
mesh->m_drawMode = DrawMode::TRIANGLES;
MeshRenderer* thingToRender = new MeshRenderer(mesh, font->GetMaterial());
m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
GL_CHECK_ERROR();
thingToRender->Render();
delete mesh;
delete thingToRender;
}
示例5: while
void SBrush::AddPatch(const SurfacePoint *pPoint, const Vector &vPatchCenter, float fSize, float fPressure, float fStrength, AxisAlignedBoundingBox &cDirtyWorldArea)
{
if (!pPoint || !pPoint->Mesh())
return;
if (m_aMeshChanges.find(pPoint->Mesh()) == m_aMeshChanges.end())
{
// map a mesh to a meshchange;
// this supports sculpting on multi meshes.
m_aMeshChanges[pPoint->Mesh()] = pPoint->Mesh()->StartChange();
//
unsigned int i = 0;
MeshRenderer *p;
while ( p = ((const Mesh *)pPoint->Mesh())->ChildByClass<MeshRenderer>( i++ ) )
m_aRenderers.push_back( p );
}
const unsigned int fIdx = pPoint->FaceIndex();
QVector<unsigned int> vIndices;
if (pPoint->Mesh()->Type() == Topology::typeQuadric)
{
for (unsigned int c = 0; c < 4; ++c)
{
const unsigned int vIdx = pPoint->Mesh()->QuadIndex(fIdx, c);
MeshChange::VertexChange &vc = m_aMeshChanges[pPoint->Mesh()]->Add(vIdx, fIdx);
const Vector vOldPos = vc.m_vPosition;
Vector vDelta = Vector(0, 10, 0);
pPoint->Mesh()->VertexPosition(vIdx) = vOldPos + vDelta;
vIndices.push_back(vIdx);
}
}
else
{
for (unsigned int c = 0; c < 3; ++c)
{
const unsigned int vIdx = pPoint->Mesh()->TriangleIndex(fIdx, c);
MeshChange::VertexChange &vc = m_aMeshChanges[pPoint->Mesh()]->Add(vIdx, fIdx);
const Vector vOldPos = vc.m_vPosition;
Vector vDelta = Vector(0, 10, 0);
pPoint->Mesh()->VertexPosition(vIdx) = vOldPos + vDelta;
vIndices.push_back(vIdx);
}
}
//
for ( int r = 0; r < m_aRenderers.size(); r++ )
{
MeshRenderer *pR = m_aRenderers[r];
for ( int i = 0; i < vIndices.size(); i++ )
pR->OnVertexPositionChange( vIndices[i], fIdx );
};
Kernel()->ViewPort()->Redraw();
};
示例6: Component
Exhaustion::Exhaustion(kick::GameObject *gameObject) : Component(gameObject) {
MeshRenderer* mr = gameObject->addComponent<MeshRenderer>();
Material *material = new Material();
material->setShader(Project::loadShader("poly-assets/shaders/unlit_vertex_colored.shader"));
mr->setMaterial(material);
Mesh *mesh = new Mesh();
mesh->setMeshData(loadPlyData("poly-assets/models","cloud.ply"));
mr->setMesh(mesh);
}
示例7:
MeshRenderer<Vertex>* StaticMesh::AddMesh(std::vector<Vertex>& vertices, std::vector<unsigned int>& indices)
{
MeshRenderer<novus::Vertex>* newMesh = NE_NEW MeshRenderer<novus::Vertex>();
newMesh->Init(EngineStatics::getRenderer(), vertices, indices);
mMeshes.push_back(newMesh);
return newMesh;
}
示例8: SetDefaultMeshRenderer
void SetDefaultMeshRenderer(MeshRenderer& meshRenderer){
//meshRenderer = MeshRenderer();
//meshRenderer.m_material = new Material();
meshRenderer.SetDefaultMaterial();
//meshRenderer.m_mesh = new Mesh();
meshRenderer.m_mesh->SetDrawMode(GL_QUADS);
meshRenderer.BindVertexArray();
}
示例9: Camera
HRESULT Jaraffe::CScene::Init()
{
// 1) Create MainCamera
Camera* newCamera = new Camera();
Camera::SetMainCamera(newCamera);
GameObject* m_pMainCamera = GameObject::Create();
m_pMainCamera->InsertComponent(new Transform);
m_pMainCamera->InsertComponent(newCamera);
m_pMainCamera->Init();
// 2) Create Directional Light
Jaraffe::Component::Light* pMainLight = new Jaraffe::Component::Light();
auto plight = pMainLight->SetLightType(Jaraffe::Light::LightType::Directional);
if (plight != nullptr)
{
auto cast = (Jaraffe::Light::DirectionalLight*)plight;
cast->Ambient = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
cast->Diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
cast->Specular = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
cast->Direction = XMFLOAT3(-0.707f, 0.0f, 0.707f);
}
GameObject* m_DirectionalLight = GameObject::Create();
m_DirectionalLight->InsertComponent(new Transform);
m_DirectionalLight->InsertComponent(pMainLight);
//---- T E S T ----
Jaraffe::Material* pMat = new Jaraffe::Material();
Jaraffe::Texture* pTex = new Jaraffe::Texture();
pTex->SetTexture(gTEXTUREMGR->CreateTexture(L"Resources/Textures/WoodCrate01.dds"));
pMat->m_MainTexture = pTex;
MeshRenderer* pMeshRenderer = new MeshRenderer();
pMeshRenderer->SetMaterial(pMat);
GameObject* m_pTestModel = GameObject::Create();
m_pTestModel->InsertComponent(new Transform);
m_pTestModel->InsertComponent(pMeshRenderer);
m_pTestModel->InsertComponent(new Mesh);
m_ObjectList.push_back(m_pTestModel);
//---- E N D ----
// All GameObject Init
for (size_t i = 0; i < m_ObjectList.size(); i++)
{
m_ObjectList[i]->Init();
}
return S_OK;
}
示例10: Header
void ProjectScreen::onAwake()
{
Screen::setResolution(800, 600, false);
header.reset(new Header(this));
filesPanel.reset(new FilesPanel(this));
hierarchyPanel.reset(new HierarchyPanel(this));
inspectorPanel.reset(new InspectorPanel(this));
scenePanel.reset(new ScenePanel(this));
logPanel.reset(new LogPanel(this));
dropdownLayer.reset(new DropdownLayer(this));
AuthorCamera::create();
inspectorCamera = InspectorCamera::create();
Floor::create();
GameObject* inspectorGo = new GameObject("_EDITOR_InspectorMesh");
inspectorGo->setLayer(1 << 1);
//inspectorGo->getTransform()->setPosition(Vector3(0, 0, 0));
MeshRenderer* inspectorMr = inspectorGo->addComponent<MeshRenderer>();
inspectorMf = inspectorGo->addComponent<MeshFilter>();
inspectorMf->setMesh(Resources::load<Mesh>("primitives/cube"));
inspectorMat.reset(new Material(Resources::load<Shader>(
"shaders/EditorDiffuseTexture")));
inspectorMr->setMaterial(inspectorMat.get());
sceneName = "Untitled.mutiny";
Application::setTitle("Mutiny - " + sceneName + " - " + SelectProjectScreen::selectedProject);
// Temp (So I can see something...)
GameObject* go = GameObject::createPrimitive(PrimitiveType::CUBE);
go->setName("Player");
go->getTransform()->setPosition(Vector3(0, 10, 0));
go = GameObject::createPrimitive(PrimitiveType::CUBE);
go->setName("WeaponSpawner");
go->getTransform()->setPosition(Vector3(10, 10, 0));
GameObject* go2 = GameObject::createPrimitive(PrimitiveType::CUBE);
go2->setName("Sword");
go2->getTransform()->setPosition(Vector3(0, 0, 0));
go2->getTransform()->setParent(go->getTransform());
go = GameObject::createPrimitive(PrimitiveType::CUBE);
go->setName("Terrain");
go->getTransform()->setPosition(Vector3(10, 0, 0));
go = GameObject::createPrimitive(PrimitiveType::CUBE);
go->setName("House");
go->getTransform()->setPosition(Vector3(10, 0, 10));
}
示例11: Mesh
void SkyBox::onAwake()
{
Debug::log("SkyBox awoken");
std::vector<Vector3> vertices;
vertices.push_back(Vector3(-100, -100, 50));
vertices.push_back(Vector3(-100, 100, 50));
vertices.push_back(Vector3(100, 100, 50));
vertices.push_back(Vector3(100, 100, 50));
vertices.push_back(Vector3(100, -100, 50));
vertices.push_back(Vector3(-100, -100, 50));
std::vector<Vector2> uv;
uv.push_back(Vector2(0, 1));
uv.push_back(Vector2(0, 0));
uv.push_back(Vector2(1, 0));
uv.push_back(Vector2(1, 0));
uv.push_back(Vector2(1, 1));
uv.push_back(Vector2(0, 1));
std::vector<int> triangles;
triangles.push_back(0);
triangles.push_back(1);
triangles.push_back(2);
triangles.push_back(3);
triangles.push_back(4);
triangles.push_back(5);
Mesh* mesh = new Mesh();
mesh->setVertices(vertices);
mesh->setUv(uv);
mesh->setTriangles(triangles, 0);
MeshFilter* meshFilter = getGameObject()->addComponent<MeshFilter>();
meshFilter->setMesh(mesh);
Texture2d* texture = Resources::load<Texture2d>("textures/clouds");
//Texture2d* texture = new Texture2d(1, 1);
//texture->setPixel(0, 0, Color(1, 0, 0));
//texture->apply();
Material* material = new Material(Resources::load<Material>("shaders/Internal-SkyboxTexture"));
material->setMainTexture(texture);
MeshRenderer* meshRenderer = getGameObject()->addComponent<MeshRenderer>();
meshRenderer->setMaterial(material);
//getGameObject()->getTransform()->translate(Vector3(0, 0, 10));
//getGameObject()->getTransform()->rotate(Vector3(0, 180, 0));
}
示例12: Vector2
//-----------------------------------------------------------------------------------
void Renderer::DrawText2D
( const Vector2& startBottomLeft
, const std::string& asciiText
, float cellWidth
, float cellHeight
, const RGBA& tint /*= RGBA::WHITE*/
, bool drawShadow /*= false*/
, const BitmapFont* font /*= nullptr*/)
{
const float SHADOW_WIDTH_OFFSET = cellWidth / 10.0f;
const float SHADOW_HEIGHT_OFFSET = cellHeight / -10.0f;
const Vector2 SHADOW_OFFSET = Vector2(SHADOW_WIDTH_OFFSET, SHADOW_HEIGHT_OFFSET);
if (asciiText.empty())
{
return;
}
MeshBuilder builder;
builder.Begin();
if (font == nullptr)
{
font = m_defaultFont;
}
int stringLength = asciiText.size();
Vector2 currentPosition = startBottomLeft;
for (int i = 0; i < stringLength; i++)
{
unsigned char currentCharacter = asciiText[i];
Vector2 topRight = currentPosition + Vector2(cellWidth, cellHeight);
AABB2 quadBounds = AABB2(currentPosition, topRight);
AABB2 glyphBounds = font->GetTexCoordsForGlyph(currentCharacter);
if (drawShadow)
{
AABB2 shadowBounds = AABB2(currentPosition + SHADOW_OFFSET, topRight + SHADOW_OFFSET);
builder.AddTexturedAABB(shadowBounds, glyphBounds.mins, glyphBounds.maxs, RGBA::BLACK);
}
builder.AddTexturedAABB(quadBounds, glyphBounds.mins, glyphBounds.maxs, tint);
currentPosition.x += cellWidth;
}
builder.End();
Mesh* mesh = new Mesh();
builder.CopyToMesh(mesh, &Vertex_PCUTB::Copy, sizeof(Vertex_PCUTB), &Vertex_PCUTB::BindMeshToVAO);
mesh->m_drawMode = DrawMode::TRIANGLES;
MeshRenderer* thingToRender = new MeshRenderer(mesh, font->GetMaterial());
m_defaultMaterial->SetMatrices(Matrix4x4::IDENTITY, m_viewStack.GetTop(), m_projStack.GetTop());
GL_CHECK_ERROR();
thingToRender->Render();
delete mesh;
delete thingToRender;
}
示例13: GameObject
void BloomScreen::onAwake()
{
BloomCamera::create();
playerGo = new GameObject("Player");
playerGo->getTransform()->setPosition(Vector3(-10, 0, -10));
MeshRenderer* playerMr = playerGo->addComponent<MeshRenderer>();
playerMr->setMaterial(Resources::load<Material>("shaders/Internal-MeshRendererTexture"));
playerMr->getMaterial()->setMainTexture(Resources::load<Texture2d>("models/curuthers/Whiskers_diffuse").cast<Texture>());
arc<Mesh> mesh = Resources::load<Mesh>("models/curuthers/curuthers");
MeshFilter* playerMf = playerGo->addComponent<MeshFilter>();
playerMf->setMesh(mesh);
}
示例14: addPlant
void Terrain::addPlant(Transform *parent, vec3 pos){
static int plantCounter = 0;
plantCounter++;
Mesh* plantMesh = plants[plantCounter % plants.size()];
auto gameObject = Engine::activeScene()->createGameObject("Terrain");
MeshRenderer* meshRenderer = gameObject->addComponent<MeshRenderer>();
meshRenderer->setMesh(plantMesh);
Material *material = new Material();
material->setShader(Project::loadShader("poly-assets/shaders/diffuse_vertex_colored.shader"));
meshRenderer->setMaterial(material);
vec3 finalPos = (vec3)(parent->globalMatrix()*vec4(pos,1.0f));
gameObject->transform()->setLocalPosition(finalPos);
gameObject->transform()->setLocalScale(vec3(1)*linearRand(0.5f,1.5f));
gameObject->transform()->setLocalRotationEuler(vec3(0,(float)linearRand(-M_PI,M_PI),0));
}
示例15: SetDefaultTexturedMeshRenderer
//assumes mesh renderer has already been newed off
void SetDefaultTexturedMeshRenderer(MeshRenderer& meshRenderer){
meshRenderer.m_material->InitializeMaterial("Data/Shaders/basicSampler.vert", "Data/Shaders/basicSampler.frag");
meshRenderer.m_mesh->SetDrawMode(GL_QUADS);
meshRenderer.BindVertexArray();
}