1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "CSphereSceneNode.h"
6
#include "IVideoDriver.h"
7
#include "ISceneManager.h"
17
CSphereSceneNode::CSphereSceneNode(f32 radius, u32 polyCountX, u32 polyCountY, ISceneNode* parent, ISceneManager* mgr, s32 id,
18
const core::vector3df& position, const core::vector3df& rotation, const core::vector3df& scale)
19
: IMeshSceneNode(parent, mgr, id, position, rotation, scale), Mesh(0),
20
Radius(radius), PolyCountX(polyCountX), PolyCountY(polyCountY)
23
setDebugName("CSphereSceneNode");
26
Mesh = SceneManager->getGeometryCreator()->createSphereMesh(radius, polyCountX, polyCountY);
32
CSphereSceneNode::~CSphereSceneNode()
40
void CSphereSceneNode::render()
42
video::IVideoDriver* driver = SceneManager->getVideoDriver();
46
driver->setMaterial(Mesh->getMeshBuffer(0)->getMaterial());
47
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
48
driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
49
if ( DebugDataVisible & scene::EDS_BBOX )
53
driver->setMaterial(m);
54
driver->draw3DBox(Mesh->getMeshBuffer(0)->getBoundingBox(), video::SColor(255,255,255,255));
61
//! returns the axis aligned bounding box of this node
62
const core::aabbox3d<f32>& CSphereSceneNode::getBoundingBox() const
64
return Mesh ? Mesh->getBoundingBox() : Box;
68
void CSphereSceneNode::OnRegisterSceneNode()
71
SceneManager->registerNodeForRendering(this);
73
ISceneNode::OnRegisterSceneNode();
77
//! returns the material based on the zero based index i. To get the amount
78
//! of materials used by this scene node, use getMaterialCount().
79
//! This function is needed for inserting the node into the scene hirachy on a
80
//! optimal position for minimizing renderstate changes, but can also be used
81
//! to directly modify the material of a scene node.
82
video::SMaterial& CSphereSceneNode::getMaterial(u32 i)
85
return ISceneNode::getMaterial(i);
87
return Mesh->getMeshBuffer(i)->getMaterial();
91
//! returns amount of materials used by this scene node.
92
u32 CSphereSceneNode::getMaterialCount() const
98
//! Writes attributes of the scene node.
99
void CSphereSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
101
ISceneNode::serializeAttributes(out, options);
103
out->addFloat("Radius", Radius);
104
out->addInt("PolyCountX", PolyCountX);
105
out->addInt("PolyCountY", PolyCountY);
109
//! Reads attributes of the scene node.
110
void CSphereSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
112
f32 oldRadius = Radius;
113
u32 oldPolyCountX = PolyCountX;
114
u32 oldPolyCountY = PolyCountY;
116
Radius = in->getAttributeAsFloat("Radius");
117
PolyCountX = in->getAttributeAsInt("PolyCountX");
118
PolyCountY = in->getAttributeAsInt("PolyCountY");
119
// legacy values read for compatibility with older versions
120
u32 polyCount = in->getAttributeAsInt("PolyCount");
121
if (PolyCountX ==0 && PolyCountY == 0)
122
PolyCountX = PolyCountY = polyCount;
124
Radius = core::max_(Radius, 0.0001f);
126
if ( !core::equals(Radius, oldRadius) || PolyCountX != oldPolyCountX || PolyCountY != oldPolyCountY)
130
Mesh = SceneManager->getGeometryCreator()->createSphereMesh(Radius, PolyCountX, PolyCountY);
133
ISceneNode::deserializeAttributes(in, options);
136
//! Creates a clone of this scene node and its children.
137
ISceneNode* CSphereSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
142
newManager = SceneManager;
144
CSphereSceneNode* nb = new CSphereSceneNode(Radius, PolyCountX, PolyCountY, newParent,
145
newManager, ID, RelativeTranslation);
147
nb->cloneMembers(this, newManager);
148
nb->getMaterial(0) = Mesh->getMeshBuffer(0)->getMaterial();
155
} // end namespace scene
156
} // end namespace irr