forked from bridgecommand/bc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLandObject.cpp
More file actions
92 lines (73 loc) · 3.44 KB
/
LandObject.cpp
File metadata and controls
92 lines (73 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Bridge Command 5.0 Ship Simulator
Copyright (C) 2014 James Packer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE. See the
GNU General Public License For more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "LandObject.hpp"
#include "IniFile.hpp"
#include <iostream>
using namespace irr;
LandObject::LandObject(const std::string& name, const irr::core::vector3df& location, irr::f32 rotation, irr::scene::ISceneManager* smgr)
{
//Load from individual object.ini file if it exists
std::string objectIniFilename = "Models/LandObject/";
objectIniFilename.append(name);
objectIniFilename.append("/object.ini");
//get filename from ini file (or empty string if file doesn't exist)
std::string objectFileName = IniFile::iniFileToString(objectIniFilename,"FileName");
if (objectFileName=="") {
objectFileName = "object.x"; //Default if not set
}
//get scale factor from ini file (or zero if not set - assume 1)
f32 objectScale = IniFile::iniFileTof32(objectIniFilename,"Scalefactor");
if (objectScale==0.0) {
objectScale = 1.0; //Default if not set
}
std::string objectFullPath = "Models/LandObject/";
objectFullPath.append(name);
objectFullPath.append("/");
objectFullPath.append(objectFileName);
//Load the mesh
scene::IMesh* objectMesh = smgr->getMesh(objectFullPath.c_str());
//add to scene node
if (objectMesh==0) {
//Failed to load mesh - load with dummy and continue
std::cout << "Failed to load land object model " << objectFullPath << std::endl;
landObject = smgr->addCubeSceneNode(0.1);
} else {
landObject = smgr->addMeshSceneNode( objectMesh, 0, -1, location );
}
//Set lighting to use diffuse and ambient, so lighting of untextured models works
if(landObject->getMaterialCount()>0) {
for(u32 mat=0;mat<landObject->getMaterialCount();mat++) {
landObject->getMaterial(mat).ColorMaterial = video::ECM_DIFFUSE_AND_AMBIENT;
}
}
landObject->setScale(core::vector3df(objectScale,objectScale,objectScale));
landObject->setRotation(irr::core::vector3df(0,rotation,0));
landObject->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true); //Normalise normals on scaled meshes, for correct lighting
}
LandObject::~LandObject()
{
//dtor
}
irr::core::vector3df LandObject::getPosition() const
{
landObject->updateAbsolutePosition();//ToDo: This may be needed, but seems odd that it's required
return landObject->getAbsolutePosition();
}
void LandObject::moveNode(irr::f32 deltaX, irr::f32 deltaY, irr::f32 deltaZ)
{
core::vector3df currentPos = landObject->getPosition();
irr::f32 newPosX = currentPos.X + deltaX;
irr::f32 newPosY = currentPos.Y + deltaY;
irr::f32 newPosZ = currentPos.Z + deltaZ;
landObject->setPosition(core::vector3df(newPosX,newPosY,newPosZ));
}