I've a plane, with one texture and 3 cube boxes on it, but the third box (cube3) isn't drawn.
Here's my code. Any advice?
Code: Select all
#include "Application.h"
Application::Application(void) {
_zoomFactor = 400;
}
Application::~Application(void) {
}
void Application::initGfx() {
_device = createDevice(video::EDT_OPENGL, dimension2d<u32>(1024, 768), 16, false, false, false, this);
_device->setWindowCaption(L"Isometric Projection");
_driver = _device->getVideoDriver();
_smgr = _device->getSceneManager();
}
void Application::Run() {
this->initGfx();
this->getTestTerrainMesh();
//_camera = _smgr->addCameraSceneNodeFPS();
_camera = _smgr->addCameraSceneNode();
_testTexture = _driver->getTexture("cube.jpg");
IMeshSceneNode *cube1 = _smgr->addCubeSceneNode(10, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1,1,1));
cube1->setMaterialTexture(0, _testTexture);
cube1->setMaterialFlag(video::EMF_LIGHTING, false);
IMeshSceneNode *cube2 = _smgr->addCubeSceneNode(10, 0, -1, vector3df(5, 5, 0), vector3df(0, 0, 0), vector3df(1,1,1));
cube2->setMaterialTexture(0, _testTexture);
cube2->setMaterialFlag(video::EMF_LIGHTING, false);
IMeshSceneNode *cube3 = _smgr->addCubeSceneNode(10, 0, -1, vector3df(10, 10, 0), vector3df(0, 0, 0), vector3df(1,1,1));
cube3->setMaterialTexture(0, _testTexture);
cube3->setMaterialFlag(video::EMF_LIGHTING, false);
while(_device->run()) {
this->Render();
}
_device->drop();
}
bool Application::OnEvent(const irr::SEvent &event) {
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
if (event.MouseInput.Event == irr::EMOUSE_INPUT_EVENT::EMIE_MOUSE_WHEEL) {
return this->OnMouseWheelEvent(event);
}
}
return false;
}
bool Application::OnMouseWheelEvent(const irr::SEvent &event) {
if (event.MouseInput.Wheel > 0) {
_zoomFactor -= event.MouseInput.Wheel * 10;
} else {
_zoomFactor += (event.MouseInput.Wheel * -1) * 10;
}
return true;
}
void Application::Render() {
_driver->beginScene(true, true, SColor(255, 0, 0, 255));
_smgr->drawAll();
matrix4 projMatrix;
projMatrix.makeIdentity();
projMatrix[0] = 1.0f;
projMatrix[8] = -1.0f;
projMatrix[1] = 0.5f;
projMatrix[5] = 1.0f;
projMatrix[9] = 0.5f;
projMatrix[10] = 0.0;
f32 scale = _zoomFactor;
matrix4 orthoMatrix;
orthoMatrix.buildProjectionMatrixOrthoLH(2 * scale, 2 * scale ,-1 * scale, 1 * scale);
orthoMatrix = orthoMatrix * projMatrix;
_camera->setProjectionMatrix(orthoMatrix, true);
_driver->endScene();
}
IAnimatedMeshSceneNode* Application::getTestTerrainMesh() {
IAnimatedMesh* terrain = _smgr->addHillPlaneMesh("ground_plane",
dimension2d<f32>( 100.0f, 100.0f ), // tile size
dimension2d<u32>( 128, 128 ), // tile count
0,
0.0f,
dimension2d<f32>( 0.0f, 0.0f ),
dimension2d<f32>( 64.0f, 64.0f ) // texture repeats
);
ITexture* texture1 = _driver->getTexture("terrain_grass.jpg");
IAnimatedMeshSceneNode* terrain_node = _smgr->addAnimatedMeshSceneNode(terrain);
terrain_node->setPosition( vector3df( 0.0f, 0.0f, 0.0f ) );
terrain_node->setMaterialTexture( 0, texture1 );
terrain_node->setMaterialFlag( video::EMF_LIGHTING, false );
terrain_node->setMaterialFlag( video::EMF_ANISOTROPIC_FILTER, true );
return terrain_node;
}