00001
00014 #ifndef SIMPLEOBJ_H
00015 #define SIMPLEOBJ_H
00016
00017 #include <IS3DCommon.H>
00018 #include "DrawObj.H"
00019 #include "IS3DEngine.H"
00020 #include "ConfigVal.H"
00021
00022 namespace IS3D {
00023
00024 typedef ReferenceCountedPointer<class BoxObj> BoxObjRef;
00025 class BoxObj : public DrawObj {
00026 public:
00027 BoxObj(const Box &box,
00028 const Color4 &solidColor=Color4(1,.2,.2,.5),
00029 const Color4 &wireColor=Color3::black()) : DrawObj("BoxObj") {
00030 _box = box;
00031 _solidColor = solidColor;
00032 _wireColor = wireColor;
00033 }
00034
00035 virtual ~BoxObj() {}
00036
00037 void draw() {
00038 Draw::box(_box, RD, _solidColor, _wireColor);
00039 }
00040 protected:
00041 Box _box;
00042 Color4 _solidColor;
00043 Color4 _wireColor;
00044 };
00045
00046
00047 typedef ReferenceCountedPointer<class ArrowObj> ArrowObjRef;
00048 class ArrowObj : public DrawObj {
00049 public:
00050 ArrowObj(const Vector3 &start, const Vector3 &direction,
00051 const Color4 &color=Color3::orange(),
00052 double scale=1.0) :
00053 DrawObj("ArrowObj") {
00054 _start = start;
00055 _dir = direction;
00056 _color = color;
00057 _scale = scale;
00058 }
00059
00060 virtual ~ArrowObj() {}
00061
00062 void draw() {
00063 Draw::arrow(_start, _dir, RD, _color, _scale);
00064 }
00065 protected:
00066 Vector3 _start;
00067 Vector3 _dir;
00068 Color4 _color;
00069 double _scale;
00070 };
00071
00072
00073 typedef ReferenceCountedPointer<class AxesObj> AxesObjRef;
00074 class AxesObj : public DrawObj {
00075 public:
00076 AxesObj(double scale=1.0) : DrawObj("AxesObj") {
00077 _xcol = Color3::red();
00078 _ycol = Color3::green();
00079 _zcol = Color3::blue();
00080 _scale = scale;
00081 }
00082
00083 AxesObj(Color4 xcol, Color4 ycol, Color4 zcol, double scale=1.0) :
00084 DrawObj("AxesObj") {
00085 _xcol = xcol;
00086 _ycol = ycol;
00087 _zcol = zcol;
00088 _scale = scale;
00089 }
00090
00091 virtual ~AxesObj() {}
00092
00093 void draw() {
00094
00095
00096
00097 RD->disableLighting();
00098 Draw::axes(CoordinateFrame(), RD, _xcol, _ycol, _zcol, _scale);
00099 RD->enableLighting();
00100 }
00101
00102 protected:
00103 Color4 _xcol, _ycol, _zcol;
00104 double _scale;
00105 };
00106
00107
00108 typedef ReferenceCountedPointer<class SphereObj> SphereObjRef;
00109 class SphereObj : public DrawObj {
00110 public:
00111 SphereObj(const Sphere &sphere,
00112 const Color4 &solidColor=Color4(1,.2,.2,.5),
00113 const Color4 &wireColor=Color3::black()) : DrawObj("SphereObj") {
00114 _sphere = sphere;
00115 _solidColor = solidColor;
00116 _wireColor = wireColor;
00117 }
00118
00119 virtual ~SphereObj() {}
00120
00121 void draw() {
00122 Draw::sphere(_sphere, RD, _solidColor, _wireColor);
00123 }
00124 protected:
00125 Sphere _sphere;
00126 Color4 _solidColor;
00127 Color4 _wireColor;
00128 };
00129
00130
00131 typedef ReferenceCountedPointer<class TextObj> TextObjRef;
00132 class TextObj : public DrawObj {
00133 public:
00134 TextObj(const std::string &str, const double textHeight,
00135 const Color4 &textColor=Color3::white(),
00136 const Color4 &outlineColor=Color4::clear()) : DrawObj("TextObj") {
00137 _str = str;
00138 _height = textHeight;
00139 _textColor = textColor;
00140 _outlineColor = outlineColor;
00141 _font = IS3DEngine::getFont();
00142 }
00143
00144 virtual ~TextObj() {}
00145
00146 void setString(const std::string &newStr) { _str = newStr; }
00147 void setOffsetFrame(CoordinateFrame cf) { _offset = cf; }
00148
00149 void draw() {
00150 CoordinateFrame xform = RD->getObjectToWorldMatrix() * _offset;
00151 RD->pushState();
00152 RD->disableLighting();
00153 _font->draw3D(RD, _str, xform, _height, _textColor, _outlineColor,
00154 GFont::XALIGN_CENTER, GFont::YALIGN_CENTER);
00155 RD->popState();
00156 }
00157
00158 protected:
00159 std::string _str;
00160 double _height;
00161 Color4 _textColor;
00162 Color4 _outlineColor;
00163 GFontRef _font;
00164 CoordinateFrame _offset;
00165 };
00166
00167
00168 typedef ReferenceCountedPointer<class ScreenTextObj> ScreenTextObjRef;
00169 class ScreenTextObj : public DrawObj {
00170 public:
00171 ScreenTextObj(const std::string &str, const double textHeight,
00172 const Color4 &textColor=Color3::white(),
00173 const Color4 &outlineColor=Color4::clear()) : DrawObj("ScreenTextObj") {
00174 _str = str;
00175 _height = textHeight;
00176 _textColor = textColor;
00177 _outlineColor = outlineColor;
00178 _pos = Vector2(20,20);
00179 _font = IS3DEngine::getFont();
00180 }
00181
00182 virtual ~ScreenTextObj() {}
00183
00184 void setString(const std::string &newStr) { _str = newStr; }
00185 void setPosition(Vector2 pos) { _pos = pos; }
00186
00187 void draw() {
00188 RD->pushState();
00189 RD->push2D();
00190 RD->disableLighting();
00191 _font->draw2D(RD, _str, _pos, _height, _textColor, _outlineColor,
00192 GFont::XALIGN_CENTER, GFont::YALIGN_CENTER);
00193 RD->pop2D();
00194 RD->popState();
00195 }
00196
00197 protected:
00198 std::string _str;
00199 double _height;
00200 Color4 _textColor;
00201 Color4 _outlineColor;
00202 GFontRef _font;
00203 Vector2 _pos;
00204 };
00205
00206
00207
00208 typedef ReferenceCountedPointer<class NamedAxesObj> NamedAxesObjRef;
00209 class NamedAxesObj : public DrawObj {
00210 public:
00211 NamedAxesObj(const std::string &str, const double scale,
00212 const Color4 &textColor=Color3::white(),
00213 const Color4 &outlineColor=Color4::clear()) : DrawObj("NamedAxesObj") {
00214 _str = str;
00215 _scale = scale;
00216 _textColor = textColor;
00217 _outlineColor = outlineColor;
00218 _font = IS3DEngine::getFont();
00219 }
00220
00221 virtual ~NamedAxesObj() {}
00222
00223 void setString(const std::string &newStr) { _str = newStr; }
00224
00225 void draw() {
00226 CoordinateFrame offset(Vector3(0,-_scale*.666,0));
00227 CoordinateFrame xform = RD->getObjectToWorldMatrix() * offset;
00228 RD->pushState();
00229 RD->disableLighting();
00230 _font->draw3D(RD, _str, xform, _scale/3.0, _textColor, _outlineColor,
00231 GFont::XALIGN_CENTER, GFont::YALIGN_CENTER);
00232
00233 Draw::axes(CoordinateFrame(), RD, Color3::red(), Color3::green(),
00234 Color3::blue(), _scale);
00235
00236 RD->popState();
00237 }
00238
00239 protected:
00240 std::string _str;
00241 double _scale;
00242 Color4 _textColor;
00243 Color4 _outlineColor;
00244 GFontRef _font;
00245 };
00246
00247
00248 }
00249
00250 #endif
00251
00252
00253