Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Add the instruction to include the irrlicht.h file below
- #include <irrlicht.h>
- #include "EventListener.h"
- //Add the instructions to use the namespaces irr, core, video and scene below
- using namespace irr;
- using namespace core;
- using namespace video;
- using namespace scene;
- using namespace gui;
- //Add the instructions to define the irrlicht.lib file for the linker
- #pragma comment(lib, "irrlicht.lib")
- //Function to duplicate and place roads on the terrain.
- void roadPlacement(ISceneManager *scnmgr, IVideoDriver *driver, ITerrainSceneNode *terrain, int j) {
- for (int i = 0; i < j; i++) {
- //Spawn the Road
- ISceneNode *road = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/roadV2.obj"));
- //Disable lighting for the road node in order to see object
- road->setMaterialFlag(EMF_LIGHTING, false);
- //Load the road texture and apply it to the road scene object
- road->setMaterialTexture(0, driver->getTexture("../media/textures/roadTexture.jpg"));
- road->getMaterial(0).getTextureMatrix(0).setTextureScale(0.011, 0.011);
- road->setPosition(vector3df(990, 800, 160 + i * 85.5));
- road->setScale(vector3df(25));
- //Sets road height to scale with terrain height
- vector3df roadPosition = road->getPosition();
- roadPosition.Y = terrain->getHeight(roadPosition.X, roadPosition.Z) + 2;
- road->setPosition(roadPosition);
- }
- }
- int main(void) {
- //Function to capture keyboard events
- EventListener listener;
- //Add the instruction to create the IrrlichtDevice and store it in a variable called device
- IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(1024, 768), 16, false, false, false, & listener);
- if (device == nullptr) {
- //Return -1 to indicate the device was not created correctly
- return -1;
- }
- ISceneManager *scnmgr = device->getSceneManager();
- IVideoDriver *driver = device->getVideoDriver();
- scnmgr->setAmbientLight(video::SColorf(0.3, 0.3, 0.3, 1));
- //Create mesh to add water effect to
- IAnimatedMesh* plane = scnmgr->addHillPlaneMesh("plane", // Name of mesh
- core::dimension2d<f32>(20, 20), // Size of a tile of the mesh. (10.0f, 10.0f) would be a good value to start, for example.
- core::dimension2d<u32>(40, 40), 0, 0, // Specifies how much tiles there will be. If you specifiy for example that a tile has the size (10.0f, 10.0f) and the tileCount is (10,10), than you get a field of 100 tiles which has the dimension 100.0fx100.0f.
- core::dimension2d<f32>(0, 0), //material
- core::dimension2d<f32>(10, 10)); //countHills
- //mesh, waveheight = 0.5f, wave speed = 350.0f, wave length = 80.0f
- ISceneNode* sea = scnmgr->addWaterSurfaceSceneNode(plane->getMesh(0), 5.0f, 300.0f, 40.0f, NULL, -1, vector3df(1150, 1000, 1650));;
- sea->setMaterialTexture(0, driver->getTexture("../media/textures/stones.jpg"));
- sea->setMaterialTexture(1, driver->getTexture("../media/textures/water.jpg"));
- sea->setMaterialFlag(EMF_LIGHTING, true);
- sea->setMaterialType(video::EMT_REFLECTION_2_LAYER);
- // SPAWN BUILDINGS //
- //Spawn the Building1
- ISceneNode *building1 = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/building1.obj"));
- //Disable lighting for the building1 node in order to see object
- building1->setMaterialFlag(EMF_LIGHTING, false);
- //Load the building1 texture and apply it to the watertower scene object
- building1->setMaterialTexture(0, driver->getTexture("../media/textures/building1.png"));
- building1->setPosition(vector3df(1150, 800, 900));
- building1->setScale(vector3df(10));
- //Spawn the Warehouse
- ISceneNode *warehouse = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/warehouse.obj"));
- //Disable lighting for the warehouse node in order to see object
- warehouse->setMaterialFlag(EMF_LIGHTING, false);
- //Load the warehouse texture and apply it to the watertower scene object
- warehouse->setMaterialTexture(0, driver->getTexture("../media/textures/warehouse.png"));
- warehouse->setPosition(vector3df(1150, 800, 600));
- warehouse->setScale(vector3df(10));
- //Spawn the Shop
- ISceneNode *shop = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/shop.obj"));
- //Disable lighting for the Shop node in order to see object
- shop->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Shop texture and apply it to the watertower scene object
- shop->setMaterialTexture(0, driver->getTexture("../media/textures/shop.png"));
- shop->setPosition(vector3df(1150, 800, 300));
- shop->setScale(vector3df(8));
- //Spawn the Apartments
- ISceneNode *apartments = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/apartments.obj"));
- //Disable lighting for the Apartments node in order to see object
- apartments->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- apartments->setMaterialTexture(0, driver->getTexture("../media/textures/apartments.png"));
- apartments->setPosition(vector3df(1200, 800, 1200));
- apartments->setScale(vector3df(8));
- //Spawn the Garage
- ISceneNode *garage = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/garage.obj"));
- //Disable lighting for the Apartments node in order to see object
- garage->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- garage->setMaterialTexture(0, driver->getTexture("../media/textures/garage.png"));
- garage->setPosition(vector3df(1150, 800, 1650));
- garage->setScale(vector3df(8));
- //Spawn the House1
- ISceneNode *house1 = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/house1.obj"));
- //Disable lighting for the Apartments node in order to see object
- house1->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- house1->setMaterialTexture(0, driver->getTexture("../media/textures/house1.png"));
- house1->setPosition(vector3df(970, 800, 1950));
- house1->setScale(vector3df(10));
- house1->setRotation(vector3df(0, 180, 0));
- //Spawn the House2
- ISceneNode *house2 = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/house2.obj"));
- //Disable lighting for the Apartments node in order to see object
- house2->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- house2->setMaterialTexture(0, driver->getTexture("../media/textures/house2.png"));
- house2->setPosition(vector3df(800, 800, 1800));
- house2->setScale(vector3df(10));
- house2->setRotation(vector3df(0, 120, 0));
- //Spawn the House3
- ISceneNode *house3 = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/house3.obj"));
- //Disable lighting for the Apartments node in order to see object
- house3->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- house3->setMaterialTexture(0, driver->getTexture("../media/textures/house3.png"));
- house3->setPosition(vector3df(800, 800, 1500));
- house3->setScale(vector3df(8));
- house3->setRotation(vector3df(0, 90, 0));
- //Spawn the Building Block
- ISceneNode *block = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/block.obj"));
- //Disable lighting for the Apartments node in order to see object
- block->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- block->setMaterialTexture(0, driver->getTexture("../media/textures/block.png"));
- block->setPosition(vector3df(970, 800, -100));
- block->setScale(vector3df(10));
- //Spawn the Shed
- ISceneNode *shed = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/shed.obj"));
- //Disable lighting for the Apartments node in order to see object
- shed->setMaterialFlag(EMF_LIGHTING, false);
- //Load the Apartments texture and apply it to the watertower scene object
- shed->setMaterialTexture(0, driver->getTexture("../media/textures/shed.png"));
- shed->setPosition(vector3df(1120, 800, 775));
- shed->setScale(vector3df(7));
- shed->setRotation(vector3df(0, -90, 0));
- // SPAWN OBJECTS //
- //Spawn the Watertower object
- ISceneNode *watertower = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/Watertower.obj"));
- //Disable lighting for the watertower node in order to see object
- watertower->setMaterialFlag(EMF_LIGHTING, false);
- //Load the watertower texture and apply it to the watertower scene object
- watertower->setMaterialTexture(0, driver->getTexture("../media/textures/watertowertexture.png"));
- watertower->setPosition(vector3df(800, 800, 1000));
- watertower->setScale(vector3df(25));
- //Spawn a tree object
- ISceneNode *tree = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/tree.obj"));
- //Disable lighting for the tree node in order to see object
- tree->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- tree->setMaterialTexture(0, driver->getTexture("../media/textures/tree.png"));
- tree->setPosition(vector3df(700, 800, 1650));
- tree->setScale(vector3df(8));
- //Spawn car object
- ISceneNode *car = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/car.obj"));
- //Disable lighting for the tree node in order to see object
- car->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- car->setMaterialTexture(0, driver->getTexture("../media/textures/car.png"));
- car->setPosition(vector3df(1015, 800, 1700));
- car->setScale(vector3df(6));
- car->setRotation(vector3df(90.0f));
- //Spawn dumpster object
- ISceneNode *bin = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/dumpster.obj"));
- //Disable lighting for the dumpster node in order to see object
- bin->setMaterialFlag(EMF_LIGHTING, false);
- //Load the dumpster texture and apply it to the watertower scene object
- bin->setMaterialTexture(0, driver->getTexture("../media/textures/dumpster.png"));
- bin->setPosition(vector3df(1100, 800, 1485));
- bin->setScale(vector3df(5));
- bin->setRotation(vector3df(0, 180, 0));
- //Spawn a treehouse object
- ISceneNode *treehouse = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/treehouse.obj"));
- //Disable lighting for the tree node in order to see object
- treehouse->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- treehouse->setMaterialTexture(0, driver->getTexture("../media/textures/treehouse.png"));
- treehouse->setPosition(vector3df(700, 800, 800));
- treehouse->setScale(vector3df(8));
- treehouse->setRotation(vector3df(0, -90, 0));
- //Spawn a busstop object
- ISceneNode *busstop = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/BusStop.obj"));
- //Disable lighting for the tree node in order to see object
- busstop->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- busstop->setMaterialTexture(0, driver->getTexture("../media/textures/BusStop.png"));
- busstop->setPosition(vector3df(900, 800, 1100));
- busstop->setScale(vector3df(3));
- busstop->setRotation(vector3df(0, 180, 0));
- //Spawn a Swing object
- ISceneNode *swing = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/Swing.obj"));
- //Disable lighting for the tree node in order to see object
- swing->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- swing->setMaterialTexture(0, driver->getTexture("../media/textures/Swing.png"));
- swing->setPosition(vector3df(500, 800, 1200));
- swing->setScale(vector3df(5));
- swing->setRotation(vector3df(0, 180, 0));
- //Spawn a Merrygoround object
- ISceneNode *merry = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/Merrygoround.obj"));
- //Disable lighting for the tree node in order to see object
- merry->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- merry->setMaterialTexture(0, driver->getTexture("../media/textures/Merrygoround.png"));
- merry->setPosition(vector3df(600, 800, 1300));
- merry->setScale(vector3df(5));
- merry->setRotation(vector3df(0, 180, 0));
- //Spawn a Slide object
- ISceneNode *slide = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/Slide.obj"));
- //Disable lighting for the tree node in order to see object
- slide->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- slide->setMaterialTexture(0, driver->getTexture("../media/textures/Slide.png"));
- slide->setPosition(vector3df(550, 800, 1400));
- slide->setScale(vector3df(5));
- slide->setRotation(vector3df(0, 90, 0));
- //Spawn a Park Bench object
- ISceneNode *parkbench = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/ParkBench.obj"));
- //Disable lighting for the tree node in order to see object
- parkbench->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- parkbench->setMaterialTexture(0, driver->getTexture("../media/textures/ParkBench.png"));
- parkbench->setPosition(vector3df(650, 800, 1450));
- parkbench->setScale(vector3df(4));
- parkbench->setRotation(vector3df(0, -60, 0));
- //Spawn a Park Table object
- ISceneNode *parktable = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/ParkTable.obj"));
- //Disable lighting for the tree node in order to see object
- parktable->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- parktable->setMaterialTexture(0, driver->getTexture("../media/textures/ParkTable.png"));
- parktable->setPosition(vector3df(650, 800, 1100));
- parktable->setScale(vector3df(3));
- parktable->setRotation(vector3df(0, -130, 0));
- //Spawn a Rubbish Bin object
- ISceneNode *rubbishbin = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/RubbishBin.obj"));
- //Disable lighting for the tree node in order to see object
- rubbishbin->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- rubbishbin->setMaterialTexture(0, driver->getTexture("../media/textures/RubbishBin.png"));
- rubbishbin->setPosition(vector3df(700, 800, 1150));
- rubbishbin->setScale(vector3df(2.5));
- // CHARACTER //
- ISceneNode *character = scnmgr->addMeshSceneNode(scnmgr->getMesh("../media/character.obj"));
- //Disable lighting for the tree node in order to see object
- character->setMaterialFlag(EMF_LIGHTING, false);
- //Load the tree texture and apply it to the watertower scene object
- character->setMaterialTexture(0, driver->getTexture("../media/textures/character.png"));
- character->setPosition(vector3df(850, 800, 1200));
- character->setScale(vector3df(1));
- // BILLBOARDS //
- //Lamp Billboard
- ISceneNode *lamp = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(15, 75), vector3df(900, 800, 1485));
- lamp->setMaterialFlag(EMF_LIGHTING, false);
- lamp->setMaterialTexture(0, driver->getTexture("../media/textures/lamp.png"));
- lamp->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Bench Billboard
- ISceneNode *bench = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(60, 30), vector3df(900, 800, 950));
- bench->setMaterialFlag(EMF_LIGHTING, false);
- bench->setMaterialTexture(0, driver->getTexture("../media/textures/bench.png"));
- bench->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //ATM Billboard
- ISceneNode *atm = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(95, 50), vector3df(1040, 800, 1550));
- atm->setMaterialFlag(EMF_LIGHTING, false);
- atm->setMaterialTexture(0, driver->getTexture("../media/textures/atm.png"));
- atm->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Bush Billboard
- ISceneNode *bush = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(40, 40), vector3df(850, 800, 1400));
- bush->setMaterialFlag(EMF_LIGHTING, false);
- bush->setMaterialTexture(0, driver->getTexture("../media/textures/bush.png"));
- bush->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Trash Bin Billboard
- ISceneNode *trashbin = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(23, 30), vector3df(900, 800, 900));
- trashbin->setMaterialFlag(EMF_LIGHTING, false);
- trashbin->setMaterialTexture(0, driver->getTexture("../media/textures/trashbin.png"));
- trashbin->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Tree2 Billboard
- ISceneNode *tree2 = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(150, 150), vector3df(400, 800, 800));
- tree2->setMaterialFlag(EMF_LIGHTING, false);
- tree2->setMaterialTexture(0, driver->getTexture("../media/textures/tree2.png"));
- tree2->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Tree3 Billboard
- ISceneNode *tree3 = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(120, 180), vector3df(300, 800, 1000));
- tree3->setMaterialFlag(EMF_LIGHTING, false);
- tree3->setMaterialTexture(0, driver->getTexture("../media/textures/tree3.png"));
- tree3->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Fence Billboard
- ISceneNode *fence = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(140, 80), vector3df(450, 800, 1300));
- fence->setMaterialFlag(EMF_LIGHTING, false);
- fence->setMaterialTexture(0, driver->getTexture("../media/textures/fence.png"));
- fence->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Playground Billboard
- ISceneNode *playground = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(100, 100), vector3df(480, 800, 1300));
- playground->setMaterialFlag(EMF_LIGHTING, false);
- playground->setMaterialTexture(0, driver->getTexture("../media/textures/playground.png"));
- playground->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- //Tree3 Billboard
- ISceneNode *tree4 = scnmgr->addBillboardSceneNode(NULL, dimension2d<f32>(150, 150), vector3df(400, 800, 1600));
- tree4->setMaterialFlag(EMF_LIGHTING, false);
- tree4->setMaterialTexture(0, driver->getTexture("../media/textures/tree4.png"));
- tree4->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
- // SKYBOX //
- //Textures for each side of Skybox
- ITexture *top = driver->getTexture("../media/textures/skyboxTOP.png");
- ITexture *bottom = driver->getTexture("../media/textures/skyboxBOTTOM.png");
- ITexture *left = driver->getTexture("../media/textures/skyboxLEFT.png");
- ITexture *right = driver->getTexture("../media/textures/skyboxRIGHT.png");
- ITexture *front = driver->getTexture("../media/textures/skyboxFRONT.png");
- ITexture *veryright = driver->getTexture("../media/textures/skyboxBACK.png");
- //Skybox node
- ISceneNode *skybox = scnmgr->addSkyBoxSceneNode(top, bottom, left, right, front, veryright);
- // TERRAIN //
- //Terrain spawn
- irr::io::path path = "../media/newterrainMap.bmp";
- ITerrainSceneNode *terrain = scnmgr->addTerrainSceneNode(path, 0, 0, vector3df(-1000, 0, -800), vector3df(0, 0, 0), vector3df(40, 1, 40), SColor(255, 255, 255, 255), 5, ETPS_17, 4);
- //Terrain texture
- terrain->setMaterialFlag(EMF_LIGHTING, false);
- terrain->setMaterialTexture(0, driver->getTexture("../media/textures/terraintexture.jpg"));
- // TERRAIN HEIGHT //
- // BUILDINGS //
- //Set building1 height to scale with terrain height
- vector3df building1Position = building1->getPosition();
- building1Position.Y = terrain->getHeight(building1Position.X, building1Position.Z);
- building1->setPosition(building1Position);
- //Set warehouse height to scale with terrain height
- vector3df warehousePosition = warehouse->getPosition();
- warehousePosition.Y = terrain->getHeight(warehousePosition.X, warehousePosition.Z);
- warehouse->setPosition(warehousePosition);
- //Set Shop height to scale with terrain height
- vector3df shopPosition = shop->getPosition();
- shopPosition.Y = terrain->getHeight(shopPosition.X, shopPosition.Z);
- shop->setPosition(shopPosition);
- //Set Apartments height to scale with terrain height
- vector3df apartmentsPosition = apartments->getPosition();
- apartmentsPosition.Y = terrain->getHeight(apartmentsPosition.X, apartmentsPosition.Z);
- apartments->setPosition(apartmentsPosition);
- //Set Garage height to scale with terrain height
- vector3df garagePosition = garage->getPosition();
- garagePosition.Y = terrain->getHeight(garagePosition.X, garagePosition.Z);
- garage->setPosition(garagePosition);
- //Set House1 height to scale with terrain height
- vector3df house1Position = house1->getPosition();
- house1Position.Y = terrain->getHeight(house1Position.X, house1Position.Z);
- house1->setPosition(house1Position);
- //Set House2 height to scale with terrain height
- vector3df house2Position = house2->getPosition();
- house2Position.Y = terrain->getHeight(house2Position.X, house2Position.Z);
- house2->setPosition(house2Position);
- //Set House3 height to scale with terrain height
- vector3df house3Position = house3->getPosition();
- house3Position.Y = terrain->getHeight(house3Position.X, house3Position.Z);
- house3->setPosition(house3Position);
- //Set Apartment Block height to scale with terrain height
- vector3df blockPosition = block->getPosition();
- blockPosition.Y = terrain->getHeight(blockPosition.X, blockPosition.Z);
- block->setPosition(blockPosition);
- //Set Shed height to scale with terrain height
- vector3df shedPosition = shed->getPosition();
- shedPosition.Y = terrain->getHeight(shedPosition.X, shedPosition.Z);
- shed->setPosition(shedPosition);
- // OBJECTS //
- //Set Watertower height to scale with terrain height
- vector3df watertowerPosition = watertower->getPosition();
- watertowerPosition.Y = terrain->getHeight(watertowerPosition.X, watertowerPosition.Z);
- watertower->setPosition(watertowerPosition);
- //Set tree height to scale with terrain height
- vector3df treePosition = tree->getPosition();
- treePosition.Y = terrain->getHeight(treePosition.X, treePosition.Z);
- tree->setPosition(treePosition);
- //Set car height to scale with terrain height
- vector3df carPosition = car->getPosition();
- carPosition.Y = terrain->getHeight(carPosition.X, carPosition.Z);
- car->setPosition(carPosition);
- //Set bin height to scale with terrain height
- vector3df binPosition = bin->getPosition();
- binPosition.Y = terrain->getHeight(binPosition.X, binPosition.Z);
- bin->setPosition(binPosition);
- //Treehouse object height to scale with terrain height
- vector3df treehousePosition = treehouse->getPosition();
- treehousePosition.Y = terrain->getHeight(treehousePosition.X, treehousePosition.Z);
- treehouse->setPosition(treehousePosition);
- //Bus Stop object height to scale with terrain height
- vector3df busstopPosition = busstop->getPosition();
- busstopPosition.Y = terrain->getHeight(busstopPosition.X, busstopPosition.Z);
- busstop->setPosition(busstopPosition);
- //Swing object height to scale with terrain height
- vector3df swingPosition = swing->getPosition();
- swingPosition.Y = terrain->getHeight(swingPosition.X, swingPosition.Z);
- swing->setPosition(swingPosition);
- //Merrygoround object height to scale with terrain height
- vector3df merryPosition = merry->getPosition();
- merryPosition.Y = terrain->getHeight(merryPosition.X, merryPosition.Z) - 6;
- merry->setPosition(merryPosition);
- //Slide object height to scale with terrain height
- vector3df slidePosition = slide->getPosition();
- slidePosition.Y = terrain->getHeight(slidePosition.X, slidePosition.Z);
- slide->setPosition(slidePosition);
- //Park Bench object height to scale with terrain height
- vector3df parkbenchPosition = parkbench->getPosition();
- parkbenchPosition.Y = terrain->getHeight(parkbenchPosition.X, parkbenchPosition.Z);
- parkbench->setPosition(parkbenchPosition);
- //Park Table object height to scale with terrain height
- vector3df parktablePosition = parktable->getPosition();
- parktablePosition.Y = terrain->getHeight(parktablePosition.X, parktablePosition.Z);
- parktable->setPosition(parktablePosition);
- //Park Rubbish Bin object height to scale with terrain height
- vector3df rubbishbinPosition = rubbishbin->getPosition();
- rubbishbinPosition.Y = terrain->getHeight(rubbishbinPosition.X, rubbishbinPosition.Z);
- rubbishbin->setPosition(rubbishbinPosition);
- // BILLBOARDS //
- //Lamp Billboard height to scale with terrain height
- vector3df lampPosition = lamp->getPosition();
- lampPosition.Y = terrain->getHeight(lampPosition.X, lampPosition.Z) + 30;
- lamp->setPosition(lampPosition);
- //Bench Billboard height to scale with terrain height
- vector3df benchPosition = bench->getPosition();
- benchPosition.Y = terrain->getHeight(benchPosition.X, benchPosition.Z) + 9;
- bench->setPosition(benchPosition);
- //ATM Billboard height to scale with terrain height
- vector3df atmPosition = atm->getPosition();
- atmPosition.Y = terrain->getHeight(atmPosition.X, atmPosition.Z) + 19;
- atm->setPosition(atmPosition);
- //Bush Billboard height to scale with terrain height
- vector3df bushPosition = bush->getPosition();
- bushPosition.Y = terrain->getHeight(bushPosition.X, bushPosition.Z) + 11;
- bush->setPosition(bushPosition);
- //Trash Bin Billboard height to scale with terrain height
- vector3df trashbinPosition = trashbin->getPosition();
- trashbinPosition.Y = terrain->getHeight(trashbinPosition.X, trashbinPosition.Z) + 10;
- trashbin->setPosition(trashbinPosition);
- //Tree2 Billboard height to scale with terrain height
- vector3df tree2Position = tree2->getPosition();
- tree2Position.Y = terrain->getHeight(tree2Position.X, tree2Position.Z) + 60;
- tree2->setPosition(tree2Position);
- //Tree3 Billboard height to scale with terrain height
- vector3df tree3Position = tree3->getPosition();
- tree3Position.Y = terrain->getHeight(tree3Position.X, tree3Position.Z) + 60;
- tree3->setPosition(tree3Position);
- //Fence Billboard height to scale with terrain height
- vector3df fencePosition = fence->getPosition();
- fencePosition.Y = terrain->getHeight(fencePosition.X, fencePosition.Z);
- fence->setPosition(fencePosition);
- //Playground Billboard height to scale with terrain height
- vector3df playgroundPosition = playground->getPosition();
- playgroundPosition.Y = terrain->getHeight(playgroundPosition.X, playgroundPosition.Z) + 35;
- playground->setPosition(playgroundPosition);
- //Tree4 Billboard height to scale with terrain height
- vector3df tree4Position = tree4->getPosition();
- tree4Position.Y = terrain->getHeight(tree4Position.X, tree4Position.Z) + 60;
- tree4->setPosition(tree4Position);
- // ROADS //
- //Road duplication
- roadPlacement(scnmgr, driver, terrain, 21);
- // CAMERAS //
- //Sets the FPS camera position
- ICameraSceneNode *camera = scnmgr->addCameraSceneNodeFPS(NULL, 100.0f, 0.0f);
- camera->setPosition(character->getPosition());
- //Sets thirdperson camera position
- ICameraSceneNode *thirdpcamera = scnmgr->addCameraSceneNode(character, vector3df(0, 30, -30), vector3df(0, 5, 0));
- //Set initial active camera to the FPS camera
- scnmgr->setActiveCamera(camera);
- //Store the initial FPS
- s32 fps_then = driver->getFPS();
- //Calculate Delta Time
- u32 then = device->getTimer()->getTime();
- bool fps = true;
- IGUIFont *font = device->getGUIEnvironment()->getFont("../media/textures/bigfont.png");
- ITextSceneNode *text = scnmgr->addTextSceneNode(font, L"Normal Text", SColor(100, 255, 255, 255), NULL, vector3df(20.0f, 0.0f, 10.0f));
- IBillboardTextSceneNode *billboard_text = scnmgr->addBillboardTextSceneNode(font, L"Billboard Text", NULL, dimension2d<f32>(20.0f, 10.0f), vector3df(-20.0f, 0.0f, 10.0f));
- IGUIStaticText *guiText = device->getGUIEnvironment()->addStaticText(L"GUI text", rect<s32>(10, 10, 100, 30), true);
- //Main loop
- while (device->run()) {
- //Clear the backbuffer
- driver->beginScene(true, true, SColor(255, 100, 101, 140));
- //Render scene objects to backbuffer
- scnmgr->drawAll();
- //Show backbuffer and final rendered frame
- driver->endScene();
- //Get the current frame rate
- s32 fps_now = driver->getFPS();
- //Calculate the frameDeltaTime
- const u32 now = device->getTimer()->getTime();
- const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
- then = now;
- vector3df nodePosition = character->getPosition();
- //Forward & Backwards Movements
- if (listener.IsKeyDown(irr::KEY_KEY_W))
- nodePosition.Z += 80 * frameDeltaTime;
- else if (listener.IsKeyDown(irr::KEY_KEY_S))
- nodePosition.Z -= 80 *frameDeltaTime;
- //Left & Right Movements
- if (listener.IsKeyDown(irr::KEY_KEY_A))
- nodePosition.X -= 80 * frameDeltaTime;
- else if (listener.IsKeyDown(irr::KEY_KEY_D))
- nodePosition.X += 80 * frameDeltaTime;
- //Update position of character & cameras
- character->setPosition(nodePosition);
- nodePosition.Y += 15;
- nodePosition.Z += 6;
- camera->setPosition(nodePosition);
- thirdpcamera->setTarget(character->getPosition());
- //Change active camera key
- if (listener.IsKeyDown(irr::KEY_KEY_E))
- {
- //Delay the change time
- listener.ChangeKeyDown(irr::KEY_KEY_E, false);
- //Change active camera
- fps = !fps;
- }
- if (fps) {
- scnmgr->setActiveCamera(camera);
- //Hide character model in FPS camera mode
- character->setVisible(false);
- }
- else {
- //Show character model in 3rd Person Camera mode
- scnmgr->setActiveCamera(thirdpcamera);
- character->setVisible(true);
- }
- //Update character position and height to scale with terrain.
- vector3df characterPosition = character->getPosition();
- characterPosition.Y = terrain->getHeight(characterPosition.X, characterPosition.Z) + 5;
- character->setPosition(characterPosition);
- //If there has been a change in frame rate
- if (fps_now != fps_then) {
- //then update window caption bar
- stringw msg = "FPS = ";
- msg += fps_now;
- text->setText(msg.c_str());
- billboard_text->setText(msg.c_str());
- guiText->setText(msg.c_str());
- device->getGUIEnvironment()->drawAll();
- msg += camera->getPosition().Z;
- device->setWindowCaption(msg.c_str());
- //Update frame rate
- fps_then = fps_now;
- }
- }
- //At this point the loop has ended so shutdown Irrlicht object
- device->drop();
- //End of program. Return 0 to indicate successful execution
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement