00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "Object.h"
00013
#include <OpenCAL/System.h>
00014
using namespace OpenCAL;
00015
00016
#include <OpenCAL/NullParentException.h>
00017
using Exceptions::NullParentException;
00018
00019
00020
00021
00022
00023
00024 Object::Object(
System *parent)
00025 : m_parent(parent), m_initialized(false), m_draw(true), m_enabled(true)
00026 {
00027
#ifdef VERBOSE
00028
Debug::print(
"Object constructor", 2);
00029
#endif // VERBOSE
00030
00031
if(!parent)
00032
throw NullParentException(__FILE__, __LINE__);
00033
00034
#ifdef VERBOSE
00035
Debug::print(
"Parent is given, adding to the the parent's object list...", 2);
00036
#endif // VERBOSE
00037
00038 parent->
addObject(
this);
00039 }
00040
00041 Object::~Object()
00042 {
00043
#ifdef VERBOSE
00044
Debug::print(
"Object destructor", 2);
00045
#endif // VERBOSE
00046
00047 m_parent->
deleteObject(
this);
00048 }
00049
00050
00051
00052
00053
00054
00055
void Object::move(
const Vector3 &direction,
float distance)
00056 {
00057 m_position += direction * distance;
00058 }
00059
00060
void Object::moveTo(
const Vector3 &position)
00061 {
00062 m_position = position;
00063 }
00064
00065
00066
00067
00068
00069
00070 Matrix44 Object::getMatrix()
const
00071
{
00072 Matrix44 result;
00073
00074 getMatrix(&result);
00075
00076
return result;
00077 }
00078
00079
void Object::getMatrix(Matrix44 *matrix)
const
00080
{
00081 matrix->identity();
00082
00083
00084 matrix->set(0,3, m_position.getX());
00085 matrix->set(1,3, m_position.getY());
00086 matrix->set(2,3, m_position.getZ());
00087 }
00088
00089
void Object::initialize()
00090 {
00091
#ifdef VERBOSE
00092
Debug::print(
"Object initialize", 2);
00093
#endif // VERBOSE
00094
00095 m_initialized =
true;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
void Object::assureInit()
00114 {
00115
if(!isInitialized())
00116 {
00117
#ifdef VERBOSE
00118
Debug::initWarning(
"object");
00119
#endif // VERBOSE
00120
initialize();
00121 }
00122 }