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
|
namespace BlueCore
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Camera::Camera() :
|
||||||
Camera::Camera()
|
_LookAt (false), _FoV(45.0), _NearPlane(1.0), _FarPlane(15000.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Camera::~Camera()
|
Camera::~Camera()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Camera::setFoV(Scalar fov)
|
void Camera::setFoV(Scalar fov)
|
||||||
{
|
{
|
||||||
_FoV = fov;
|
_FoV = fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Camera::setAspectRatio(Scalar aspect)
|
|
||||||
{
|
|
||||||
_AspectRatio = aspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Camera::setNearPlane(Scalar near)
|
void Camera::setNearPlane(Scalar near)
|
||||||
{
|
{
|
||||||
_NearPlane = near;
|
_NearPlane = near;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Camera::setFarPlane(Scalar far)
|
void Camera::setFarPlane(Scalar far)
|
||||||
{
|
{
|
||||||
_FarPlane = far;
|
_FarPlane = far;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Camera::setPosition(const Vector3& position)
|
void Camera::setPosition(const Vector3& position)
|
||||||
{
|
{
|
||||||
_Position = position;
|
_Position = position;
|
||||||
|
|
||||||
|
if (_LookAt)
|
||||||
|
updateLookAtRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector3& Camera::getPosition()
|
const Vector3& Camera::getPosition()
|
||||||
@ -52,7 +44,6 @@ const Vector3& Camera::getPosition()
|
|||||||
return _Position;
|
return _Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Camera::setRotation(const Quaternion& rotation)
|
void Camera::setRotation(const Quaternion& rotation)
|
||||||
{
|
{
|
||||||
_Rotation = rotation;
|
_Rotation = rotation;
|
||||||
@ -63,69 +54,6 @@ const Quaternion& Camera::getRotation()
|
|||||||
return _Rotation;
|
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
|
Scalar Camera::getNearPlane() const
|
||||||
{
|
{
|
||||||
return _NearPlane;
|
return _NearPlane;
|
||||||
@ -141,5 +69,19 @@ Scalar Camera::getFov() const
|
|||||||
return _FoV;
|
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 _LookAtPoint;
|
||||||
Vector3 _LookAtUp;
|
Vector3 _LookAtUp;
|
||||||
bool _LookAt;
|
bool _LookAt;
|
||||||
Scalar _NearPlane, _FarPlane, _FoV, _AspectRatio;
|
Scalar _FoV, _NearPlane, _FarPlane;
|
||||||
//Frustum _Frustum;
|
//Frustum _Frustum;
|
||||||
|
|
||||||
Vector3 _Position;
|
Vector3 _Position;
|
||||||
Quaternion _Rotation;
|
Quaternion _Rotation;
|
||||||
|
|
||||||
|
void updateLookAtRotation();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Camera();
|
Camera();
|
||||||
@ -35,7 +37,6 @@ public:
|
|||||||
void lookStraight();
|
void lookStraight();
|
||||||
|
|
||||||
void setFoV(Scalar fov);
|
void setFoV(Scalar fov);
|
||||||
void setAspectRatio(Scalar aspect);
|
|
||||||
void setNearPlane(Scalar near);
|
void setNearPlane(Scalar near);
|
||||||
void setFarPlane(Scalar far);
|
void setFarPlane(Scalar far);
|
||||||
|
|
||||||
|
@ -12,26 +12,17 @@
|
|||||||
|
|
||||||
namespace BlueCore
|
namespace BlueCore
|
||||||
{
|
{
|
||||||
template <class T>
|
template<class T> class Matrix3x3Template
|
||||||
class Matrix3x3Template
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
T m[9];
|
T m[9];
|
||||||
|
|
||||||
/**
|
|
||||||
* default constructor
|
|
||||||
*/
|
|
||||||
inline Matrix3x3Template()
|
inline Matrix3x3Template()
|
||||||
{
|
{
|
||||||
identity();
|
identity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Matrix3x3Template(const S a[9])
|
||||||
/**
|
|
||||||
* constructor from array
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Matrix3x3Template( const S a[9] )
|
|
||||||
{
|
{
|
||||||
m[0] = static_cast<T>(a[0]);
|
m[0] = static_cast<T>(a[0]);
|
||||||
m[1] = static_cast<T>(a[1]);
|
m[1] = static_cast<T>(a[1]);
|
||||||
@ -46,12 +37,7 @@ namespace BlueCore
|
|||||||
m[8] = static_cast<T>(a[8]);
|
m[8] = static_cast<T>(a[8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Matrix3x3Template(const Matrix3x3Template<S> &a)
|
||||||
/**
|
|
||||||
* copy constructor
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Matrix3x3Template( const Matrix3x3Template<S> &a )
|
|
||||||
{
|
{
|
||||||
m[0] = static_cast<T>(a.m[0]);
|
m[0] = static_cast<T>(a.m[0]);
|
||||||
m[1] = static_cast<T>(a.m[1]);
|
m[1] = static_cast<T>(a.m[1]);
|
||||||
@ -66,18 +52,13 @@ namespace BlueCore
|
|||||||
m[8] = static_cast<T>(a.m[8]);
|
m[8] = static_cast<T>(a.m[8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Matrix3x3Template(const Vector3Template<T> &h,
|
||||||
/**
|
|
||||||
* constructor from heading and up vectors
|
|
||||||
*/
|
|
||||||
inline Matrix3x3Template(
|
|
||||||
const Vector3Template<T> &h,
|
|
||||||
const Vector3Template<T> &u)
|
const Vector3Template<T> &u)
|
||||||
{
|
{
|
||||||
Vector3Template<T> a, b, c;
|
Vector3Template<T> a, b, c;
|
||||||
c = h.unit();
|
c = h.normalized();
|
||||||
a = h.crossProduct( u ).unit();
|
a = h.cross( u ).normalized();
|
||||||
b = c.crossProduct( a ).unit();
|
b = c.cross( a ).normalized();
|
||||||
|
|
||||||
m[0] = a.x;
|
m[0] = a.x;
|
||||||
m[1] = b.x;
|
m[1] = b.x;
|
||||||
@ -92,10 +73,6 @@ namespace BlueCore
|
|||||||
m[8] = c.z;
|
m[8] = c.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* contructor from euler angles
|
|
||||||
*/
|
|
||||||
inline Matrix3x3Template(T a, T e, T t)
|
inline Matrix3x3Template(T a, T e, T t)
|
||||||
{
|
{
|
||||||
T ch = cos(a);
|
T ch = cos(a);
|
||||||
@ -118,24 +95,15 @@ namespace BlueCore
|
|||||||
m[8] = -sh*sa*sb + ch*cb;
|
m[8] = -sh*sa*sb + ch*cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Matrix3x3Template(const QuaternionTemplate<S> &q)
|
||||||
/**
|
|
||||||
* contructor from quaternion
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Matrix3x3Template( const QuaternionTemplate<S> &q )
|
|
||||||
{
|
{
|
||||||
T xx = static_cast<T>(q.x*q.x),
|
T xx = static_cast<T>(q.x*q.x), xy = static_cast<T>(q.x*q.y), xz =
|
||||||
xy = static_cast<T>(q.x*q.y),
|
static_cast<T>(q.x*q.z), xw = static_cast<T>(q.x*q.w),
|
||||||
xz = static_cast<T>(q.x*q.z),
|
|
||||||
xw = static_cast<T>(q.x*q.w),
|
|
||||||
|
|
||||||
yy = static_cast<T>(q.y*q.y),
|
yy = static_cast<T>(q.y*q.y), yz = static_cast<T>(q.y*q.z), yw =
|
||||||
yz = static_cast<T>(q.y*q.z),
|
static_cast<T>(q.y*q.w),
|
||||||
yw = static_cast<T>(q.y*q.w),
|
|
||||||
|
|
||||||
zz = static_cast<T>(q.z*q.z),
|
zz = static_cast<T>(q.z*q.z), zw = static_cast<T>(q.z*q.w);
|
||||||
zw = static_cast<T>(q.z*q.w);
|
|
||||||
|
|
||||||
m[0] = 1 - yy - yy - zz - zz;
|
m[0] = 1 - yy - yy - zz - zz;
|
||||||
m[1] = xy + xy + zw + zw;
|
m[1] = xy + xy + zw + zw;
|
||||||
@ -150,10 +118,13 @@ namespace BlueCore
|
|||||||
m[8] = 1 - xx - xx - yy - yy;
|
m[8] = 1 - xx - xx - yy - yy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set(size_t i, Vector3Template<T>& v)
|
||||||
|
{
|
||||||
|
m[i] = v.x;
|
||||||
|
m[i+3] = v.y;
|
||||||
|
m[i+6] = v.z;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* set matrix to identity matrix
|
|
||||||
*/
|
|
||||||
inline void identity()
|
inline void identity()
|
||||||
{
|
{
|
||||||
m[0] = static_cast<T>(1);
|
m[0] = static_cast<T>(1);
|
||||||
@ -169,25 +140,23 @@ namespace BlueCore
|
|||||||
m[8] = static_cast<T>(1);
|
m[8] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get transposed matrix
|
|
||||||
*/
|
|
||||||
inline Matrix3x3Template<T> transposed() const
|
inline Matrix3x3Template<T> transposed() const
|
||||||
{
|
{
|
||||||
Matrix3x3Template<T> a;
|
Matrix3x3Template<T> a;
|
||||||
|
|
||||||
a.m[0] = m[0]; a.m[3] = m[1]; a.m[6] = m[2];
|
a.m[0] = m[0];
|
||||||
a.m[1] = m[3]; a.m[4] = m[4]; a.m[7] = m[5];
|
a.m[3] = m[1];
|
||||||
a.m[2] = m[6]; a.m[5] = m[7]; a.m[8] = m[8];
|
a.m[6] = m[2];
|
||||||
|
a.m[1] = m[3];
|
||||||
|
a.m[4] = m[4];
|
||||||
|
a.m[7] = m[5];
|
||||||
|
a.m[2] = m[6];
|
||||||
|
a.m[5] = m[7];
|
||||||
|
a.m[8] = m[8];
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* transpose
|
|
||||||
*/
|
|
||||||
inline void transpose()
|
inline void transpose()
|
||||||
{
|
{
|
||||||
swap(m[3], m[1]);
|
swap(m[3], m[1]);
|
||||||
@ -195,14 +164,10 @@ namespace BlueCore
|
|||||||
swap(m[7], m[5]);
|
swap(m[7], m[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* determinate
|
|
||||||
*/
|
|
||||||
inline T determinant() const
|
inline T determinant() const
|
||||||
{
|
{
|
||||||
return ( m[0]*m[4]*m[8] + m[1]*m[5]*m[6] + m[2]*m[3]*m[7] )
|
return (m[0]*m[4]*m[8] + m[1]*m[5]*m[6] + m[2]*m[3]*m[7] ) - (m[6]*m[4]
|
||||||
- ( m[6]*m[4]*m[2] + m[7]*m[5]*m[0] + m[8]*m[3]*m[1] );
|
*m[2] + m[7]*m[5]*m[0] + m[8]*m[3]*m[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Matrix3x3Template<T> inverted()
|
inline Matrix3x3Template<T> inverted()
|
||||||
@ -224,12 +189,7 @@ namespace BlueCore
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Matrix3x3Template<T> &operator +=(
|
||||||
/**
|
|
||||||
* add/assign operator
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Matrix3x3Template<T> &operator += (
|
|
||||||
const Matrix3x3Template<S> &a)
|
const Matrix3x3Template<S> &a)
|
||||||
{
|
{
|
||||||
m[0] += static_cast<T>(a.m[0]);
|
m[0] += static_cast<T>(a.m[0]);
|
||||||
@ -247,80 +207,51 @@ namespace BlueCore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Matrix3x3Template<T> operator *(
|
||||||
/**
|
const Matrix3x3Template<S> &a)
|
||||||
* matrix multiplication
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Matrix3x3Template<T> operator * ( const Matrix3x3Template<S> &a )
|
|
||||||
{
|
{
|
||||||
Matrix3x3Template<T> result;
|
Matrix3x3Template<T> result;
|
||||||
|
|
||||||
result.m[0] = m[0] * static_cast<T>(a.m[0])
|
result.m[0] = m[0] * static_cast<T>(a.m[0]) + m[3]
|
||||||
+ m[3] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[6] * static_cast<T>(a.m[2]);
|
||||||
+ m[6] * static_cast<T>(a.m[2]);
|
|
||||||
|
|
||||||
result.m[1] = m[1] * static_cast<T>(a.m[0])
|
result.m[1] = m[1] * static_cast<T>(a.m[0]) + m[4]
|
||||||
+ m[4] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[7] * static_cast<T>(a.m[2]);
|
||||||
+ m[7] * static_cast<T>(a.m[2]);
|
|
||||||
|
|
||||||
result.m[2] = m[2] * static_cast<T>(a.m[0])
|
result.m[2] = m[2] * static_cast<T>(a.m[0]) + m[5]
|
||||||
+ m[5] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[8] * static_cast<T>(a.m[2]);
|
||||||
+ m[8] * static_cast<T>(a.m[2]);
|
|
||||||
|
|
||||||
|
result.m[3] = m[0] * static_cast<T>(a.m[3]) + m[3]
|
||||||
|
* static_cast<T>(a.m[4]) + m[6] * static_cast<T>(a.m[5]);
|
||||||
|
|
||||||
result.m[3] = m[0] * static_cast<T>(a.m[3])
|
result.m[4] = m[1] * static_cast<T>(a.m[3]) + m[4]
|
||||||
+ m[3] * static_cast<T>(a.m[4])
|
* static_cast<T>(a.m[4]) + m[7] * static_cast<T>(a.m[5]);
|
||||||
+ m[6] * static_cast<T>(a.m[5]);
|
|
||||||
|
|
||||||
result.m[4] = m[1] * static_cast<T>(a.m[3])
|
result.m[5] = m[2] * static_cast<T>(a.m[3]) + m[5]
|
||||||
+ m[4] * static_cast<T>(a.m[4])
|
* static_cast<T>(a.m[4]) + m[8] * static_cast<T>(a.m[5]);
|
||||||
+ m[7] * static_cast<T>(a.m[5]);
|
|
||||||
|
|
||||||
result.m[5] = m[2] * static_cast<T>(a.m[3])
|
result.m[6] = m[0] * static_cast<T>(a.m[6]) + m[3]
|
||||||
+ m[5] * static_cast<T>(a.m[4])
|
* static_cast<T>(a.m[7]) + m[6] * static_cast<T>(a.m[8]);
|
||||||
+ m[8] * static_cast<T>(a.m[5]);
|
|
||||||
|
|
||||||
|
result.m[7] = m[1] * static_cast<T>(a.m[6]) + m[4]
|
||||||
|
* static_cast<T>(a.m[7]) + m[7] * static_cast<T>(a.m[8]);
|
||||||
|
|
||||||
result.m[6] = m[0] * static_cast<T>(a.m[6])
|
result.m[8] = m[2] * static_cast<T>(a.m[6]) + m[5]
|
||||||
+ m[3] * static_cast<T>(a.m[7])
|
* static_cast<T>(a.m[7]) + m[8] * static_cast<T>(a.m[8]);
|
||||||
+ m[6] * static_cast<T>(a.m[8]);
|
|
||||||
|
|
||||||
result.m[7] = m[1] * static_cast<T>(a.m[6])
|
|
||||||
+ m[4] * static_cast<T>(a.m[7])
|
|
||||||
+ m[7] * static_cast<T>(a.m[8]);
|
|
||||||
|
|
||||||
result.m[8] = m[2] * static_cast<T>(a.m[6])
|
|
||||||
+ m[5] * static_cast<T>(a.m[7])
|
|
||||||
+ m[8] * static_cast<T>(a.m[8]);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> Vector3Template<T> operator *(const Vector3Template<S>& a)
|
||||||
/**
|
|
||||||
* matrix vector multiplication
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
Vector3Template<T> operator * ( const Vector3Template<S>& a )
|
|
||||||
{
|
{
|
||||||
return Vector3Template<T>(
|
return Vector3Template<T>(m[0] * static_cast<T>(a.x) + m[3]
|
||||||
m[0] * static_cast<T>(a.x)
|
* static_cast<T>(a.y) + m[6] * static_cast<T>(a.z), m[1]
|
||||||
+ m[3] * static_cast<T>(a.y)
|
* static_cast<T>(a.x) + m[4] * static_cast<T>(a.y) + m[7]
|
||||||
+ m[6] * static_cast<T>(a.z),
|
* static_cast<T>(a.z), m[2] * static_cast<T>(a.x) + m[5]
|
||||||
m[1] * static_cast<T>(a.x)
|
* static_cast<T>(a.y) + m[8] * static_cast<T>(a.z) );
|
||||||
+ m[4] * static_cast<T>(a.y)
|
|
||||||
+ m[7] * static_cast<T>(a.z),
|
|
||||||
m[2] * static_cast<T>(a.x)
|
|
||||||
+ m[5] * static_cast<T>(a.y)
|
|
||||||
+ m[8] * static_cast<T>(a.z) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
template<class S> Matrix3x3Template<T> operator *(const S a)
|
||||||
* matrix scalar multiplication
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
Matrix3x3Template<T> operator * ( const S a )
|
|
||||||
{
|
{
|
||||||
Matrix3x3Template<T> result;
|
Matrix3x3Template<T> result;
|
||||||
|
|
||||||
@ -339,30 +270,72 @@ namespace BlueCore
|
|||||||
|
|
||||||
friend std::ostream &operator <<(std::ostream& os, Matrix3x3Template<T> m)
|
friend std::ostream &operator <<(std::ostream& os, Matrix3x3Template<T> m)
|
||||||
{
|
{
|
||||||
os << "( " << m.m[0] << ", " << m.m[1] << ", " << m.m[2] << " )" << std::endl;
|
os << "( " << m.m[0] << ", " << m.m[1] << ", " << m.m[2] << " )"
|
||||||
os << "( " << m.m[3] << ", " << m.m[4] << ", " << m.m[5] << " )" << std::endl;
|
<< std::endl;
|
||||||
os << "( " << m.m[6] << ", " << m.m[7] << ", " << m.m[8] << " )" << std::endl;
|
os << "( " << m.m[3] << ", " << m.m[4] << ", " << m.m[5] << " )"
|
||||||
|
<< std::endl;
|
||||||
|
os << "( " << m.m[6] << ", " << m.m[7] << ", " << m.m[8] << " )"
|
||||||
|
<< std::endl;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuaternionTemplate<T> toQuaternion() const
|
||||||
|
{
|
||||||
|
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
||||||
|
// article "Quaternion Calculus and Fast Animation".
|
||||||
|
|
||||||
|
T fTrace = m[0]+m[4]+m[8];
|
||||||
|
T fRoot;
|
||||||
|
QuaternionTemplate<T> q;
|
||||||
|
|
||||||
|
if (fTrace > 0.0)
|
||||||
|
{
|
||||||
|
// |w| > 1/2, may as well choose w > 1/2
|
||||||
|
fRoot = std::sqrt(fTrace + 1.0); // 2w
|
||||||
|
q.w = 0.5*fRoot;
|
||||||
|
fRoot = 0.5/fRoot; // 1/(4w)
|
||||||
|
q.x = (m[7]-m[5])*fRoot;
|
||||||
|
q.y = (m[2]-m[6])*fRoot;
|
||||||
|
q.z = (m[3]-m[1])*fRoot;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// |w| <= 1/2
|
||||||
|
static size_t s_iNext[3] =
|
||||||
|
{ 1, 2, 0 };
|
||||||
|
size_t i = 0;
|
||||||
|
if (m[4] > m[0])
|
||||||
|
i = 1;
|
||||||
|
if (m[8] > m[i*3+i])
|
||||||
|
i = 2;
|
||||||
|
size_t j = s_iNext[i];
|
||||||
|
size_t k = s_iNext[j];
|
||||||
|
|
||||||
|
fRoot = std::sqrt(m[i*3+i]-m[j*3+j]-m[k*k+1] + 1.0);
|
||||||
|
T* apkQuat[3] =
|
||||||
|
{ &q.x, &q.y, &q.z };
|
||||||
|
*apkQuat[i] = 0.5*fRoot;
|
||||||
|
fRoot = 0.5/fRoot;
|
||||||
|
q.w = (m[k*3+j]-m[j*3+k])*fRoot;
|
||||||
|
*apkQuat[j] = (m[j*3+i]+m[i*3+j])*fRoot;
|
||||||
|
*apkQuat[k] = (m[k*3+i]+m[i*3+k])*fRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
return q;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Matrix3x3Template<float> Matrix3x3Float;
|
typedef Matrix3x3Template<float> Matrix3x3Float;
|
||||||
typedef Matrix3x3Template<double> Matrix3x3Double;
|
typedef Matrix3x3Template<double> Matrix3x3Double;
|
||||||
typedef Matrix3x3Template<Scalar> Matrix3x3;
|
typedef Matrix3x3Template<Scalar> Matrix3x3;
|
||||||
|
|
||||||
|
template<class T> class Matrix4x4Template
|
||||||
template <class T>
|
|
||||||
class Matrix4x4Template
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
T m[16];
|
T m[16];
|
||||||
|
|
||||||
/**
|
|
||||||
* default constructor
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template()
|
inline Matrix4x4Template()
|
||||||
{
|
{
|
||||||
identity();
|
identity();
|
||||||
@ -391,21 +364,26 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor from array
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(const T a[16])
|
inline Matrix4x4Template(const T a[16])
|
||||||
{
|
{
|
||||||
m[0] = a[0]; m[1] = a[1]; m[2] = a[2]; m[3] = a[3];
|
m[0] = a[0];
|
||||||
m[4] = a[4]; m[5] = a[5]; m[6] = a[6]; m[7] = a[7];
|
m[1] = a[1];
|
||||||
m[8] = a[8]; m[9] = a[9]; m[10] = a[10]; m[11] = a[11];
|
m[2] = a[2];
|
||||||
m[12] = a[12]; m[13] = a[13]; m[14] = a[14]; m[15] = a[15];
|
m[3] = a[3];
|
||||||
|
m[4] = a[4];
|
||||||
|
m[5] = a[5];
|
||||||
|
m[6] = a[6];
|
||||||
|
m[7] = a[7];
|
||||||
|
m[8] = a[8];
|
||||||
|
m[9] = a[9];
|
||||||
|
m[10] = a[10];
|
||||||
|
m[11] = a[11];
|
||||||
|
m[12] = a[12];
|
||||||
|
m[13] = a[13];
|
||||||
|
m[14] = a[14];
|
||||||
|
m[15] = a[15];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor from 3x3 matrix, add. element are set to zero
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(const Matrix3x3Template<T> &a)
|
inline Matrix4x4Template(const Matrix3x3Template<T> &a)
|
||||||
{
|
{
|
||||||
m[0] = a[0];
|
m[0] = a[0];
|
||||||
@ -429,11 +407,7 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
inline Matrix4x4Template(const Matrix3x3Template<T> &a,
|
||||||
* constructor from 3x3 rotation matrix and translation vector
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(
|
|
||||||
const Matrix3x3Template<T> &a,
|
|
||||||
const Vector3Template<T> &b)
|
const Vector3Template<T> &b)
|
||||||
{
|
{
|
||||||
m[0] = a[0];
|
m[0] = a[0];
|
||||||
@ -457,10 +431,6 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* copy constructor
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(const Matrix4x4Template<T> &a)
|
inline Matrix4x4Template(const Matrix4x4Template<T> &a)
|
||||||
{
|
{
|
||||||
m[0] = a.m[0];
|
m[0] = a.m[0];
|
||||||
@ -484,10 +454,6 @@ namespace BlueCore
|
|||||||
m[15] = a.m[15];
|
m[15] = a.m[15];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor from quaternion
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(const QuaternionTemplate<T> &q)
|
inline Matrix4x4Template(const QuaternionTemplate<T> &q)
|
||||||
{
|
{
|
||||||
m[0] = 1 - 2*q.y*q.y - 2*q.z*q.z;
|
m[0] = 1 - 2*q.y*q.y - 2*q.z*q.z;
|
||||||
@ -511,12 +477,7 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Matrix4x4Template(const QuaternionTemplate<T> &q,
|
||||||
/**
|
|
||||||
* constructor from quaternion and translation vector
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(
|
|
||||||
const QuaternionTemplate<T> &q,
|
|
||||||
const Vector3Template<T> &a)
|
const Vector3Template<T> &a)
|
||||||
{
|
{
|
||||||
m[0] = 1 - 2*q.y*q.y - 2*q.z*q.z;
|
m[0] = 1 - 2*q.y*q.y - 2*q.z*q.z;
|
||||||
@ -540,14 +501,8 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Matrix4x4Template(const Vector3Template<T> &h,
|
||||||
/**
|
const Vector3Template<T> &u, const Vector3Template<T> &t)
|
||||||
* constructor from heading, up and translation vectors
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(
|
|
||||||
const Vector3Template<T> &h,
|
|
||||||
const Vector3Template<T> &u,
|
|
||||||
const Vector3Template<T> &t )
|
|
||||||
{
|
{
|
||||||
Vector3Template<T> a, b, c;
|
Vector3Template<T> a, b, c;
|
||||||
c = h.unit();
|
c = h.unit();
|
||||||
@ -575,15 +530,7 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Matrix4x4Template(T a, T e, T t, const Vector3Template<T> &tr)
|
||||||
/**
|
|
||||||
* contructor from euler angles
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template(
|
|
||||||
T a,
|
|
||||||
T e,
|
|
||||||
T t,
|
|
||||||
const Vector3Template<T> &tr )
|
|
||||||
{
|
{
|
||||||
T ch = cos(a);
|
T ch = cos(a);
|
||||||
T sh = sin(a);
|
T sh = sin(a);
|
||||||
@ -602,7 +549,6 @@ namespace BlueCore
|
|||||||
m[6] = -ca*sb;
|
m[6] = -ca*sb;
|
||||||
m[7] = static_cast<T>(0);
|
m[7] = static_cast<T>(0);
|
||||||
|
|
||||||
|
|
||||||
m[8] = -sh*ca;
|
m[8] = -sh*ca;
|
||||||
m[9] = sh*sa*cb + ch*sb;
|
m[9] = sh*sa*cb + ch*sb;
|
||||||
m[10] = -sh*sa*sb + ch*cb;
|
m[10] = -sh*sa*sb + ch*cb;
|
||||||
@ -614,10 +560,6 @@ namespace BlueCore
|
|||||||
m[15] = static_cast<T>(1);
|
m[15] = static_cast<T>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* transpose this matrix
|
|
||||||
*/
|
|
||||||
inline void transpose()
|
inline void transpose()
|
||||||
{
|
{
|
||||||
std::swap(m[4], m[1]);
|
std::swap(m[4], m[1]);
|
||||||
@ -629,217 +571,102 @@ namespace BlueCore
|
|||||||
std::swap(m[14], m[11]);
|
std::swap(m[14], m[11]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get transposed matrix
|
|
||||||
*/
|
|
||||||
inline Matrix4x4Template<T> transposed()
|
inline Matrix4x4Template<T> transposed()
|
||||||
{
|
{
|
||||||
Matrix4x4Template<T> a;
|
Matrix4x4Template<T> a;
|
||||||
|
|
||||||
a.m[0] = m[0]; a.m[4] = m[1]; a.m[8] = m[2]; a.m[12] = m[3];
|
a.m[0] = m[0];
|
||||||
a.m[1] = m[4]; a.m[5] = m[5]; a.m[9] = m[6]; a.m[13] = m[7];
|
a.m[4] = m[1];
|
||||||
a.m[2] = m[8]; a.m[6] = m[9]; a.m[10] = m[10]; a.m[14] = m[11];
|
a.m[8] = m[2];
|
||||||
a.m[3] = m[12]; a.m[7] = m[13]; a.m[11] = m[14]; a.m[15] = m[15];
|
a.m[12] = m[3];
|
||||||
|
a.m[1] = m[4];
|
||||||
|
a.m[5] = m[5];
|
||||||
|
a.m[9] = m[6];
|
||||||
|
a.m[13] = m[7];
|
||||||
|
a.m[2] = m[8];
|
||||||
|
a.m[6] = m[9];
|
||||||
|
a.m[10] = m[10];
|
||||||
|
a.m[14] = m[11];
|
||||||
|
a.m[3] = m[12];
|
||||||
|
a.m[7] = m[13];
|
||||||
|
a.m[11] = m[14];
|
||||||
|
a.m[15] = m[15];
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Matrix4x4Template<T> operator *(
|
||||||
/**
|
const Matrix4x4Template<S> &a)
|
||||||
* matrix multiplication
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Matrix4x4Template<T> operator * ( const Matrix4x4Template<S> &a )
|
|
||||||
{
|
{
|
||||||
Matrix4x4Template<T> result;
|
Matrix4x4Template<T> result;
|
||||||
|
|
||||||
result.m[0] = m[0] * static_cast<T>(a.m[0])
|
result.m[0] = m[0] * static_cast<T>(a.m[0]) + m[4]
|
||||||
+ m[4] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[8] * static_cast<T>(a.m[2])
|
||||||
+ m[8] * static_cast<T>(a.m[2])
|
|
||||||
+ m[12] * static_cast<T>(a.m[3]);
|
+ m[12] * static_cast<T>(a.m[3]);
|
||||||
|
|
||||||
result.m[1] = m[1] * static_cast<T>(a.m[0])
|
result.m[1] = m[1] * static_cast<T>(a.m[0]) + m[5]
|
||||||
+ m[5] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[9] * static_cast<T>(a.m[2])
|
||||||
+ m[9] * static_cast<T>(a.m[2])
|
|
||||||
+ m[13] * static_cast<T>(a.m[3]);
|
+ m[13] * static_cast<T>(a.m[3]);
|
||||||
|
|
||||||
result.m[2] = m[2] * static_cast<T>(a.m[0])
|
result.m[2] = m[2] * static_cast<T>(a.m[0]) + m[6]
|
||||||
+ m[6] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[10] * static_cast<T>(a.m[2])
|
||||||
+ m[10] * static_cast<T>(a.m[2])
|
|
||||||
+ m[14] * static_cast<T>(a.m[3]);
|
+ m[14] * static_cast<T>(a.m[3]);
|
||||||
|
|
||||||
result.m[3] = m[3] * static_cast<T>(a.m[0])
|
result.m[3] = m[3] * static_cast<T>(a.m[0]) + m[7]
|
||||||
+ m[7] * static_cast<T>(a.m[1])
|
* static_cast<T>(a.m[1]) + m[11] * static_cast<T>(a.m[2])
|
||||||
+ m[11] * static_cast<T>(a.m[2])
|
|
||||||
+ m[15] * static_cast<T>(a.m[3]);
|
+ m[15] * static_cast<T>(a.m[3]);
|
||||||
|
|
||||||
|
result.m[4] = m[0] * static_cast<T>(a.m[4]) + m[4]
|
||||||
result.m[4] = m[0] * static_cast<T>(a.m[4])
|
* static_cast<T>(a.m[5]) + m[8] * static_cast<T>(a.m[6])
|
||||||
+ m[4] * static_cast<T>(a.m[5])
|
|
||||||
+ m[8] * static_cast<T>(a.m[6])
|
|
||||||
+ m[12] * static_cast<T>(a.m[7]);
|
+ m[12] * static_cast<T>(a.m[7]);
|
||||||
|
|
||||||
result.m[5] = m[1] * static_cast<T>(a.m[4])
|
result.m[5] = m[1] * static_cast<T>(a.m[4]) + m[5]
|
||||||
+ m[5] * static_cast<T>(a.m[5])
|
* static_cast<T>(a.m[5]) + m[9] * static_cast<T>(a.m[6])
|
||||||
+ m[9] * static_cast<T>(a.m[6])
|
|
||||||
+ m[13] * static_cast<T>(a.m[7]);
|
+ m[13] * static_cast<T>(a.m[7]);
|
||||||
|
|
||||||
result.m[6] = m[2] * static_cast<T>(a.m[4])
|
result.m[6] = m[2] * static_cast<T>(a.m[4]) + m[6]
|
||||||
+ m[6] * static_cast<T>(a.m[5])
|
* static_cast<T>(a.m[5]) + m[10] * static_cast<T>(a.m[6])
|
||||||
+ m[10] * static_cast<T>(a.m[6])
|
|
||||||
+ m[14] * static_cast<T>(a.m[7]);
|
+ m[14] * static_cast<T>(a.m[7]);
|
||||||
|
|
||||||
result.m[7] = m[3] * static_cast<T>(a.m[4])
|
result.m[7] = m[3] * static_cast<T>(a.m[4]) + m[7]
|
||||||
+ m[7] * static_cast<T>(a.m[5])
|
* static_cast<T>(a.m[5]) + m[11] * static_cast<T>(a.m[6])
|
||||||
+ m[11] * static_cast<T>(a.m[6])
|
|
||||||
+ m[15] * static_cast<T>(a.m[7]);
|
+ m[15] * static_cast<T>(a.m[7]);
|
||||||
|
|
||||||
|
result.m[8] = m[0] * static_cast<T>(a.m[8]) + m[4]
|
||||||
result.m[8] = m[0] * static_cast<T>(a.m[8])
|
* static_cast<T>(a.m[9]) + m[8] * static_cast<T>(a.m[10])
|
||||||
+ m[4] * static_cast<T>(a.m[9])
|
|
||||||
+ m[8] * static_cast<T>(a.m[10])
|
|
||||||
+ m[12] * static_cast<T>(a.m[11]);
|
+ m[12] * static_cast<T>(a.m[11]);
|
||||||
|
|
||||||
result.m[9] = m[1] * static_cast<T>(a.m[8])
|
result.m[9] = m[1] * static_cast<T>(a.m[8]) + m[5]
|
||||||
+ m[5] * static_cast<T>(a.m[9])
|
* static_cast<T>(a.m[9]) + m[9] * static_cast<T>(a.m[10])
|
||||||
+ m[9] * static_cast<T>(a.m[10])
|
|
||||||
+ m[13] * static_cast<T>(a.m[11]);
|
+ m[13] * static_cast<T>(a.m[11]);
|
||||||
|
|
||||||
result.m[10] = m[2] * static_cast<T>(a.m[8])
|
result.m[10] = m[2] * static_cast<T>(a.m[8]) + m[6]
|
||||||
+ m[6] * static_cast<T>(a.m[9])
|
* static_cast<T>(a.m[9]) + m[10] * static_cast<T>(a.m[10])
|
||||||
+ m[10] * static_cast<T>(a.m[10])
|
|
||||||
+ m[14] * static_cast<T>(a.m[11]);
|
+ m[14] * static_cast<T>(a.m[11]);
|
||||||
|
|
||||||
result.m[11] = m[3] * static_cast<T>(a.m[8])
|
result.m[11] = m[3] * static_cast<T>(a.m[8]) + m[7]
|
||||||
+ m[7] * static_cast<T>(a.m[9])
|
* static_cast<T>(a.m[9]) + m[11] * static_cast<T>(a.m[10])
|
||||||
+ m[11] * static_cast<T>(a.m[10])
|
|
||||||
+ m[15] * static_cast<T>(a.m[11]);
|
+ m[15] * static_cast<T>(a.m[11]);
|
||||||
|
|
||||||
|
result.m[12] = m[0] * static_cast<T>(a.m[12]) + m[4]
|
||||||
result.m[12] = m[0] * static_cast<T>(a.m[12])
|
* static_cast<T>(a.m[13]) + m[8] * static_cast<T>(a.m[14])
|
||||||
+ m[4] * static_cast<T>(a.m[13])
|
|
||||||
+ m[8] * static_cast<T>(a.m[14])
|
|
||||||
+ m[12] * static_cast<T>(a.m[15]);
|
+ m[12] * static_cast<T>(a.m[15]);
|
||||||
|
|
||||||
result.m[13] = m[1] * static_cast<T>(a.m[12])
|
result.m[13] = m[1] * static_cast<T>(a.m[12]) + m[5]
|
||||||
+ m[5] * static_cast<T>(a.m[13])
|
* static_cast<T>(a.m[13]) + m[9] * static_cast<T>(a.m[14])
|
||||||
+ m[9] * static_cast<T>(a.m[14])
|
|
||||||
+ m[13] * static_cast<T>(a.m[15]);
|
+ m[13] * static_cast<T>(a.m[15]);
|
||||||
|
|
||||||
result.m[14] = m[2] * static_cast<T>(a.m[12])
|
result.m[14] = m[2] * static_cast<T>(a.m[12]) + m[6]
|
||||||
+ m[6] * static_cast<T>(a.m[13])
|
* static_cast<T>(a.m[13]) + m[10] * static_cast<T>(a.m[14])
|
||||||
+ m[10] * static_cast<T>(a.m[14])
|
|
||||||
+ m[14] * static_cast<T>(a.m[15]);
|
+ m[14] * static_cast<T>(a.m[15]);
|
||||||
|
|
||||||
result.m[15] = m[3] * static_cast<T>(a.m[12])
|
result.m[15] = m[3] * static_cast<T>(a.m[12]) + m[7]
|
||||||
+ m[7] * static_cast<T>(a.m[13])
|
* static_cast<T>(a.m[13]) + m[11] * static_cast<T>(a.m[14])
|
||||||
+ m[11] * static_cast<T>(a.m[14])
|
|
||||||
+ m[15] * static_cast<T>(a.m[15]);
|
+ m[15] * static_cast<T>(a.m[15]);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* matrix multiplication
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
template <class S>
|
|
||||||
inline Matrix4x4Template<T> operator *= ( const Matrix4x4Template<S> &a )
|
|
||||||
{
|
|
||||||
Matrix4x4Template<T> result;
|
|
||||||
|
|
||||||
result.m[0] = m[0] * static_cast<T>(a.m[0])
|
|
||||||
+ m[4] * static_cast<T>(a.m[1])
|
|
||||||
+ m[8] * static_cast<T>(a.m[2]);
|
|
||||||
+ m[12] * static_cast<T>(a.m[3]);
|
|
||||||
|
|
||||||
result.m[1] = m[1] * static_cast<T>(a.m[0])
|
|
||||||
+ m[5] * static_cast<T>(a.m[1])
|
|
||||||
+ m[9] * static_cast<T>(a.m[2]);
|
|
||||||
+ m[13] * static_cast<T>(a.m[3]);
|
|
||||||
|
|
||||||
result.m[2] = m[2] * static_cast<T>(a.m[0])
|
|
||||||
+ m[6] * static_cast<T>(a.m[1])
|
|
||||||
+ m[10] * static_cast<T>(a.m[2]);
|
|
||||||
+ m[14] * static_cast<T>(a.m[3]);
|
|
||||||
|
|
||||||
result.m[3] = m[3] * static_cast<T>(a.m[0])
|
|
||||||
+ m[7] * static_cast<T>(a.m[1])
|
|
||||||
+ m[11] * static_cast<T>(a.m[2]);
|
|
||||||
+ m[15] * static_cast<T>(a.m[3]);
|
|
||||||
|
|
||||||
|
|
||||||
result.m[4] = m[0] * static_cast<T>(a.m[4])
|
|
||||||
+ m[4] * static_cast<T>(a.m[5])
|
|
||||||
+ m[8] * static_cast<T>(a.m[6]);
|
|
||||||
+ m[12] * static_cast<T>(a.m[7]);
|
|
||||||
|
|
||||||
result.m[5] = m[1] * static_cast<T>(a.m[4])
|
|
||||||
+ m[5] * static_cast<T>(a.m[5])
|
|
||||||
+ m[9] * static_cast<T>(a.m[6]);
|
|
||||||
+ m[13] * static_cast<T>(a.m[7]);
|
|
||||||
|
|
||||||
result.m[6] = m[2] * static_cast<T>(a.m[4])
|
|
||||||
+ m[6] * static_cast<T>(a.m[5])
|
|
||||||
+ m[10] * static_cast<T>(a.m[6]);
|
|
||||||
+ m[14] * static_cast<T>(a.m[7]);
|
|
||||||
|
|
||||||
result.m[7] = m[3] * static_cast<T>(a.m[4])
|
|
||||||
+ m[7] * static_cast<T>(a.m[5])
|
|
||||||
+ m[11] * static_cast<T>(a.m[6]);
|
|
||||||
+ m[15] * static_cast<T>(a.m[7]);
|
|
||||||
|
|
||||||
|
|
||||||
result.m[8] = m[0] * static_cast<T>(a.m[8])
|
|
||||||
+ m[4] * static_cast<T>(a.m[9])
|
|
||||||
+ m[8] * static_cast<T>(a.m[10]);
|
|
||||||
+ m[12] * static_cast<T>(a.m[11]);
|
|
||||||
|
|
||||||
result.m[9] = m[1] * static_cast<T>(a.m[8])
|
|
||||||
+ m[5] * static_cast<T>(a.m[9])
|
|
||||||
+ m[9] * static_cast<T>(a.m[10]);
|
|
||||||
+ m[13] * static_cast<T>(a.m[11]);
|
|
||||||
|
|
||||||
result.m[10] = m[2] * static_cast<T>(a.m[8])
|
|
||||||
+ m[6] * static_cast<T>(a.m[9])
|
|
||||||
+ m[10] * static_cast<T>(a.m[10]);
|
|
||||||
+ m[14] * static_cast<T>(a.m[11]);
|
|
||||||
|
|
||||||
result.m[11] = m[3] * static_cast<T>(a.m[8])
|
|
||||||
+ m[7] * static_cast<T>(a.m[9])
|
|
||||||
+ m[11] * static_cast<T>(a.m[10]);
|
|
||||||
+ m[15] * static_cast<T>(a.m[11]);
|
|
||||||
|
|
||||||
|
|
||||||
result.m[12] = m[0] * static_cast<T>(a.m[12])
|
|
||||||
+ m[4] * static_cast<T>(a.m[13])
|
|
||||||
+ m[8] * static_cast<T>(a.m[14]);
|
|
||||||
+ m[12] * static_cast<T>(a.m[15]);
|
|
||||||
|
|
||||||
result.m[13] = m[1] * static_cast<T>(a.m[12])
|
|
||||||
+ m[5] * static_cast<T>(a.m[13])
|
|
||||||
+ m[9] * static_cast<T>(a.m[14]);
|
|
||||||
+ m[13] * static_cast<T>(a.m[15]);
|
|
||||||
|
|
||||||
result.m[14] = m[2] * static_cast<T>(a.m[12])
|
|
||||||
+ m[6] * static_cast<T>(a.m[13])
|
|
||||||
+ m[10] * static_cast<T>(a.m[14]);
|
|
||||||
+ m[14] * static_cast<T>(a.m[15]);
|
|
||||||
|
|
||||||
result.m[15] = m[3] * static_cast<T>(a.m[12])
|
|
||||||
+ m[7] * static_cast<T>(a.m[13])
|
|
||||||
+ m[11] * static_cast<T>(a.m[14]);
|
|
||||||
+ m[15] * static_cast<T>(a.m[15]);
|
|
||||||
|
|
||||||
m = result.m;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* matrix vector multiplication
|
|
||||||
*/
|
|
||||||
Vector3Template<T> operator *(const Vector3Template<T> &a)
|
Vector3Template<T> operator *(const Vector3Template<T> &a)
|
||||||
{
|
{
|
||||||
Vector3Template<T> result;
|
Vector3Template<T> result;
|
||||||
|
@ -5,16 +5,11 @@
|
|||||||
|
|
||||||
namespace BlueCore
|
namespace BlueCore
|
||||||
{
|
{
|
||||||
template <class T>
|
template<class T> class QuaternionTemplate
|
||||||
class QuaternionTemplate
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
T w, x, y, z;
|
T w, x, y, z;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor
|
|
||||||
*/
|
|
||||||
inline QuaternionTemplate()
|
inline QuaternionTemplate()
|
||||||
{
|
{
|
||||||
w = static_cast<T>(1.0);
|
w = static_cast<T>(1.0);
|
||||||
@ -23,12 +18,7 @@ namespace BlueCore
|
|||||||
z = static_cast<T>(0.0);
|
z = static_cast<T>(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate(S w, S x, S y, S z)
|
||||||
/**
|
|
||||||
* contructor
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate( S w, S x, S y, S z )
|
|
||||||
{
|
{
|
||||||
this->w = static_cast<T>(w);
|
this->w = static_cast<T>(w);
|
||||||
this->x = static_cast<T>(x);
|
this->x = static_cast<T>(x);
|
||||||
@ -36,12 +26,7 @@ namespace BlueCore
|
|||||||
this->z = static_cast<T>(z);
|
this->z = static_cast<T>(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate(Vector3Template<S> axis, S angle)
|
||||||
/**
|
|
||||||
* contructor
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate( Vector3Template<S> axis, S angle )
|
|
||||||
{
|
{
|
||||||
T half_angle = static_cast<T>(angle)/static_cast<T>(2.0);
|
T half_angle = static_cast<T>(angle)/static_cast<T>(2.0);
|
||||||
T sin_half_angle = static_cast<T>(sin(half_angle) );
|
T sin_half_angle = static_cast<T>(sin(half_angle) );
|
||||||
@ -52,12 +37,7 @@ namespace BlueCore
|
|||||||
z = sin_half_angle * static_cast<T>(axis.z);
|
z = sin_half_angle * static_cast<T>(axis.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate(S h, S a, S b)
|
||||||
/**
|
|
||||||
* contructor
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate( S h, S a, S b )
|
|
||||||
{
|
{
|
||||||
T c1 = static_cast<T>(cos(h / 2.0) );
|
T c1 = static_cast<T>(cos(h / 2.0) );
|
||||||
T c2 = static_cast<T>(cos(a / 2.0) );
|
T c2 = static_cast<T>(cos(a / 2.0) );
|
||||||
@ -72,10 +52,6 @@ namespace BlueCore
|
|||||||
z = c1 * s2 * c3 - s1 * c2 * s3;
|
z = c1 * s2 * c3 - s1 * c2 * s3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* identity
|
|
||||||
*/
|
|
||||||
inline void identity()
|
inline void identity()
|
||||||
{
|
{
|
||||||
w = static_cast<T>(1.0);
|
w = static_cast<T>(1.0);
|
||||||
@ -84,27 +60,15 @@ namespace BlueCore
|
|||||||
z = static_cast<T>(0.0);
|
z = static_cast<T>(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> operator +(
|
||||||
/**
|
|
||||||
* operator +
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> operator + (
|
|
||||||
const QuaternionTemplate<S> &a) const
|
const QuaternionTemplate<S> &a) const
|
||||||
{
|
{
|
||||||
return QuaternionTemplate<T>(
|
return QuaternionTemplate<T>(w + static_cast<T>(a.w), x
|
||||||
w + static_cast<T>(a.w),
|
+ static_cast<T>(a.x), y + static_cast<T>(a.y), z
|
||||||
x + static_cast<T>(a.x),
|
+ static_cast<T>(a.z) );
|
||||||
y + static_cast<T>(a.y),
|
|
||||||
z + static_cast<T>(a.z) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> &operator +=(
|
||||||
/**
|
|
||||||
* operator +=
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> &operator += (
|
|
||||||
const QuaternionTemplate<S> &a)
|
const QuaternionTemplate<S> &a)
|
||||||
{
|
{
|
||||||
w += static_cast<T>(a.w);
|
w += static_cast<T>(a.w);
|
||||||
@ -115,74 +79,44 @@ namespace BlueCore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> operator -(
|
||||||
/**
|
|
||||||
* operator -
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> operator - (
|
|
||||||
const QuaternionTemplate<S> &a) const
|
const QuaternionTemplate<S> &a) const
|
||||||
{
|
{
|
||||||
return QuaternionTemplate<T>(
|
return QuaternionTemplate<T>(w - static_cast<T>(a.w), x
|
||||||
w - static_cast<T>(a.w),
|
- static_cast<T>(a.x), y - static_cast<T>(a.y), z
|
||||||
x - static_cast<T>(a.x),
|
- static_cast<T>(a.z) );
|
||||||
y - static_cast<T>(a.y),
|
|
||||||
z - static_cast<T>(a.z) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> operator *(
|
||||||
/**
|
|
||||||
* operator *
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> operator * (
|
|
||||||
const QuaternionTemplate<S> &a) const
|
const QuaternionTemplate<S> &a) const
|
||||||
{
|
{
|
||||||
return QuaternionTemplate<T>(
|
return QuaternionTemplate<T>(w * static_cast<T>(a.w) - x
|
||||||
w * static_cast<T>(a.w) -
|
* static_cast<T>(a.x) - y * static_cast<T>(a.y) - z
|
||||||
x * static_cast<T>(a.x) -
|
* static_cast<T>(a.z), w * static_cast<T>(a.x) + x
|
||||||
y * static_cast<T>(a.y) -
|
* static_cast<T>(a.w) + y * static_cast<T>(a.z) - z
|
||||||
z * static_cast<T>(a.z),
|
* static_cast<T>(a.y), w * static_cast<T>(a.y) - x
|
||||||
w * static_cast<T>(a.x) +
|
* static_cast<T>(a.z) + y * static_cast<T>(a.w) + z
|
||||||
x * static_cast<T>(a.w) +
|
* static_cast<T>(a.x), w * static_cast<T>(a.z) + x
|
||||||
y * static_cast<T>(a.z) -
|
* static_cast<T>(a.y) - y * static_cast<T>(a.x) + z
|
||||||
z * static_cast<T>(a.y),
|
* static_cast<T>(a.w) );
|
||||||
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) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> &operator *=(
|
||||||
/**
|
|
||||||
* operator *=
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> &operator *=(
|
|
||||||
const QuaternionTemplate<S> &a)
|
const QuaternionTemplate<S> &a)
|
||||||
{
|
{
|
||||||
w = w * static_cast<T>(a.w) - x * static_cast<T>(a.x) -
|
w = w * static_cast<T>(a.w) - x * static_cast<T>(a.x) - y
|
||||||
y * static_cast<T>(a.y) - z * static_cast<T>(a.z);
|
* static_cast<T>(a.y) - z * static_cast<T>(a.z);
|
||||||
x = w * static_cast<T>(a.x) + x * static_cast<T>(a.w) +
|
x = w * static_cast<T>(a.x) + x * static_cast<T>(a.w) + y
|
||||||
y * static_cast<T>(a.z) - z * static_cast<T>(a.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 = w * static_cast<T>(a.y) - x * static_cast<T>(a.z) + y
|
||||||
y * static_cast<T>(a.w) + z * static_cast<T>(a.x);
|
* static_cast<T>(a.w) + z * static_cast<T>(a.x);
|
||||||
z = w * static_cast<T>(a.z) + x * static_cast<T>(a.y) -
|
z = w * static_cast<T>(a.z) + x * static_cast<T>(a.y) - y
|
||||||
y * static_cast<T>(a.x) + z * static_cast<T>(a.w);
|
* static_cast<T>(a.x) + z * static_cast<T>(a.w);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> &operator -=(
|
||||||
/**
|
|
||||||
* operator -=
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> &operator -= (
|
|
||||||
const QuaternionTemplate<S> &a)
|
const QuaternionTemplate<S> &a)
|
||||||
{
|
{
|
||||||
w -= static_cast<T>(a.w);
|
w -= static_cast<T>(a.w);
|
||||||
@ -193,12 +127,7 @@ namespace BlueCore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline QuaternionTemplate<T> &operator =(
|
||||||
/**
|
|
||||||
* operator =
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline QuaternionTemplate<T> &operator = (
|
|
||||||
const QuaternionTemplate<S> &a)
|
const QuaternionTemplate<S> &a)
|
||||||
{
|
{
|
||||||
w = static_cast<T>(a.w);
|
w = static_cast<T>(a.w);
|
||||||
@ -209,28 +138,17 @@ namespace BlueCore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* unit
|
|
||||||
*/
|
|
||||||
inline QuaternionTemplate<T> unit() const
|
inline QuaternionTemplate<T> unit() const
|
||||||
{
|
{
|
||||||
T d = 1/sqrt(w*w + x*x + y*y + z*z);
|
T d = 1/sqrt(w*w + x*x + y*y + z*z);
|
||||||
return QuaternionTemplate<T>(w * d, x * d, y * d, z * d);
|
return QuaternionTemplate<T>(w * d, x * d, y * d, z * d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* inversed
|
|
||||||
*/
|
|
||||||
inline QuaternionTemplate<T> inversed() const
|
inline QuaternionTemplate<T> inversed() const
|
||||||
{
|
{
|
||||||
return QuaternionTemplate<T>(w, -x, -y, -z);
|
return QuaternionTemplate<T>(w, -x, -y, -z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* inversed
|
|
||||||
*/
|
|
||||||
inline void inverse()
|
inline void inverse()
|
||||||
{
|
{
|
||||||
x = -x;
|
x = -x;
|
||||||
@ -238,10 +156,6 @@ namespace BlueCore
|
|||||||
z = -z;
|
z = -z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* normalize
|
|
||||||
*/
|
|
||||||
inline QuaternionTemplate<T> &normalize()
|
inline QuaternionTemplate<T> &normalize()
|
||||||
{
|
{
|
||||||
T d = 1/sqrt(w*w + x*x + y*y + z*z);
|
T d = 1/sqrt(w*w + x*x + y*y + z*z);
|
||||||
@ -253,106 +167,64 @@ namespace BlueCore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline const Vector3Template<T> apply(
|
||||||
/**
|
|
||||||
* apply
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline const Vector3Template<T> apply(
|
|
||||||
const Vector3Template<S> &a) const
|
const Vector3Template<S> &a) const
|
||||||
{
|
{
|
||||||
T xx = x*x, xy = x*y, xz = x*z, xw = x*w,
|
T xx = x*x, xy = x*y, xz = x*z, xw = x*w, yy = y*y, yz = y*z, yw = y*w,
|
||||||
yy = y*y, yz = y*z, yw = y*w,
|
|
||||||
zz = z*z, zw = z*w;
|
zz = z*z, zw = z*w;
|
||||||
|
|
||||||
return Vector3Template<T>(
|
return Vector3Template<T>( 2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy
|
||||||
2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy - zz ) +
|
- zz ) + static_cast<T>(a.y) * (xy - zw ) + static_cast<T>(a.z)
|
||||||
static_cast<T>(a.y) * ( xy - zw ) +
|
* (xz + yw ) ),
|
||||||
static_cast<T>(a.z) * ( xz + yw ) ),
|
|
||||||
|
|
||||||
2.0 * ( static_cast<T>(a.x) * ( xy + zw ) +
|
2.0 * ( static_cast<T>(a.x) * (xy + zw ) + static_cast<T>(a.y) * ( 0.5
|
||||||
static_cast<T>(a.y) * ( 0.5 - xx - zz ) +
|
- xx - zz ) + static_cast<T>(a.z) * (yz - xw ) ),
|
||||||
static_cast<T>(a.z) * ( yz - xw ) ),
|
|
||||||
|
|
||||||
2.0 * ( static_cast<T>(a.x) * ( xz - yw ) +
|
2.0 * ( static_cast<T>(a.x) * (xz - yw ) + static_cast<T>(a.y) * (yz
|
||||||
static_cast<T>(a.y) * ( yz + xw ) +
|
+ xw ) + static_cast<T>(a.z) * ( 0.5 - xx - yy ) ));
|
||||||
static_cast<T>(a.z) * ( 0.5 - xx - yy ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline const Vector3Template<T> operator *(
|
||||||
/**
|
|
||||||
* apply
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline const Vector3Template<T> operator * (
|
|
||||||
const Vector3Template<S> &a) const
|
const Vector3Template<S> &a) const
|
||||||
{
|
{
|
||||||
T xx = x*x, xy = x*y, xz = x*z, xw = x*w,
|
T xx = x*x, xy = x*y, xz = x*z, xw = x*w, yy = y*y, yz = y*z, yw = y*w,
|
||||||
yy = y*y, yz = y*z, yw = y*w,
|
|
||||||
zz = z*z, zw = z*w;
|
zz = z*z, zw = z*w;
|
||||||
|
|
||||||
return Vector3Template<T>(
|
return Vector3Template<T>( 2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy
|
||||||
2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy - zz ) +
|
- zz ) + static_cast<T>(a.y) * (xy - zw ) + static_cast<T>(a.z)
|
||||||
static_cast<T>(a.y) * ( xy - zw ) +
|
* (xz + yw ) ),
|
||||||
static_cast<T>(a.z) * ( xz + yw ) ),
|
|
||||||
|
|
||||||
2.0 * ( static_cast<T>(a.x) * ( xy + zw ) +
|
2.0 * ( static_cast<T>(a.x) * (xy + zw ) + static_cast<T>(a.y) * ( 0.5
|
||||||
static_cast<T>(a.y) * ( 0.5 - xx - zz ) +
|
- xx - zz ) + static_cast<T>(a.z) * (yz - xw ) ),
|
||||||
static_cast<T>(a.z) * ( yz - xw ) ),
|
|
||||||
|
|
||||||
2.0 * ( static_cast<T>(a.x) * ( xz - yw ) +
|
2.0 * ( static_cast<T>(a.x) * (xz - yw ) + static_cast<T>(a.y) * (yz
|
||||||
static_cast<T>(a.y) * ( yz + xw ) +
|
+ xw ) + static_cast<T>(a.z) * ( 0.5 - xx - yy ) ));
|
||||||
static_cast<T>(a.z) * ( 0.5 - xx - yy ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class S> inline Vector3Template<T> applyInversed(
|
||||||
/**
|
|
||||||
* applyInversed
|
|
||||||
*/
|
|
||||||
template <class S>
|
|
||||||
inline Vector3Template<T> applyInversed(
|
|
||||||
const Vector3Template<S> &a) const
|
const Vector3Template<S> &a) const
|
||||||
{
|
{
|
||||||
T xx = x*x, xy = x*y, xz = x*z, xw = -x*w,
|
T xx = x*x, xy = x*y, xz = x*z, xw = -x*w, yy = y*y, yz = y*z, yw = -y
|
||||||
yy = y*y, yz = y*z, yw = -y*w,
|
*w, zz = z*z, zw = -z*w;
|
||||||
zz = z*z, zw = -z*w;
|
|
||||||
|
|
||||||
return Vector3Template<T>(
|
return Vector3Template<T>( 2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy
|
||||||
2.0 * ( static_cast<T>(a.x) * ( 0.5 - yy - zz ) +
|
- zz ) + static_cast<T>(a.y) * (xy - zw ) + static_cast<T>(a.z)
|
||||||
static_cast<T>(a.y) * ( xy - zw ) +
|
* (xz + yw ) ),
|
||||||
static_cast<T>(a.z) * ( xz + yw ) ),
|
|
||||||
|
|
||||||
2.0 * ( static_cast<T>(a.x) * ( xy + zw ) +
|
2.0 * ( static_cast<T>(a.x) * (xy + zw ) + static_cast<T>(a.y) * ( 0.5
|
||||||
static_cast<T>(a.y) * ( 0.5 - xx - zz ) +
|
- xx - zz ) + static_cast<T>(a.z) * (yz - xw ) ),
|
||||||
static_cast<T>(a.z) * ( yz - xw ) ),
|
|
||||||
|
|
||||||
2.0 * ( static_cast<T>(a.x) * ( xz - yw ) +
|
2.0 * ( static_cast<T>(a.x) * (xz - yw ) + static_cast<T>(a.y) * (yz
|
||||||
static_cast<T>(a.y) * ( yz + xw ) +
|
+ xw ) + static_cast<T>(a.z) * ( 0.5 - xx - yy ) ));
|
||||||
static_cast<T>(a.z) * ( 0.5 - xx - yy ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
inline QuaternionTemplate<T> slerp(const QuaternionTemplate<T> &q,
|
||||||
* transform from ode to gl coodinates
|
const Scalar &t)
|
||||||
*/
|
|
||||||
inline QuaternionTemplate<T> toGl() const
|
|
||||||
{
|
{
|
||||||
return QuaternionTemplate<T>( w, x, z, -y );
|
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;
|
||||||
* 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;
|
|
||||||
|
|
||||||
return QuaternionTemplate<T>(a*w+b*q.w, a*x+b*q.x, a*y+b*q.y, a*z+b*q.z);
|
return QuaternionTemplate<T>(a*w+b*q.w, a*x+b*q.x, a*y+b*q.y, a*z+b*q.z);
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,17 @@ namespace BlueCore
|
|||||||
void Model::render(RenderDevice *device) const
|
void Model::render(RenderDevice *device) const
|
||||||
{
|
{
|
||||||
ModelMesh->render();
|
ModelMesh->render();
|
||||||
//glEnable(GL_LIGHTING);
|
/*
|
||||||
//glDepthFunc ( GL_LEQUAL );
|
glEnable(GL_LIGHTING);
|
||||||
//glEnable ( GL_DEPTH_TEST );
|
glDepthFunc ( GL_LEQUAL );
|
||||||
//glDepthMask ( GL_TRUE );
|
glEnable ( GL_DEPTH_TEST );
|
||||||
|
glDepthMask ( GL_TRUE );
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
glEnableClientState (GL_VERTEX_ARRAY );
|
glEnableClientState (GL_VERTEX_ARRAY );
|
||||||
glEnableClientState (GL_TEXTURE_COORD_ARRAY );
|
glEnableClientState (GL_TEXTURE_COORD_ARRAY );
|
||||||
glEnableClientState (GL_NORMAL_ARRAY );
|
glEnableClientState (GL_NORMAL_ARRAY );
|
||||||
|
|
||||||
glMatrixMode (GL_MODELVIEW );
|
|
||||||
glPushMatrix();
|
|
||||||
Matrix4x4 m(_AbsoluteRotation, _AbsoluteTranslation);
|
|
||||||
glMultMatrixd ( ( GLdouble * ) &m.m );
|
|
||||||
|
|
||||||
mesh->vertex_buffer.bind();
|
mesh->vertex_buffer.bind();
|
||||||
mesh->index_buffer.bind();
|
mesh->index_buffer.bind();
|
||||||
*/
|
*/
|
||||||
|
@ -137,11 +137,13 @@ void RenderDevice::setupProjectionMatrix()
|
|||||||
void RenderDevice::setupViewMatrix()
|
void RenderDevice::setupViewMatrix()
|
||||||
{
|
{
|
||||||
if (_Camera.valid())
|
if (_Camera.valid())
|
||||||
|
{
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
Matrix4x4 m(_Camera->getRotation(), _Camera->getRotation().applyInversed(_Camera->getPosition() * -1.0) );
|
||||||
glMultMatrixd( ( GLdouble * ) &m.m );
|
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RenderDevice::pushTransformation(const Vector3& position,
|
void RenderDevice::pushTransformation(const Vector3& position,
|
||||||
const Quaternion& orientation)
|
const Quaternion& orientation)
|
||||||
|
@ -545,7 +545,6 @@ bool RigidBodySimulation::step()
|
|||||||
{
|
{
|
||||||
if (_steps > 0)
|
if (_steps > 0)
|
||||||
{
|
{
|
||||||
_ScriptSystem->callFunction("OnStep", _stepSize);
|
|
||||||
dSpaceCollide(_space, 0, &nearCallback);
|
dSpaceCollide(_space, 0, &nearCallback);
|
||||||
dWorldQuickStep(_world, _stepSize);
|
dWorldQuickStep(_world, _stepSize);
|
||||||
StepSignal(_stepSize);
|
StepSignal(_stepSize);
|
||||||
|
@ -25,7 +25,7 @@ namespace BlueCore
|
|||||||
{
|
{
|
||||||
class RigidBodySimulation;
|
class RigidBodySimulation;
|
||||||
|
|
||||||
class RigidBody
|
class RigidBody : public Referenced
|
||||||
{
|
{
|
||||||
Vector3 _Position;
|
Vector3 _Position;
|
||||||
Quaternion _Orientation;
|
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,10 +1,10 @@
|
|||||||
#include "SceneNode.h"
|
#include "SceneNode.h"
|
||||||
|
|
||||||
namespace BlueCore {
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
#define DEBUG_SCENEGRAPH
|
#define DEBUG_SCENEGRAPH
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
SceneNode::SceneNode() :
|
SceneNode::SceneNode() :
|
||||||
Named("unnamed SceneNode"), _Parent(0)
|
Named("unnamed SceneNode"), _Parent(0)
|
||||||
{
|
{
|
||||||
@ -13,7 +13,6 @@ SceneNode::SceneNode() :
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
SceneNode::SceneNode(const std::string &name) :
|
SceneNode::SceneNode(const std::string &name) :
|
||||||
Named(name), _Parent(0)
|
Named(name), _Parent(0)
|
||||||
{
|
{
|
||||||
@ -22,7 +21,6 @@ SceneNode::SceneNode(const std::string &name) :
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
SceneNode::~SceneNode()
|
SceneNode::~SceneNode()
|
||||||
{
|
{
|
||||||
detachAll();
|
detachAll();
|
||||||
@ -32,7 +30,6 @@ SceneNode::~SceneNode()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SceneNode::attach(SceneNode *node)
|
void SceneNode::attach(SceneNode *node)
|
||||||
{
|
{
|
||||||
if (node == 0)
|
if (node == 0)
|
||||||
@ -45,12 +42,12 @@ void SceneNode::attach(SceneNode *node)
|
|||||||
node->addReference();
|
node->addReference();
|
||||||
|
|
||||||
#ifdef DEBUG_SCENEGRAPH
|
#ifdef DEBUG_SCENEGRAPH
|
||||||
clog << "SceneNode '" << node->getName() << "' attached to '" << this->getName() << "'" << endline;
|
clog << "SceneNode '" << node->getName() << "' attached to '"
|
||||||
|
<< this->getName() << "'" << endline;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SceneNode::detach(SceneNode *node)
|
void SceneNode::detach(SceneNode *node)
|
||||||
{
|
{
|
||||||
node->_Parent = 0;
|
node->_Parent = 0;
|
||||||
@ -59,11 +56,11 @@ void SceneNode::detach(SceneNode *node)
|
|||||||
_Children.remove(node);
|
_Children.remove(node);
|
||||||
|
|
||||||
#ifdef DEBUG_SCENEGRAPH
|
#ifdef DEBUG_SCENEGRAPH
|
||||||
clog << "SceneNode '" << node->getName() << "' detach from '" << this->getName() << "'" << endline;
|
clog << "SceneNode '" << node->getName() << "' detach from '"
|
||||||
|
<< this->getName() << "'" << endline;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SceneNode::detachAll()
|
void SceneNode::detachAll()
|
||||||
{
|
{
|
||||||
SceneNodeList::iterator i;
|
SceneNodeList::iterator i;
|
||||||
@ -77,26 +74,22 @@ void SceneNode::detachAll()
|
|||||||
_Children.clear();
|
_Children.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
SceneNode *SceneNode::getParent() const
|
SceneNode *SceneNode::getParent() const
|
||||||
{
|
{
|
||||||
return _Parent;
|
return _Parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SceneNode::detachFromParent()
|
void SceneNode::detachFromParent()
|
||||||
{
|
{
|
||||||
if (_Parent)
|
if (_Parent)
|
||||||
_Parent->detach( this);
|
_Parent->detach( this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
const SceneNode::SceneNodeList& SceneNode::getChildren() const
|
const SceneNode::SceneNodeList& SceneNode::getChildren() const
|
||||||
{
|
{
|
||||||
return _Children;
|
return _Children;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SceneNode::update(Scalar time)
|
void SceneNode::update(Scalar time)
|
||||||
{
|
{
|
||||||
updateAbsoluteTransformation();
|
updateAbsoluteTransformation();
|
||||||
@ -110,8 +103,7 @@ void SceneNode::update(Scalar time)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void SceneNode::queue(RenderQueue *queue, Camera *camera)
|
||||||
void SceneNode::render(RenderDevice *device, Camera *camera)
|
|
||||||
{
|
{
|
||||||
if (isActive())
|
if (isActive())
|
||||||
{
|
{
|
||||||
@ -119,12 +111,11 @@ void SceneNode::render(RenderDevice *device, Camera *camera)
|
|||||||
|
|
||||||
for (i = _Children.begin(); i != _Children.end(); i++)
|
for (i = _Children.begin(); i != _Children.end(); i++)
|
||||||
{
|
{
|
||||||
( *i )->render(device, camera);
|
( *i )->queue(queue, camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
const Transformation& SceneNode::getRelativeTransformation()
|
const Transformation& SceneNode::getRelativeTransformation()
|
||||||
{
|
{
|
||||||
return _RelativeTransformation;
|
return _RelativeTransformation;
|
||||||
@ -135,19 +126,16 @@ const Transformation& SceneNode::getAbsoluteTransformation()
|
|||||||
return _AbsoluteTransformation;
|
return _AbsoluteTransformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void SceneNode::setRelativeTranslation(const Vector3 &translation)
|
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()
|
void SceneNode::updateAbsoluteTransformation()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
#define BLUECORE_SCENE_NODE_H
|
#define BLUECORE_SCENE_NODE_H
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "RenderDevice.h"
|
#include "RenderQueue.h"
|
||||||
|
#include "RigidBodySimulation.h"
|
||||||
|
#include "ModelManager.h"
|
||||||
|
|
||||||
#include "Utilities/Referenced.h"
|
#include "Utilities/Referenced.h"
|
||||||
#include "Utilities/Named.h"
|
#include "Utilities/Named.h"
|
||||||
@ -30,6 +32,9 @@ class SceneNode : public Referenced, public Named, public Activated
|
|||||||
Transformation _RelativeTransformation;
|
Transformation _RelativeTransformation;
|
||||||
Transformation _AbsoluteTransformation;
|
Transformation _AbsoluteTransformation;
|
||||||
|
|
||||||
|
weak_ptr<RigidBody> _RigidBody;
|
||||||
|
weak_ptr<Model> _Model;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SceneNode();
|
SceneNode();
|
||||||
@ -45,7 +50,7 @@ class SceneNode : public Referenced, public Named, public Activated
|
|||||||
void detachFromParent();
|
void detachFromParent();
|
||||||
|
|
||||||
virtual void update(Scalar time);
|
virtual void update(Scalar time);
|
||||||
virtual void render (RenderDevice *device, Camera *camera);
|
virtual void queue (RenderQueue *queue, Camera *camera);
|
||||||
|
|
||||||
const Transformation& getRelativeTransformation();
|
const Transformation& getRelativeTransformation();
|
||||||
const Transformation& getAbsoluteTransformation();
|
const Transformation& getAbsoluteTransformation();
|
||||||
|
@ -200,4 +200,20 @@ void ScriptSystem::callFunction(const std::string &name, double value)
|
|||||||
}
|
}
|
||||||
sq_pop(_VM, 1);
|
sq_pop(_VM, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::callFunction(const std::string &name, double value1, double value2)
|
||||||
|
{
|
||||||
|
sq_pushroottable(_VM);
|
||||||
|
sq_pushstring(_VM, name.c_str(), -1);
|
||||||
|
if (SQ_SUCCEEDED(sq_get(_VM, -2)) )
|
||||||
|
{
|
||||||
|
sq_pushroottable(_VM);
|
||||||
|
sq_pushfloat(_VM, value1);
|
||||||
|
sq_pushfloat(_VM, value2);
|
||||||
|
sq_call(_VM, 3, SQFalse, SQTrue);
|
||||||
|
sq_pop(_VM, 1);
|
||||||
|
}
|
||||||
|
sq_pop(_VM, 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ class ScriptSystem : public Referenced
|
|||||||
|
|
||||||
void callFunction(const std::string &name);
|
void callFunction(const std::string &name);
|
||||||
void callFunction(const std::string &name, double value);
|
void callFunction(const std::string &name, double value);
|
||||||
|
void callFunction(const std::string &name, double value1, double value2);
|
||||||
|
void callFunction(const std::string &name, double value1, double value2, double value3);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BlueCore
|
} // namespace BlueCore
|
||||||
|
59
engine/ScriptSystem_Application.cpp
Normal file
59
engine/ScriptSystem_Application.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
|
static weak_ptr<Application> gApplication;
|
||||||
|
|
||||||
|
static SQInteger _quit(HSQUIRRELVM v)
|
||||||
|
{
|
||||||
|
if (gApplication.valid())
|
||||||
|
gApplication->quit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _toggle_pause(HSQUIRRELVM v)
|
||||||
|
{
|
||||||
|
if (gApplication.valid())
|
||||||
|
gApplication->togglePause();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _setscenegraph(HSQUIRRELVM v)
|
||||||
|
{
|
||||||
|
SceneGraph *scenegraph = 0;
|
||||||
|
|
||||||
|
sq_getinstanceup(v, -1, ( void ** ) &scenegraph, 0);
|
||||||
|
|
||||||
|
gApplication->setSceneGraph(scenegraph);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupScriptSystem_Application(ScriptSystem* scriptsystem,
|
||||||
|
Application* application)
|
||||||
|
{
|
||||||
|
if (application == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
gApplication = application;
|
||||||
|
|
||||||
|
HSQUIRRELVM vm = scriptsystem->getVM();
|
||||||
|
sq_pushroottable(vm);
|
||||||
|
|
||||||
|
sq_pushstring(vm, "quit", -1);
|
||||||
|
sq_newclosure(vm, _quit, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
sq_pushstring(vm, "togglePause", -1);
|
||||||
|
sq_newclosure(vm, _toggle_pause, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
sq_pushstring(vm, "setSceneGraph", -1);
|
||||||
|
sq_newclosure(vm, _setscenegraph, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
sq_pop(vm, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
engine/ScriptSystem_Application.h
Normal file
11
engine/ScriptSystem_Application.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef BLUECORE_SCRIPTING_APPLICATION_H
|
||||||
|
#define BLUECORE_SCRIPTING_APPLICATION_H
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
void setupScriptSystem_Application(ScriptSystem* scriptsystem, Application* application);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
125
engine/ScriptSystem_Camera.cpp
Normal file
125
engine/ScriptSystem_Camera.cpp
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
#include "ScriptSystem_Camera.h"
|
||||||
|
#include "ScriptSystem_Math.h"
|
||||||
|
|
||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
|
static SQInteger _camera_releasehook(SQUserPointer p, SQInteger size)
|
||||||
|
{
|
||||||
|
Camera *camera = (Camera *)p;
|
||||||
|
|
||||||
|
if (camera)
|
||||||
|
camera->removeReference();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _camera_constructor(HSQUIRRELVM vm)
|
||||||
|
{
|
||||||
|
SQInteger argc = sq_gettop(vm);
|
||||||
|
|
||||||
|
if (argc < 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Camera *camera = new Camera();
|
||||||
|
camera->addReference();
|
||||||
|
|
||||||
|
sq_setinstanceup(vm, 1, (void *)camera );
|
||||||
|
sq_setreleasehook(vm, 1, _camera_releasehook);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _camera_setposition(HSQUIRRELVM v)
|
||||||
|
{
|
||||||
|
Camera *camera = 0;
|
||||||
|
|
||||||
|
sq_getinstanceup(v, 1, ( void ** ) &camera, 0);
|
||||||
|
|
||||||
|
if (camera)
|
||||||
|
{
|
||||||
|
Vector3 position;
|
||||||
|
int argc = sq_gettop(v);
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
_getvectorvalues(v, 2, position.x, position.y, position.z);
|
||||||
|
}
|
||||||
|
else if (argc == 4)
|
||||||
|
{
|
||||||
|
sq_getfloat(v, 2, &position.x);
|
||||||
|
sq_getfloat(v, 3, &position.y);
|
||||||
|
sq_getfloat(v, 4, &position.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
camera->setPosition(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _camera_lookat(HSQUIRRELVM v)
|
||||||
|
{
|
||||||
|
Camera *camera = 0;
|
||||||
|
|
||||||
|
sq_getinstanceup(v, 1, ( void ** ) &camera, 0);
|
||||||
|
|
||||||
|
if (camera)
|
||||||
|
{
|
||||||
|
Vector3 position;
|
||||||
|
int argc = sq_gettop(v);
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
_getvectorvalues(v, 2, position.x, position.y, position.z);
|
||||||
|
}
|
||||||
|
else if (argc == 4)
|
||||||
|
{
|
||||||
|
sq_getfloat(v, 2, &position.x);
|
||||||
|
sq_getfloat(v, 3, &position.y);
|
||||||
|
sq_getfloat(v, 4, &position.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
camera->lookAt(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupScriptSystem_Camera(ScriptSystem* scriptsystem)
|
||||||
|
{
|
||||||
|
if (scriptsystem == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
HSQUIRRELVM vm = scriptsystem->getVM();
|
||||||
|
|
||||||
|
sq_pushroottable(vm);
|
||||||
|
|
||||||
|
// push class
|
||||||
|
sq_pushstring(vm, "Camera", -1);
|
||||||
|
|
||||||
|
if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
|
||||||
|
{
|
||||||
|
// register constructor
|
||||||
|
sq_pushstring(vm, "constructor", -1);
|
||||||
|
sq_newclosure(vm, _camera_constructor, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
sq_pushstring(vm, "setPosition", -1);
|
||||||
|
sq_newclosure(vm, _camera_setposition, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
sq_pushstring(vm, "lookAt", -1);
|
||||||
|
sq_newclosure(vm, _camera_lookat, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
// create class
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
sq_poptop(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
engine/ScriptSystem_Camera.h
Normal file
11
engine/ScriptSystem_Camera.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef BLUECORE_SCRIPTING_CAMERA_H
|
||||||
|
#define BLUECORE_SCRIPTING_CAMERA_H
|
||||||
|
|
||||||
|
#include "ScriptSystem.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
void setupScriptSystem_Camera(ScriptSystem* scriptsystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
81
engine/ScriptSystem_SceneGraph.cpp
Normal file
81
engine/ScriptSystem_SceneGraph.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#include "ScriptSystem_Camera.h"
|
||||||
|
#include "ScriptSystem_Math.h"
|
||||||
|
|
||||||
|
#include "SceneGraph.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
|
static SQInteger _scenegraph_releasehook(SQUserPointer p, SQInteger size)
|
||||||
|
{
|
||||||
|
SceneGraph *scenegraph = (SceneGraph *)p;
|
||||||
|
|
||||||
|
if (scenegraph)
|
||||||
|
scenegraph->removeReference();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _scenegraph_constructor(HSQUIRRELVM vm)
|
||||||
|
{
|
||||||
|
SQInteger argc = sq_gettop(vm);
|
||||||
|
|
||||||
|
if (argc < 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
SceneGraph *scenegraph = new SceneGraph();
|
||||||
|
scenegraph->addReference();
|
||||||
|
|
||||||
|
sq_setinstanceup(vm, 1, (void *)scenegraph );
|
||||||
|
sq_setreleasehook(vm, 1, _scenegraph_releasehook);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQInteger _set_camera(HSQUIRRELVM v)
|
||||||
|
{
|
||||||
|
SceneGraph *scenegraph = 0;
|
||||||
|
|
||||||
|
sq_getinstanceup(v, 1, ( void ** ) &scenegraph, 0);
|
||||||
|
|
||||||
|
if (scenegraph)
|
||||||
|
{
|
||||||
|
Camera *camera;
|
||||||
|
sq_getinstanceup (v, 2, ( void ** ) &camera, 0);
|
||||||
|
scenegraph->setCamera(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupScriptSystem_SceneGraph(ScriptSystem* scriptsystem)
|
||||||
|
{
|
||||||
|
if (scriptsystem == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
HSQUIRRELVM vm = scriptsystem->getVM();
|
||||||
|
|
||||||
|
sq_pushroottable(vm);
|
||||||
|
|
||||||
|
// push class
|
||||||
|
sq_pushstring(vm, "SceneGraph", -1);
|
||||||
|
|
||||||
|
if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
|
||||||
|
{
|
||||||
|
// register constructor
|
||||||
|
sq_pushstring(vm, "constructor", -1);
|
||||||
|
sq_newclosure(vm, _scenegraph_constructor, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
sq_pushstring(vm, "setCamera", -1);
|
||||||
|
sq_newclosure(vm, _set_camera, 0);
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
|
// create class
|
||||||
|
sq_newslot(vm, -3, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
sq_poptop(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
engine/ScriptSystem_SceneGraph.h
Normal file
11
engine/ScriptSystem_SceneGraph.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef BLUECORE_SCRIPTING_CAMERA_H
|
||||||
|
#define BLUECORE_SCRIPTING_CAMERA_H
|
||||||
|
|
||||||
|
#include "ScriptSystem.h"
|
||||||
|
|
||||||
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
void setupScriptSystem_SceneGraph(ScriptSystem* scriptsystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace BlueCore {
|
namespace BlueCore
|
||||||
|
{
|
||||||
|
|
||||||
void CfgParser::parseFile(const std::string& filename)
|
void CfgParser::parseFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
@ -19,8 +20,6 @@ void CfgParser::parseFile (const std::string& filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CfgParser::parseLine(const std::string& line)
|
void CfgParser::parseLine(const std::string& line)
|
||||||
{
|
{
|
||||||
std::string::size_type i(line.find_first_of('='));
|
std::string::size_type i(line.find_first_of('='));
|
||||||
@ -34,8 +33,6 @@ void CfgParser::parseLine (const std::string& line)
|
|||||||
_Pairs[key] = value;
|
_Pairs[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CfgParser::parse(const char* buffer, unsigned int length)
|
void CfgParser::parse(const char* buffer, unsigned int length)
|
||||||
{
|
{
|
||||||
const char* ptr = buffer;
|
const char* ptr = buffer;
|
||||||
@ -58,8 +55,6 @@ void CfgParser::parse (const char* buffer, unsigned int length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double CfgParser::get(const std::string& key, double defaultValue)
|
double CfgParser::get(const std::string& key, double defaultValue)
|
||||||
{
|
{
|
||||||
double value;
|
double value;
|
||||||
@ -70,8 +65,6 @@ double CfgParser::get (const std::string& key, double defaultValue)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CfgParser::getDouble(const std::string& key, double& value)
|
bool CfgParser::getDouble(const std::string& key, double& value)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::const_iterator result;
|
std::map<std::string, std::string>::const_iterator result;
|
||||||
@ -86,8 +79,6 @@ bool CfgParser::getDouble (const std::string& key, double& value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int CfgParser::get(const std::string& key, int defaultValue)
|
int CfgParser::get(const std::string& key, int defaultValue)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
@ -98,8 +89,6 @@ int CfgParser::get (const std::string& key, int defaultValue)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CfgParser::getInteger(const std::string& key, int& value)
|
bool CfgParser::getInteger(const std::string& key, int& value)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::const_iterator result;
|
std::map<std::string, std::string>::const_iterator result;
|
||||||
@ -114,7 +103,6 @@ bool CfgParser::getInteger (const std::string& key, int& value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CfgParser::get(const std::string& key, bool defaultValue)
|
bool CfgParser::get(const std::string& key, bool defaultValue)
|
||||||
{
|
{
|
||||||
bool value;
|
bool value;
|
||||||
@ -125,8 +113,6 @@ bool CfgParser::get (const std::string& key, bool defaultValue)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CfgParser::getBoolean(const std::string& key, bool& value)
|
bool CfgParser::getBoolean(const std::string& key, bool& value)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::const_iterator result;
|
std::map<std::string, std::string>::const_iterator result;
|
||||||
@ -149,8 +135,6 @@ bool CfgParser::getBoolean (const std::string& key, bool& value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string CfgParser::get(const std::string& key, std::string defaultValue)
|
std::string CfgParser::get(const std::string& key, std::string defaultValue)
|
||||||
{
|
{
|
||||||
std::string value;
|
std::string value;
|
||||||
@ -161,8 +145,6 @@ std::string CfgParser::get (const std::string& key, std::string defaultValue)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CfgParser::getString(const std::string& key, std::string& value)
|
bool CfgParser::getString(const std::string& key, std::string& value)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::const_iterator result;
|
std::map<std::string, std::string>::const_iterator result;
|
||||||
@ -177,8 +159,6 @@ bool CfgParser::getString (const std::string& key, std::string& value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CfgParser::getStrings(const std::string& key, std::vector<string>& strings)
|
bool CfgParser::getStrings(const std::string& key, std::vector<string>& strings)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::const_iterator result;
|
std::map<std::string, std::string>::const_iterator result;
|
||||||
@ -193,6 +173,23 @@ bool CfgParser::getStrings (const std::string& key, std::vector<string>& strings
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CfgParser::getDoubles(const std::string& key, std::vector<double>& doubles)
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string>::const_iterator result;
|
||||||
|
result = _Pairs.find(key);
|
||||||
|
|
||||||
|
if (result != _Pairs.end())
|
||||||
|
{
|
||||||
|
std::vector<std::string> strings;
|
||||||
|
explode(result->second, strings, true, ",");
|
||||||
|
std::vector<std::string>::iterator i;
|
||||||
|
for (i = strings.begin(); i != strings.end(); i++)
|
||||||
|
doubles.push_back(atof((*i).c_str()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace BlueCore
|
} // namespace BlueCore
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ public:
|
|||||||
|
|
||||||
bool getStrings (const std::string& key, std::vector<std::string>& strings);
|
bool getStrings (const std::string& key, std::vector<std::string>& strings);
|
||||||
|
|
||||||
|
bool getDoubles (const std::string& key, std::vector<double>& doubles);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::map<std::string, std::string> _Pairs;
|
std::map<std::string, std::string> _Pairs;
|
||||||
|
@ -71,16 +71,26 @@ lastFPS <- 0;
|
|||||||
frameCount <- 0;
|
frameCount <- 0;
|
||||||
FPS <- 1;
|
FPS <- 1;
|
||||||
body <- null;
|
body <- null;
|
||||||
|
camera <- null;
|
||||||
|
mainSceneGraph <- null;
|
||||||
|
|
||||||
function Initialize()
|
function Initialize()
|
||||||
{
|
{
|
||||||
::font = Font();//Font ("DejaVuSans.ttf", 24, 1 );
|
::font = Font();//Font ("DejaVuSans.ttf", 24, 1 );
|
||||||
::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
|
::logo = Image ("image.png", 0.0, 0.0, 1.0, 1.0);
|
||||||
::body = RigidBody();
|
::body = RigidBody();
|
||||||
|
::camera = Camera();
|
||||||
|
::mainSceneGraph = SceneGraph();
|
||||||
|
::camera.lookAt (0.0, 0.0, 0.0);
|
||||||
|
::mainSceneGraph.setCamera (::camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
function OnFrame( delta )
|
function OnFrame (delta, total)
|
||||||
|
{
|
||||||
|
::camera.setPosition (::body.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
function OnOverlay (delta, total)
|
||||||
{
|
{
|
||||||
::frameCount += 1
|
::frameCount += 1
|
||||||
::lastFPS += delta;
|
::lastFPS += delta;
|
||||||
@ -92,20 +102,30 @@ function OnFrame( delta )
|
|||||||
::lastFPS -= 0.1;
|
::lastFPS -= 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (total < 2.0)
|
||||||
|
::logo.draw (0.5, 0.5);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v <- ::body.getPosition();
|
||||||
|
::font.print(10, 40, "Position: " + v.x + ", " + v.y + ", " + v.z, 1, 1 );
|
||||||
|
|
||||||
|
local seconds = floor(total % 60);
|
||||||
|
if (seconds < 10)
|
||||||
|
::font.print(10, 70, "Time: " + floor(total / 60.0) + ":0" + seconds, 1, 1 );
|
||||||
|
else
|
||||||
|
::font.print(10, 70, "Time: " + floor(total / 60.0) + ":" + seconds, 1, 1 );
|
||||||
|
|
||||||
if (::FPS > 0)
|
if (::FPS > 0)
|
||||||
{
|
{
|
||||||
local fps = "FPS: " + FPS + " / " + (1.0/::FPS)*1000.0 + " ms";
|
local fps = "FPS: " + FPS + " / " + (1.0/::FPS)*1000.0 + " ms";
|
||||||
::font.print( 10, 10, fps, 1, 1 );
|
::font.print( 10, 10, fps, 1, 1 );
|
||||||
}
|
}
|
||||||
// ::logo.draw (0.5, 0.5);
|
}
|
||||||
|
|
||||||
v <- ::body.getPosition();
|
|
||||||
::font.print(10, 40, "Position: " + v.x + ", " + v.y + ", " + v.z, 1, 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function OnStep( delte )
|
function OnStep (delta, total)
|
||||||
{
|
{
|
||||||
::body.applyLocalForce( Vector(0.0, 0.0, 1.0) );
|
::body.applyLocalForce( Vector(1.0, 0.0, 1.0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
function Shutdown()
|
function Shutdown()
|
||||||
|
207
engine/main.cpp
207
engine/main.cpp
@ -1,26 +1,5 @@
|
|||||||
#include "GL/glew.h"
|
#include "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 "ScriptSystem_Font.h"
|
|
||||||
#include "ScriptSystem_Image.h"
|
|
||||||
#include "ScriptSystem_Math.h"
|
|
||||||
#include "ScriptSystem_RigidBody.h"
|
|
||||||
#include "RigidBodySimulation.h"
|
|
||||||
|
|
||||||
#include "Camera.h"
|
|
||||||
#include "SceneNode.h"
|
|
||||||
|
|
||||||
#include "Utilities/CfgParser.h"
|
|
||||||
#include "Utilities/Log.h"
|
#include "Utilities/Log.h"
|
||||||
#include "Utilities/Kernel.h"
|
|
||||||
|
|
||||||
#include "physfs.h"
|
#include "physfs.h"
|
||||||
|
|
||||||
@ -65,193 +44,17 @@ void shutdownPhysfs()
|
|||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Application : public sigslot::has_slots<>
|
|
||||||
{
|
|
||||||
bool _Running;
|
|
||||||
double _DeltaTime;
|
|
||||||
double _LastTime;
|
|
||||||
|
|
||||||
void KeySlot(int key, int action)
|
|
||||||
{
|
|
||||||
if (key == GLFW_KEY_ESC && action == GLFW_RELEASE)
|
|
||||||
quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
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<Camera> _Camera;
|
|
||||||
ref_ptr<RenderQueue> _RenderQueue;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool 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);
|
|
||||||
_Camera = new Camera();
|
|
||||||
_RenderQueue = new RenderQueue();
|
|
||||||
|
|
||||||
setupScriptSystem_Font(_ScriptSystem, _FontManager);
|
|
||||||
setupScriptSystem_Image(_ScriptSystem, _TextureManager, _Device);
|
|
||||||
setupScriptSystem_Math(_ScriptSystem);
|
|
||||||
setupScriptSystem_RigidBody(_ScriptSystem, _Simulation);
|
|
||||||
|
|
||||||
_ScriptSystem->loadScript("main");
|
|
||||||
_ScriptSystem->callFunction("Initialize");
|
|
||||||
|
|
||||||
_Window->KeySignal.connect(this, &Application::KeySlot);
|
|
||||||
|
|
||||||
_Running = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if (window.valid() && device.valid())
|
|
||||||
{
|
|
||||||
|
|
||||||
camera->setFoV(45.0);
|
|
||||||
camera->setAspectRatio((double)width/(double)height);
|
|
||||||
camera->setNearPlane(1.0);
|
|
||||||
camera->setFarPlane(15000.0);
|
|
||||||
camera->setPosition(Vector3(0.0, 0.0, 20.0));
|
|
||||||
|
|
||||||
device->setAmbientLight(1.0, 1.0, 1.0);
|
|
||||||
|
|
||||||
//ref_ptr<SceneNode> rootnode(new SceneNode("root node"));
|
|
||||||
|
|
||||||
|
|
||||||
ref_ptr<Model> model = modelmanager->loadModel("combat");
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void shutdown()
|
|
||||||
{
|
|
||||||
_ScriptSystem->callFunction("Shutdown");
|
|
||||||
}
|
|
||||||
|
|
||||||
void quit()
|
|
||||||
{
|
|
||||||
_Running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void run()
|
|
||||||
{
|
|
||||||
clog << "--- starting main loop..."<< endlog;
|
|
||||||
|
|
||||||
_DeltaTime = 0;
|
|
||||||
_LastTime = glfwGetTime();
|
|
||||||
|
|
||||||
while (_Window->isOpen() && _Running)
|
|
||||||
{
|
|
||||||
double time = glfwGetTime();
|
|
||||||
_DeltaTime = time - _LastTime;
|
|
||||||
_LastTime = time;
|
|
||||||
|
|
||||||
_Device->clear();
|
|
||||||
/*
|
|
||||||
camera->setRotation(Quaternion(Vector3(0.0, 1.0, 0.0), fmod(time
|
|
||||||
/5.0, 6.2)));
|
|
||||||
device->begin3D(camera);
|
|
||||||
queue->clear();
|
|
||||||
queue->addOpaqueItem(model, Vector3(10.0, 0.0, 0.0), Quaternion());
|
|
||||||
queue->render(device);
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
_Simulation->saveStates();
|
|
||||||
_Simulation->updateSteps(_DeltaTime);
|
|
||||||
while (_Simulation->step())
|
|
||||||
;
|
|
||||||
|
|
||||||
_ScriptSystem->callFunction("OnFrame", _DeltaTime);
|
|
||||||
|
|
||||||
_Device->swap();
|
|
||||||
}
|
|
||||||
|
|
||||||
clog << "--- main loop finished..."<< endlog;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
initializePhysfs(argv[0]);
|
initializePhysfs(argv[0]);
|
||||||
|
|
||||||
Application app;
|
ref_ptr<Application> app = new Application();
|
||||||
|
|
||||||
if (app.initialize())
|
if (app->initialize())
|
||||||
{
|
{
|
||||||
app.run();
|
app->run();
|
||||||
}
|
}
|
||||||
app.shutdown();
|
app->shutdown();
|
||||||
|
|
||||||
shutdownPhysfs();
|
shutdownPhysfs();
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,16 @@ Scripting
|
|||||||
---------
|
---------
|
||||||
|
|
||||||
* make event based input available
|
* make event based input available
|
||||||
|
* make font height available
|
||||||
|
|
||||||
|
SceneGraph
|
||||||
|
----------
|
||||||
|
|
||||||
|
* create scene graph
|
||||||
|
|
||||||
* make ShaderProgram a class
|
* make ShaderProgram a class
|
||||||
* create RenderSet AND/OR RenderQueue
|
* create RenderSet AND/OR RenderQueue
|
||||||
|
* RenderQueueVisitor
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user