implemented application and scenegraph
This commit is contained in:
parent
77504c68f3
commit
2373b382f1
220
engine/Application.cpp
Normal file
220
engine/Application.cpp
Normal file
@ -0,0 +1,220 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include "Utilities/CfgParser.h"
|
||||
#include "Utilities/Log.h"
|
||||
|
||||
#include "ScriptSystem_Application.h"
|
||||
#include "ScriptSystem_Camera.h"
|
||||
#include "ScriptSystem_Font.h"
|
||||
#include "ScriptSystem_Image.h"
|
||||
#include "ScriptSystem_Math.h"
|
||||
#include "ScriptSystem_RigidBody.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
void Application::KeySlot(int key, int action)
|
||||
{
|
||||
if (key == GLFW_KEY_ESC && action == GLFW_RELEASE)
|
||||
quit();
|
||||
}
|
||||
|
||||
void Application::MouseMoveSlot(int x, int y)
|
||||
{
|
||||
_CameraPhi += (x - _LastMouseX) / 200.0;
|
||||
_LastMouseX = x;
|
||||
|
||||
_CameraTheta += (y - _LastMouseY) / 200.0;
|
||||
_LastMouseY = y;
|
||||
}
|
||||
|
||||
void Application::MouseWheelSlot(int z)
|
||||
{
|
||||
if ((z - _LastWheel) < 0)
|
||||
_CameraRadius *= 2.0;
|
||||
else
|
||||
_CameraRadius *= 0.5;
|
||||
|
||||
if (_CameraRadius < 1.0)
|
||||
_CameraRadius = 1.0;
|
||||
|
||||
_LastWheel = z;
|
||||
}
|
||||
|
||||
bool Application::initialize()
|
||||
{
|
||||
CfgParser cfg;
|
||||
cfg.parseFile("options.cfg");
|
||||
|
||||
int width = cfg.get("width", 640);
|
||||
int height = cfg.get("height", 480);
|
||||
bool fullscreen = cfg.get("fullscreen", false);
|
||||
|
||||
_Window = new RenderWindow();
|
||||
if (_Window->create(width, height, 0, 0, 0, fullscreen) == false)
|
||||
return false;
|
||||
|
||||
_Device = new RenderDevice(_Window);
|
||||
_FontManager = new FontManager(_Device);
|
||||
_MeshManager = new MeshManager(_Device);
|
||||
_TextureManager = new TextureManager();
|
||||
_ScriptSystem = new ScriptSystem();
|
||||
_ShaderManager = new ShaderManager(_Window);
|
||||
_Simulation = new RigidBodySimulation(_ScriptSystem);
|
||||
_ModelManager = new ModelManager (_TextureManager, _ShaderManager, _MeshManager);
|
||||
_RenderQueue = new RenderQueue();
|
||||
|
||||
setupScriptSystem_Application(_ScriptSystem, this);
|
||||
setupScriptSystem_Camera(_ScriptSystem);
|
||||
setupScriptSystem_Font(_ScriptSystem, _FontManager);
|
||||
setupScriptSystem_Image(_ScriptSystem, _TextureManager, _Device);
|
||||
setupScriptSystem_Math(_ScriptSystem);
|
||||
setupScriptSystem_RigidBody(_ScriptSystem, _Simulation);
|
||||
|
||||
if (_ScriptSystem->loadScript("main") == false)
|
||||
return false;
|
||||
|
||||
_ScriptSystem->callFunction("Initialize");
|
||||
|
||||
_Window->KeySignal.connect(this, &Application::KeySlot);
|
||||
_Window->MouseMoveSignal.connect(this, &Application::MouseMoveSlot);
|
||||
_Window->MouseWheelSignal.connect(this, &Application::MouseWheelSlot);
|
||||
|
||||
_Running = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::shutdown()
|
||||
{
|
||||
_ScriptSystem->callFunction("Shutdown");
|
||||
}
|
||||
|
||||
void Application::quit()
|
||||
{
|
||||
_Running = false;
|
||||
}
|
||||
|
||||
void Application::run()
|
||||
{
|
||||
clog << "--- starting main loop..."<< endlog;
|
||||
|
||||
_SimulationTime = 0.0;
|
||||
_StartTime = glfwGetTime();
|
||||
_LastTime = _StartTime;
|
||||
|
||||
double delta = 0.0;
|
||||
|
||||
_Paused = false;
|
||||
_Running = true;
|
||||
|
||||
while (_Window->isOpen() && _Running)
|
||||
{
|
||||
double now = glfwGetTime();
|
||||
delta = now - _LastTime;
|
||||
_LastTime = now;
|
||||
|
||||
_ScriptSystem->callFunction("OnFrame", delta, now - _StartTime);
|
||||
|
||||
_Device->clear();
|
||||
|
||||
//Quaternion q(-_CameraPhi, 0.0, -_CameraTheta);
|
||||
//camera->setPosition(q.apply(Vector3(0.0, 0.0, _CameraRadius)));
|
||||
//camera->setRotation(q);
|
||||
//pos += 5 * _DeltaTime;
|
||||
if (_SceneGraph.valid())
|
||||
{
|
||||
_SceneGraph->queue(_RenderQueue);
|
||||
_RenderQueue->render(_Device);
|
||||
}
|
||||
/*
|
||||
{
|
||||
_Device->begin3D(_Camera);
|
||||
_Device->setAmbientLight(1.0, 1.0, 1.0);
|
||||
_RenderQueue->clear();
|
||||
_RenderQueue->addOpaqueItem(model, Vector3(0.0, 0.0, 0.0),
|
||||
Quaternion());
|
||||
_RenderQueue->render(_Device);
|
||||
_Device->end3D();
|
||||
}
|
||||
*/
|
||||
/*
|
||||
device->pushAbsoluteTransformation(Vector3(), camera->getRotation());
|
||||
|
||||
class RenderState
|
||||
{
|
||||
bool _Blending;
|
||||
GLint _BlendFuncSrc;
|
||||
GLint _BlendFuncDest;
|
||||
|
||||
bool _DepthTest;
|
||||
bool _DepthMask;
|
||||
|
||||
bool _Lighting;
|
||||
};
|
||||
GLfloat mat_specular[] =
|
||||
{ 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat mat_shininess[] =
|
||||
{ 2.0 };
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor4d( 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
device->setTexture(0, starTexture, true);
|
||||
starMesh->render();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
device->popTransformation();
|
||||
*/
|
||||
// device->useShader (program);
|
||||
// device->setTexture (stage, name, texture)
|
||||
// device->clearTextures (stage+1);
|
||||
//glEnable (GL_TEXTURE_2D);
|
||||
//glEnable (GL_LIGHTING);
|
||||
//glBindTexture (GL_TEXTURE_2D, texture->getId() );
|
||||
|
||||
// device->
|
||||
//device->
|
||||
//model->render();
|
||||
if (_Paused == false)
|
||||
{
|
||||
_Simulation->saveStates();
|
||||
_Simulation->updateSteps(delta);
|
||||
while (_Simulation->getSteps() > 0)
|
||||
{
|
||||
_ScriptSystem->callFunction("OnStep",
|
||||
_Simulation->getStepSize(), _SimulationTime);
|
||||
_SimulationTime += _Simulation->getStepSize();
|
||||
_Simulation->step();
|
||||
}
|
||||
}
|
||||
|
||||
_Device->begin2D();
|
||||
_ScriptSystem->callFunction("OnOverlay", delta, now - _StartTime);
|
||||
_Device->end2D();
|
||||
|
||||
_Device->swap();
|
||||
}
|
||||
|
||||
clog << "--- main loop finished..."<< endlog;
|
||||
}
|
||||
|
||||
void Application::setSceneGraph(SceneGraph *graph)
|
||||
{
|
||||
_SceneGraph = graph;
|
||||
}
|
||||
|
||||
void Application::togglePause()
|
||||
{
|
||||
_Paused = !_Paused;
|
||||
}
|
||||
}
|
||||
|
60
engine/Application.h
Normal file
60
engine/Application.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef BLUECORE_APPLICATION_H
|
||||
#define BLUECORE_APPLICATION_H
|
||||
|
||||
#include "RenderWindow.h"
|
||||
#include "RenderDevice.h"
|
||||
#include "FontManager.h"
|
||||
#include "MeshManager.h"
|
||||
#include "TextureManager.h"
|
||||
#include "ShaderManager.h"
|
||||
#include "ModelManager.h"
|
||||
#include "TextureImage.h"
|
||||
#include "ScriptSystem.h"
|
||||
#include "RigidBodySimulation.h"
|
||||
#include "SceneGraph.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
class Application : public Referenced, public sigslot::has_slots<>
|
||||
{
|
||||
bool _Running;
|
||||
bool _Paused;
|
||||
|
||||
double _SimulationTime;
|
||||
double _StartTime;
|
||||
double _LastTime;
|
||||
|
||||
double _CameraPhi, _CameraTheta, _CameraRadius;
|
||||
int _LastMouseX, _LastMouseY, _LastWheel;
|
||||
|
||||
ref_ptr<RenderWindow> _Window;
|
||||
ref_ptr<RenderDevice> _Device;
|
||||
ref_ptr<FontManager> _FontManager;
|
||||
ref_ptr<MeshManager> _MeshManager;
|
||||
ref_ptr<TextureManager> _TextureManager;
|
||||
ref_ptr<ScriptSystem> _ScriptSystem;
|
||||
ref_ptr<ShaderManager> _ShaderManager;
|
||||
ref_ptr<RigidBodySimulation> _Simulation;
|
||||
ref_ptr<ModelManager> _ModelManager;
|
||||
ref_ptr<RenderQueue> _RenderQueue;
|
||||
ref_ptr<SceneGraph> _SceneGraph;
|
||||
|
||||
|
||||
void KeySlot(int key, int action);
|
||||
void MouseMoveSlot(int x, int y);
|
||||
void MouseWheelSlot(int z);
|
||||
|
||||
public:
|
||||
|
||||
bool initialize();
|
||||
void shutdown();
|
||||
void quit();
|
||||
void run();
|
||||
void togglePause();
|
||||
|
||||
void setSceneGraph (SceneGraph *scenegraph);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /*APPLICATION_H_*/
|
@ -7,44 +7,36 @@
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
|
||||
Camera::Camera()
|
||||
Camera::Camera() :
|
||||
_LookAt (false), _FoV(45.0), _NearPlane(1.0), _FarPlane(15000.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Camera::setFoV(Scalar fov)
|
||||
{
|
||||
_FoV = fov;
|
||||
}
|
||||
|
||||
|
||||
void Camera::setAspectRatio(Scalar aspect)
|
||||
{
|
||||
_AspectRatio = aspect;
|
||||
}
|
||||
|
||||
|
||||
void Camera::setNearPlane(Scalar near)
|
||||
{
|
||||
_NearPlane = near;
|
||||
}
|
||||
|
||||
|
||||
void Camera::setFarPlane(Scalar far)
|
||||
{
|
||||
_FarPlane = far;
|
||||
}
|
||||
|
||||
|
||||
void Camera::setPosition(const Vector3& position)
|
||||
{
|
||||
_Position = position;
|
||||
|
||||
if (_LookAt)
|
||||
updateLookAtRotation();
|
||||
}
|
||||
|
||||
const Vector3& Camera::getPosition()
|
||||
@ -52,7 +44,6 @@ const Vector3& Camera::getPosition()
|
||||
return _Position;
|
||||
}
|
||||
|
||||
|
||||
void Camera::setRotation(const Quaternion& rotation)
|
||||
{
|
||||
_Rotation = rotation;
|
||||
@ -63,69 +54,6 @@ const Quaternion& Camera::getRotation()
|
||||
return _Rotation;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
void Camera::setupProjectionMatrix()
|
||||
{
|
||||
Scalar fW, fH;
|
||||
|
||||
fH = tan ( (_FoV / 2) / 180* Pi ) * _NearPlane;
|
||||
fW = fH * _AspectRatio;
|
||||
|
||||
// setup projectiom matrix
|
||||
glMatrixMode (GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
glFrustum ( -fW, fW, -fH, fH, _NearPlane, _FarPlane );
|
||||
|
||||
// save variables for frustum culling
|
||||
/*
|
||||
_near = nearZ;
|
||||
_far = farZ;
|
||||
_hNear = tan ( ( fov / 2 ) / 180 * Pi ) * nearZ;
|
||||
_wNear = _hNear * aspect;
|
||||
_hFar = tan ( ( fov / 2 ) / 180 * Pi ) * farZ;
|
||||
_wFar = _hFar * aspect;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::setupViewMatrix()
|
||||
{
|
||||
// set the view matrix
|
||||
glMatrixMode (GL_MODELVIEW );
|
||||
glLoadIdentity();
|
||||
Matrix4x4 m(_Rotation, _Rotation.applyInversed(_Position * -1.0) );
|
||||
glMultMatrixd ( ( GLdouble * ) &m.m );
|
||||
/*
|
||||
// calculate frustum planes
|
||||
Vector3 up = q.apply ( Vector3 ( 0.0, 1.0, 0.0 ) );
|
||||
Vector3 right = q.apply ( Vector3 ( 1.0, 0.0, 0.0 ) );
|
||||
Vector3 d = q.apply ( Vector3 ( 0.0, 0.0, -1.0 ) );
|
||||
|
||||
Vector3 fc = p + d * _far;
|
||||
|
||||
Vector3 ftl = fc + ( up * _hFar ) - ( right * _wFar );
|
||||
Vector3 ftr = fc + ( up * _hFar ) + ( right * _wFar );
|
||||
Vector3 fbl = fc - ( up * _hFar ) - ( right * _wFar );
|
||||
Vector3 fbr = fc - ( up * _hFar ) + ( right * _wFar );
|
||||
|
||||
Vector3 nc = p + d * _near;
|
||||
|
||||
Vector3 ntl = nc + ( up * _hNear ) - ( right * _wNear );
|
||||
Vector3 ntr = nc + ( up * _hNear ) + ( right * _wNear );
|
||||
Vector3 nbl = nc - ( up * _hNear ) - ( right * _wNear );
|
||||
Vector3 nbr = nc - ( up * _hNear ) + ( right * _wNear );
|
||||
|
||||
_frustumPlanes[RightPlane] = Plane ( nbr, fbr, ntr );
|
||||
_frustumPlanes[LeftPlane] = Plane ( ntl, fbl, nbl );
|
||||
_frustumPlanes[BottomPlane] = Plane ( nbl, fbr, nbr );
|
||||
_frustumPlanes[TopPlane] = Plane ( ntr, ftl, ntl );
|
||||
_frustumPlanes[FarPlane] = Plane ( ftl, ftr, fbl );
|
||||
_frustumPlanes[NearPlane] = Plane ( ntl, nbl, ntr );
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
Scalar Camera::getNearPlane() const
|
||||
{
|
||||
return _NearPlane;
|
||||
@ -141,5 +69,19 @@ Scalar Camera::getFov() const
|
||||
return _FoV;
|
||||
}
|
||||
|
||||
} // namespace BlueCore
|
||||
void Camera::lookAt(const Vector3 &point)
|
||||
{
|
||||
_LookAt = true;
|
||||
_LookAtPoint = point;
|
||||
_LookAtUp = Vector3(0.0, 1.0, 0.0);
|
||||
|
||||
updateLookAtRotation();
|
||||
}
|
||||
|
||||
void Camera::updateLookAtRotation()
|
||||
{
|
||||
Matrix3x3 m (_LookAtPoint - _Position, _LookAtUp);
|
||||
_Rotation = m.toQuaternion().inversed();
|
||||
}
|
||||
|
||||
} // namespace BlueCore
|
||||
|
@ -19,12 +19,14 @@ private:
|
||||
Vector3 _LookAtPoint;
|
||||
Vector3 _LookAtUp;
|
||||
bool _LookAt;
|
||||
Scalar _NearPlane, _FarPlane, _FoV, _AspectRatio;
|
||||
Scalar _FoV, _NearPlane, _FarPlane;
|
||||
//Frustum _Frustum;
|
||||
|
||||
Vector3 _Position;
|
||||
Quaternion _Rotation;
|
||||
|
||||
void updateLookAtRotation();
|
||||
|
||||
public:
|
||||
|
||||
Camera();
|
||||
@ -35,7 +37,6 @@ public:
|
||||
void lookStraight();
|
||||
|
||||
void setFoV(Scalar fov);
|
||||
void setAspectRatio(Scalar aspect);
|
||||
void setNearPlane(Scalar near);
|
||||
void setFarPlane(Scalar far);
|
||||
|
||||
@ -48,7 +49,7 @@ public:
|
||||
Scalar getNearPlane() const;
|
||||
Scalar getFarPlane() const;
|
||||
Scalar getFov() const;
|
||||
|
||||
|
||||
//const Frustum &getFrustum() const;
|
||||
};
|
||||
|
||||
|
1405
engine/Math/Matrix.h
1405
engine/Math/Matrix.h
File diff suppressed because it is too large
Load Diff
@ -5,362 +5,234 @@
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
template <class T>
|
||||
class QuaternionTemplate
|
||||
template<class T> class QuaternionTemplate
|
||||
{
|
||||
public:
|
||||
T w, x, y, z;
|
||||
|
||||
inline QuaternionTemplate()
|
||||
{
|
||||
public:
|
||||
T w, x, y, z;
|
||||
w = static_cast<T>(1.0);
|
||||
x = static_cast<T>(0.0);
|
||||
y = static_cast<T>(0.0);
|
||||
z = static_cast<T>(0.0);
|
||||
}
|
||||
|
||||
template<class S> inline QuaternionTemplate(S w, S x, S y, S z)
|
||||
{
|
||||
this->w = static_cast<T>(w);
|
||||
this->x = static_cast<T>(x);
|
||||
this->y = static_cast<T>(y);
|
||||
this->z = static_cast<T>(z);
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
inline QuaternionTemplate()
|
||||
{
|
||||
w = static_cast<T>(1.0);
|
||||
x = static_cast<T>(0.0);
|
||||
y = static_cast<T>(0.0);
|
||||
z = static_cast<T>(0.0);
|
||||
}
|
||||
|
||||
template<class S> inline QuaternionTemplate(Vector3Template<S> axis, S angle)
|
||||
{
|
||||
T half_angle = static_cast<T>(angle)/static_cast<T>(2.0);
|
||||
T sin_half_angle = static_cast<T>(sin(half_angle) );
|
||||
|
||||
/**
|
||||
* contructor
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate( S w, S x, S y, S z )
|
||||
{
|
||||
this->w = static_cast<T>(w);
|
||||
this->x = static_cast<T>(x);
|
||||
this->y = static_cast<T>(y);
|
||||
this->z = static_cast<T>(z);
|
||||
}
|
||||
w = static_cast<T>(cos(half_angle) );
|
||||
x = sin_half_angle * static_cast<T>(axis.x);
|
||||
y = sin_half_angle * static_cast<T>(axis.y);
|
||||
z = sin_half_angle * static_cast<T>(axis.z);
|
||||
}
|
||||
|
||||
template<class S> inline QuaternionTemplate(S h, S a, S b)
|
||||
{
|
||||
T c1 = static_cast<T>(cos(h / 2.0) );
|
||||
T c2 = static_cast<T>(cos(a / 2.0) );
|
||||
T c3 = static_cast<T>(cos(b / 2.0) );
|
||||
T s1 = static_cast<T>(sin(h / 2.0) );
|
||||
T s2 = static_cast<T>(sin(a / 2.0) );
|
||||
T s3 = static_cast<T>(sin(b / 2.0) );
|
||||
|
||||
/**
|
||||
* contructor
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate( Vector3Template<S> axis, S angle )
|
||||
{
|
||||
T half_angle = static_cast<T>(angle)/static_cast<T>(2.0);
|
||||
T sin_half_angle = static_cast<T>( sin( half_angle ) );
|
||||
|
||||
w = static_cast<T>( cos( half_angle ) );
|
||||
x = sin_half_angle * static_cast<T>(axis.x);
|
||||
y = sin_half_angle * static_cast<T>(axis.y);
|
||||
z = sin_half_angle * static_cast<T>(axis.z);
|
||||
}
|
||||
w = c1 * c2 * c3 - s1 * s2 * s3;
|
||||
x = s1 * s2 * c3 + c1 * c2 * s3;
|
||||
y = s1 * c2 * c3 + c1 * s2 * s3;
|
||||
z = c1 * s2 * c3 - s1 * c2 * s3;
|
||||
}
|
||||
|
||||
inline void identity()
|
||||
{
|
||||
w = static_cast<T>(1.0);
|
||||
x = static_cast<T>(0.0);
|
||||
y = static_cast<T>(0.0);
|
||||
z = static_cast<T>(0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* contructor
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate( S h, S a, S b )
|
||||
{
|
||||
T c1 = static_cast<T>( cos(h / 2.0) );
|
||||
T c2 = static_cast<T>( cos(a / 2.0) );
|
||||
T c3 = static_cast<T>( cos(b / 2.0) );
|
||||
T s1 = static_cast<T>( sin(h / 2.0) );
|
||||
T s2 = static_cast<T>( sin(a / 2.0) );
|
||||
T s3 = static_cast<T>( sin(b / 2.0) );
|
||||
|
||||
w = c1 * c2 * c3 - s1 * s2 * s3;
|
||||
x = s1 * s2 * c3 + c1 * c2 * s3;
|
||||
y = s1 * c2 * c3 + c1 * s2 * s3;
|
||||
z = c1 * s2 * c3 - s1 * c2 * s3;
|
||||
}
|
||||
template<class S> inline QuaternionTemplate<T> operator +(
|
||||
const QuaternionTemplate<S> &a) const
|
||||
{
|
||||
return QuaternionTemplate<T>(w + static_cast<T>(a.w), x
|
||||
+ static_cast<T>(a.x), y + static_cast<T>(a.y), z
|
||||
+ static_cast<T>(a.z) );
|
||||
}
|
||||
|
||||
template<class S> inline QuaternionTemplate<T> &operator +=(
|
||||
const QuaternionTemplate<S> &a)
|
||||
{
|
||||
w += static_cast<T>(a.w);
|
||||
x += static_cast<T>(a.x);
|
||||
y += static_cast<T>(a.y);
|
||||
z += static_cast<T>(a.z);
|
||||
|
||||
/**
|
||||
* identity
|
||||
*/
|
||||
inline void identity()
|
||||
{
|
||||
w = static_cast<T>(1.0);
|
||||
x = static_cast<T>(0.0);
|
||||
y = static_cast<T>(0.0);
|
||||
z = static_cast<T>(0.0);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* operator +
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> operator + (
|
||||
const QuaternionTemplate<S> &a ) const
|
||||
{
|
||||
return QuaternionTemplate<T>(
|
||||
w + static_cast<T>(a.w),
|
||||
x + static_cast<T>(a.x),
|
||||
y + static_cast<T>(a.y),
|
||||
z + static_cast<T>(a.z) );
|
||||
}
|
||||
template<class S> inline QuaternionTemplate<T> operator -(
|
||||
const QuaternionTemplate<S> &a) const
|
||||
{
|
||||
return QuaternionTemplate<T>(w - static_cast<T>(a.w), x
|
||||
- static_cast<T>(a.x), y - static_cast<T>(a.y), z
|
||||
- static_cast<T>(a.z) );
|
||||
}
|
||||
|
||||
template<class S> inline QuaternionTemplate<T> operator *(
|
||||
const QuaternionTemplate<S> &a) const
|
||||
{
|
||||
return QuaternionTemplate<T>(w * static_cast<T>(a.w) - x
|
||||
* static_cast<T>(a.x) - y * static_cast<T>(a.y) - z
|
||||
* static_cast<T>(a.z), w * static_cast<T>(a.x) + x
|
||||
* static_cast<T>(a.w) + y * static_cast<T>(a.z) - z
|
||||
* static_cast<T>(a.y), w * static_cast<T>(a.y) - x
|
||||
* static_cast<T>(a.z) + y * static_cast<T>(a.w) + z
|
||||
* static_cast<T>(a.x), w * static_cast<T>(a.z) + x
|
||||
* static_cast<T>(a.y) - y * static_cast<T>(a.x) + z
|
||||
* static_cast<T>(a.w) );
|
||||
}
|
||||
|
||||
/**
|
||||
* operator +=
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> &operator += (
|
||||
const QuaternionTemplate<S> &a )
|
||||
{
|
||||
w += static_cast<T>(a.w);
|
||||
x += static_cast<T>(a.x);
|
||||
y += static_cast<T>(a.y);
|
||||
z += static_cast<T>(a.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
template<class S> inline QuaternionTemplate<T> &operator *=(
|
||||
const QuaternionTemplate<S> &a)
|
||||
{
|
||||
w = w * static_cast<T>(a.w) - x * static_cast<T>(a.x) - y
|
||||
* static_cast<T>(a.y) - z * static_cast<T>(a.z);
|
||||
x = w * static_cast<T>(a.x) + x * static_cast<T>(a.w) + y
|
||||
* static_cast<T>(a.z) - z * static_cast<T>(a.y);
|
||||
y = w * static_cast<T>(a.y) - x * static_cast<T>(a.z) + y
|
||||
* static_cast<T>(a.w) + z * static_cast<T>(a.x);
|
||||
z = w * static_cast<T>(a.z) + x * static_cast<T>(a.y) - y
|
||||
* static_cast<T>(a.x) + z * static_cast<T>(a.w);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* operator -
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> operator - (
|
||||
const QuaternionTemplate<S> &a ) const
|
||||
{
|
||||
return QuaternionTemplate<T>(
|
||||
w - static_cast<T>(a.w),
|
||||
x - static_cast<T>(a.x),
|
||||
y - static_cast<T>(a.y),
|
||||
z - static_cast<T>(a.z) );
|
||||
}
|
||||
|
||||
template<class S> inline QuaternionTemplate<T> &operator -=(
|
||||
const QuaternionTemplate<S> &a)
|
||||
{
|
||||
w -= static_cast<T>(a.w);
|
||||
x -= static_cast<T>(a.x);
|
||||
y -= static_cast<T>(a.y);
|
||||
z -= static_cast<T>(a.z);
|
||||
|
||||
/**
|
||||
* operator *
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> operator * (
|
||||
const QuaternionTemplate<S> &a ) const
|
||||
{
|
||||
return QuaternionTemplate<T>(
|
||||
w * static_cast<T>(a.w) -
|
||||
x * static_cast<T>(a.x) -
|
||||
y * static_cast<T>(a.y) -
|
||||
z * static_cast<T>(a.z),
|
||||
w * static_cast<T>(a.x) +
|
||||
x * static_cast<T>(a.w) +
|
||||
y * static_cast<T>(a.z) -
|
||||
z * static_cast<T>(a.y),
|
||||
w * static_cast<T>(a.y) -
|
||||
x * static_cast<T>(a.z) +
|
||||
y * static_cast<T>(a.w) +
|
||||
z * static_cast<T>(a.x),
|
||||
w * static_cast<T>(a.z) +
|
||||
x * static_cast<T>(a.y) -
|
||||
y * static_cast<T>(a.x) +
|
||||
z * static_cast<T>(a.w) );
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* operator *=
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> &operator *=(
|
||||
const QuaternionTemplate<S> &a )
|
||||
{
|
||||
w = w * static_cast<T>(a.w) - x * static_cast<T>(a.x) -
|
||||
y * static_cast<T>(a.y) - z * static_cast<T>(a.z);
|
||||
x = w * static_cast<T>(a.x) + x * static_cast<T>(a.w) +
|
||||
y * static_cast<T>(a.z) - z * static_cast<T>(a.y);
|
||||
y = w * static_cast<T>(a.y) - x * static_cast<T>(a.z) +
|
||||
y * static_cast<T>(a.w) + z * static_cast<T>(a.x);
|
||||
z = w * static_cast<T>(a.z) + x * static_cast<T>(a.y) -
|
||||
y * static_cast<T>(a.x) + z * static_cast<T>(a.w);
|
||||
|
||||
return *this;
|
||||
}
|
||||
template<class S> inline QuaternionTemplate<T> &operator =(
|
||||
const QuaternionTemplate<S> &a)
|
||||
{
|
||||
w = static_cast<T>(a.w);
|
||||
x = static_cast<T>(a.x);
|
||||
y = static_cast<T>(a.y);
|
||||
z = static_cast<T>(a.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* operator -=
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> &operator -= (
|
||||
const QuaternionTemplate<S> &a )
|
||||
{
|
||||
w -= static_cast<T>(a.w);
|
||||
x -= static_cast<T>(a.x);
|
||||
y -= static_cast<T>(a.y);
|
||||
z -= static_cast<T>(a.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
inline QuaternionTemplate<T> unit() const
|
||||
{
|
||||
T d = 1/sqrt(w*w + x*x + y*y + z*z);
|
||||
return QuaternionTemplate<T>(w * d, x * d, y * d, z * d);
|
||||
}
|
||||
|
||||
inline QuaternionTemplate<T> inversed() const
|
||||
{
|
||||
return QuaternionTemplate<T>(w, -x, -y, -z);
|
||||
}
|
||||
|
||||
/**
|
||||
* operator =
|
||||
*/
|
||||
template <class S>
|
||||
inline QuaternionTemplate<T> &operator = (
|
||||
const QuaternionTemplate<S> &a )
|
||||
{
|
||||
w = static_cast<T>(a.w);
|
||||
x = static_cast<T>(a.x);
|
||||
y = static_cast<T>(a.y);
|
||||
z = static_cast<T>(a.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
inline void inverse()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
inline QuaternionTemplate<T> &normalize()
|
||||
{
|
||||
T d = 1/sqrt(w*w + x*x + y*y + z*z);
|
||||
w *= d;
|
||||
x *= d;
|
||||
y *= d;
|
||||
z *= d;
|
||||
|
||||
/**
|
||||
* unit
|
||||
*/
|
||||
inline QuaternionTemplate<T> unit() const
|
||||
{
|
||||
T d = 1/sqrt( w*w + x*x + y*y + z*z );
|
||||
return QuaternionTemplate<T>( w * d, x * d, y * d, z * d );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* inversed
|
||||
*/
|
||||
inline QuaternionTemplate<T> inversed() const
|
||||
{
|
||||
return QuaternionTemplate<T>( w, -x, -y, -z );
|
||||
}
|
||||
|
||||
/**
|
||||
* inversed
|
||||
*/
|
||||
inline void inverse()
|
||||
{
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* normalize
|
||||
*/
|
||||
inline QuaternionTemplate<T> &normalize()
|
||||
{
|
||||
T d = 1/sqrt( w*w + x*x + y*y + z*z );
|
||||
w *= d;
|
||||
x *= d;
|
||||
y *= d;
|
||||
z *= d;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* apply
|
||||
*/
|
||||
template <class S>
|
||||
inline const Vector3Template<T> apply(
|
||||
const Vector3Template<S> &a ) const
|
||||
{
|
||||
T xx = x*x, xy = x*y, xz = x*z, xw = x*w,
|
||||
yy = y*y, yz = y*z, yw = y*w,
|
||||
template<class S> inline const Vector3Template<T> apply(
|
||||
const Vector3Template<S> &a) const
|
||||
{
|
||||
T xx = x*x, xy = x*y, xz = x*z, xw = x*w, yy = y*y, yz = y*z, yw = y*w,
|
||||
zz = z*z, zw = z*w;
|
||||
|
||||
return Vector3Template<T>(
|
||||
2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy - zz ) +
|
||||
static_cast<T>(a.y) * ( xy - zw ) +
|
||||
static_cast<T>(a.z) * ( xz + yw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * ( xy + zw ) +
|
||||
static_cast<T>(a.y) * ( 0.5 - xx - zz ) +
|
||||
static_cast<T>(a.z) * ( yz - xw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * ( xz - yw ) +
|
||||
static_cast<T>(a.y) * ( yz + xw ) +
|
||||
static_cast<T>(a.z) * ( 0.5 - xx - yy ) ) );
|
||||
}
|
||||
|
||||
return Vector3Template<T>( 2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy
|
||||
- zz ) + static_cast<T>(a.y) * (xy - zw ) + static_cast<T>(a.z)
|
||||
* (xz + yw ) ),
|
||||
|
||||
/**
|
||||
* apply
|
||||
*/
|
||||
template <class S>
|
||||
inline const Vector3Template<T> operator * (
|
||||
const Vector3Template<S> &a ) const
|
||||
{
|
||||
T xx = x*x, xy = x*y, xz = x*z, xw = x*w,
|
||||
yy = y*y, yz = y*z, yw = y*w,
|
||||
2.0 * ( static_cast<T>(a.x) * (xy + zw ) + static_cast<T>(a.y) * ( 0.5
|
||||
- xx - zz ) + static_cast<T>(a.z) * (yz - xw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * (xz - yw ) + static_cast<T>(a.y) * (yz
|
||||
+ xw ) + static_cast<T>(a.z) * ( 0.5 - xx - yy ) ));
|
||||
}
|
||||
|
||||
template<class S> inline const Vector3Template<T> operator *(
|
||||
const Vector3Template<S> &a) const
|
||||
{
|
||||
T xx = x*x, xy = x*y, xz = x*z, xw = x*w, yy = y*y, yz = y*z, yw = y*w,
|
||||
zz = z*z, zw = z*w;
|
||||
|
||||
return Vector3Template<T>(
|
||||
2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy - zz ) +
|
||||
static_cast<T>(a.y) * ( xy - zw ) +
|
||||
static_cast<T>(a.z) * ( xz + yw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * ( xy + zw ) +
|
||||
static_cast<T>(a.y) * ( 0.5 - xx - zz ) +
|
||||
static_cast<T>(a.z) * ( yz - xw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * ( xz - yw ) +
|
||||
static_cast<T>(a.y) * ( yz + xw ) +
|
||||
static_cast<T>(a.z) * ( 0.5 - xx - yy ) ) );
|
||||
}
|
||||
|
||||
return Vector3Template<T>( 2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy
|
||||
- zz ) + static_cast<T>(a.y) * (xy - zw ) + static_cast<T>(a.z)
|
||||
* (xz + yw ) ),
|
||||
|
||||
/**
|
||||
* applyInversed
|
||||
*/
|
||||
template <class S>
|
||||
inline Vector3Template<T> applyInversed(
|
||||
const Vector3Template<S> &a ) const
|
||||
{
|
||||
T xx = x*x, xy = x*y, xz = x*z, xw = -x*w,
|
||||
yy = y*y, yz = y*z, yw = -y*w,
|
||||
zz = z*z, zw = -z*w;
|
||||
|
||||
return Vector3Template<T>(
|
||||
2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy - zz ) +
|
||||
static_cast<T>(a.y) * ( xy - zw ) +
|
||||
static_cast<T>(a.z) * ( xz + yw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * ( xy + zw ) +
|
||||
static_cast<T>(a.y) * ( 0.5 - xx - zz ) +
|
||||
static_cast<T>(a.z) * ( yz - xw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * ( xz - yw ) +
|
||||
static_cast<T>(a.y) * ( yz + xw ) +
|
||||
static_cast<T>(a.z) * ( 0.5 - xx - yy ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* transform from ode to gl coodinates
|
||||
*/
|
||||
inline QuaternionTemplate<T> toGl() const
|
||||
{
|
||||
return QuaternionTemplate<T>( w, x, z, -y );
|
||||
}
|
||||
2.0 * ( static_cast<T>(a.x) * (xy + zw ) + static_cast<T>(a.y) * ( 0.5
|
||||
- xx - zz ) + static_cast<T>(a.z) * (yz - xw ) ),
|
||||
|
||||
/**
|
||||
* transform from gl to ode coodinates
|
||||
*/
|
||||
inline QuaternionTemplate<T> toOde() const
|
||||
{
|
||||
return QuaternionTemplate<T>( w, x, -z, y );
|
||||
}
|
||||
|
||||
inline QuaternionTemplate<T> slerp( const QuaternionTemplate<T> &q, const Scalar &t )
|
||||
{
|
||||
Scalar phi = acos(w*q.w + x*q.x + y*q.y + z*q.z);
|
||||
Scalar s = 1 / sin(phi);
|
||||
Scalar a = sin(phi*(1-t)) * s;
|
||||
Scalar b = sin(phi*t) * s;
|
||||
2.0 * ( static_cast<T>(a.x) * (xz - yw ) + static_cast<T>(a.y) * (yz
|
||||
+ xw ) + static_cast<T>(a.z) * ( 0.5 - xx - yy ) ));
|
||||
}
|
||||
|
||||
return QuaternionTemplate<T>( a*w+b*q.w, a*x+b*q.x, a*y+b*q.y, a*z+b*q.z );
|
||||
}
|
||||
};
|
||||
|
||||
typedef QuaternionTemplate<float> QuaternionFloat;
|
||||
typedef QuaternionTemplate<double> QuaternionDouble;
|
||||
typedef QuaternionTemplate<Scalar> Quaternion;
|
||||
template<class S> inline Vector3Template<T> applyInversed(
|
||||
const Vector3Template<S> &a) const
|
||||
{
|
||||
T xx = x*x, xy = x*y, xz = x*z, xw = -x*w, yy = y*y, yz = y*z, yw = -y
|
||||
*w, zz = z*z, zw = -z*w;
|
||||
|
||||
return Vector3Template<T>( 2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy
|
||||
- zz ) + static_cast<T>(a.y) * (xy - zw ) + static_cast<T>(a.z)
|
||||
* (xz + yw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * (xy + zw ) + static_cast<T>(a.y) * ( 0.5
|
||||
- xx - zz ) + static_cast<T>(a.z) * (yz - xw ) ),
|
||||
|
||||
2.0 * ( static_cast<T>(a.x) * (xz - yw ) + static_cast<T>(a.y) * (yz
|
||||
+ xw ) + static_cast<T>(a.z) * ( 0.5 - xx - yy ) ));
|
||||
}
|
||||
|
||||
inline QuaternionTemplate<T> slerp(const QuaternionTemplate<T> &q,
|
||||
const Scalar &t)
|
||||
{
|
||||
T phi = acos(w*q.w + x*q.x + y*q.y + z*q.z);
|
||||
T s = 1 / sin(phi);
|
||||
T a = sin(phi*(1-t)) * s;
|
||||
T b = sin(phi*t) * s;
|
||||
|
||||
return QuaternionTemplate<T>(a*w+b*q.w, a*x+b*q.x, a*y+b*q.y, a*z+b*q.z);
|
||||
}
|
||||
};
|
||||
|
||||
typedef QuaternionTemplate<float> QuaternionFloat;
|
||||
typedef QuaternionTemplate<double> QuaternionDouble;
|
||||
typedef QuaternionTemplate<Scalar> Quaternion;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -20,25 +20,21 @@ namespace BlueCore
|
||||
void Model::render(RenderDevice *device) const
|
||||
{
|
||||
ModelMesh->render();
|
||||
//glEnable(GL_LIGHTING);
|
||||
//glDepthFunc ( GL_LEQUAL );
|
||||
//glEnable ( GL_DEPTH_TEST );
|
||||
//glDepthMask ( GL_TRUE );
|
||||
|
||||
/*
|
||||
glEnable(GL_LIGHTING);
|
||||
glDepthFunc ( GL_LEQUAL );
|
||||
glEnable ( GL_DEPTH_TEST );
|
||||
glDepthMask ( GL_TRUE );
|
||||
*/
|
||||
/*
|
||||
glEnableClientState (GL_VERTEX_ARRAY );
|
||||
glEnableClientState (GL_TEXTURE_COORD_ARRAY );
|
||||
glEnableClientState (GL_NORMAL_ARRAY );
|
||||
|
||||
glMatrixMode (GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
Matrix4x4 m(_AbsoluteRotation, _AbsoluteTranslation);
|
||||
glMultMatrixd ( ( GLdouble * ) &m.m );
|
||||
|
||||
mesh->vertex_buffer.bind();
|
||||
mesh->index_buffer.bind();
|
||||
*/
|
||||
/*
|
||||
/*
|
||||
glMaterialfv (GL_FRONT, GL_SHININESS, &pass.Shininess);
|
||||
glMaterialfv (GL_FRONT, GL_SPECULAR, ( GLfloat * ) &pass.Specular );
|
||||
|
||||
|
@ -137,10 +137,12 @@ void RenderDevice::setupProjectionMatrix()
|
||||
void RenderDevice::setupViewMatrix()
|
||||
{
|
||||
if (_Camera.valid())
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
||||
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||
glLoadIdentity();
|
||||
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
||||
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||
}
|
||||
}
|
||||
|
||||
void RenderDevice::pushTransformation(const Vector3& position,
|
||||
|
@ -545,7 +545,6 @@ bool RigidBodySimulation::step()
|
||||
{
|
||||
if (_steps > 0)
|
||||
{
|
||||
_ScriptSystem->callFunction("OnStep", _stepSize);
|
||||
dSpaceCollide(_space, 0, &nearCallback);
|
||||
dWorldQuickStep(_world, _stepSize);
|
||||
StepSignal(_stepSize);
|
||||
|
@ -25,7 +25,7 @@ namespace BlueCore
|
||||
{
|
||||
class RigidBodySimulation;
|
||||
|
||||
class RigidBody
|
||||
class RigidBody : public Referenced
|
||||
{
|
||||
Vector3 _Position;
|
||||
Quaternion _Orientation;
|
||||
|
35
engine/SceneGraph.cpp
Normal file
35
engine/SceneGraph.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "SceneGraph.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
SceneGraph::SceneGraph()
|
||||
{
|
||||
_RootNode = new SceneNode();
|
||||
}
|
||||
SceneGraph::~SceneGraph()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SceneNode* SceneGraph::getRootNode()
|
||||
{
|
||||
return _RootNode.pointer();
|
||||
}
|
||||
|
||||
void SceneGraph::setCamera(Camera *camera)
|
||||
{
|
||||
_Camera = camera;
|
||||
}
|
||||
|
||||
void SceneGraph::update(Scalar time)
|
||||
{
|
||||
_RootNode->update (time);
|
||||
}
|
||||
|
||||
void SceneGraph::queue (RenderQueue *queue)
|
||||
{
|
||||
_RootNode->queue (queue, _Camera);
|
||||
}
|
||||
|
||||
}
|
29
engine/SceneGraph.h
Normal file
29
engine/SceneGraph.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef BLUECORE_SCENEGRAPH_H
|
||||
#define BLUECORE_SCENEGRAPH_H
|
||||
|
||||
#include "SceneNode.h"
|
||||
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
class SceneGraph : public Referenced
|
||||
{
|
||||
ref_ptr<SceneNode> _RootNode;
|
||||
ref_ptr<Camera> _Camera;
|
||||
|
||||
public:
|
||||
SceneGraph();
|
||||
~SceneGraph();
|
||||
|
||||
SceneNode* getRootNode();
|
||||
|
||||
void setCamera(Camera *camera);
|
||||
|
||||
void update(Scalar time);
|
||||
void queue (RenderQueue *queue);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /*SCENEGRAPH_H_*/
|
@ -1,162 +1,150 @@
|
||||
#include "SceneNode.h"
|
||||
|
||||
namespace BlueCore {
|
||||
namespace BlueCore
|
||||
{
|
||||
|
||||
#define DEBUG_SCENEGRAPH
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SceneNode::SceneNode() :
|
||||
Named("unnamed SceneNode"), _Parent(0)
|
||||
Named("unnamed SceneNode"), _Parent(0)
|
||||
{
|
||||
#ifdef DEBUG_SCENEGRAPH
|
||||
clog << "SceneNode 'Unnamed SceneNode' created." << endline;
|
||||
clog << "SceneNode 'Unnamed SceneNode' created." << endline;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SceneNode::SceneNode(const std::string &name) :
|
||||
Named(name), _Parent(0)
|
||||
Named(name), _Parent(0)
|
||||
{
|
||||
#ifdef DEBUG_SCENEGRAPH
|
||||
clog << "SceneNode '" << name << "' created." << endline;
|
||||
clog << "SceneNode '" << name << "' created." << endline;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SceneNode::~SceneNode()
|
||||
{
|
||||
detachAll();
|
||||
detachAll();
|
||||
|
||||
#ifdef DEBUG_SCENEGRAPH
|
||||
clog << "SceneNode '" << getName() << "' deleted." << endline;
|
||||
#endif
|
||||
#ifdef DEBUG_SCENEGRAPH
|
||||
clog << "SceneNode '" << getName() << "' deleted." << endline;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::attach(SceneNode *node)
|
||||
{
|
||||
if (node == 0)
|
||||
return;
|
||||
if (node == 0)
|
||||
return;
|
||||
|
||||
_Children.push_back(node );
|
||||
_Children.push_back(node);
|
||||
|
||||
node->_Parent = this;
|
||||
node->_Parent = this;
|
||||
|
||||
node->addReference();
|
||||
node->addReference();
|
||||
|
||||
#ifdef DEBUG_SCENEGRAPH
|
||||
clog << "SceneNode '" << node->getName() << "' attached to '" << this->getName() << "'" << endline;
|
||||
clog << "SceneNode '" << node->getName() << "' attached to '"
|
||||
<< this->getName() << "'" << endline;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::detach(SceneNode *node)
|
||||
{
|
||||
node->_Parent = 0;
|
||||
node->removeReference();
|
||||
node->_Parent = 0;
|
||||
node->removeReference();
|
||||
|
||||
_Children.remove(node );
|
||||
_Children.remove(node);
|
||||
|
||||
#ifdef DEBUG_SCENEGRAPH
|
||||
clog << "SceneNode '" << node->getName() << "' detach from '" << this->getName() << "'" << endline;
|
||||
clog << "SceneNode '" << node->getName() << "' detach from '"
|
||||
<< this->getName() << "'" << endline;
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::detachAll()
|
||||
{
|
||||
SceneNodeList::iterator i;
|
||||
SceneNodeList::iterator i;
|
||||
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
{
|
||||
( *i )->_Parent = 0;
|
||||
( *i )->removeReference();
|
||||
}
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
{
|
||||
( *i )->_Parent = 0;
|
||||
( *i )->removeReference();
|
||||
}
|
||||
|
||||
_Children.clear();
|
||||
_Children.clear();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
SceneNode *SceneNode::getParent() const
|
||||
{
|
||||
return _Parent;
|
||||
return _Parent;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::detachFromParent()
|
||||
{
|
||||
if (_Parent )
|
||||
_Parent->detach( this);
|
||||
if (_Parent)
|
||||
_Parent->detach( this);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const SceneNode::SceneNodeList& SceneNode::getChildren () const
|
||||
const SceneNode::SceneNodeList& SceneNode::getChildren() const
|
||||
{
|
||||
return _Children;
|
||||
return _Children;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::update(Scalar time)
|
||||
{
|
||||
updateAbsoluteTransformation();
|
||||
updateAbsoluteTransformation();
|
||||
|
||||
// if (isActive() )
|
||||
{
|
||||
SceneNodeList::iterator i;
|
||||
// if (isActive() )
|
||||
{
|
||||
SceneNodeList::iterator i;
|
||||
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
( *i )->update(time );
|
||||
}
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
( *i )->update(time);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::render(RenderDevice *device, Camera *camera)
|
||||
void SceneNode::queue(RenderQueue *queue, Camera *camera)
|
||||
{
|
||||
if (isActive() )
|
||||
{
|
||||
SceneNodeList::iterator i;
|
||||
if (isActive())
|
||||
{
|
||||
SceneNodeList::iterator i;
|
||||
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
{
|
||||
( *i )->render(device, camera);
|
||||
}
|
||||
}
|
||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||
{
|
||||
( *i )->queue(queue, camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const Transformation& SceneNode::getRelativeTransformation()
|
||||
{
|
||||
return _RelativeTransformation;
|
||||
return _RelativeTransformation;
|
||||
}
|
||||
|
||||
const Transformation& SceneNode::getAbsoluteTransformation()
|
||||
{
|
||||
return _AbsoluteTransformation;
|
||||
return _AbsoluteTransformation;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::setRelativeTranslation(const Vector3 &translation)
|
||||
{
|
||||
_RelativeTransformation.translation = translation;
|
||||
_RelativeTransformation.translation = translation;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::setRelativeRotation (const Quaternion &rotation)
|
||||
void SceneNode::setRelativeRotation(const Quaternion &rotation)
|
||||
{
|
||||
_RelativeTransformation.rotation = rotation;
|
||||
_RelativeTransformation.rotation = rotation;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void SceneNode::updateAbsoluteTransformation()
|
||||
{
|
||||
/*
|
||||
if (_Parent )
|
||||
_AbsoluteTranslation = _Parent->getAbsoluteTranslation()
|
||||
+_Parent->getAbsoluteRotation().inversed() * _RelativeTranslation;
|
||||
else
|
||||
_AbsoluteTranslation = _RelativeTranslation;
|
||||
*/
|
||||
/*
|
||||
if (_Parent )
|
||||
_AbsoluteTranslation = _Parent->getAbsoluteTranslation()
|
||||
+_Parent->getAbsoluteRotation().inversed() * _RelativeTranslation;
|
||||
else
|
||||