00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00035
00036 #ifndef GROOVX_GFX_GXTRANSFORM_CC_UTC20050626084023_DEFINED
00037 #define GROOVX_GFX_GXTRANSFORM_CC_UTC20050626084023_DEFINED
00038
00039 #include "gxtransform.h"
00040
00041 #include "geom/box.h"
00042 #include "geom/rect.h"
00043 #include "geom/txform.h"
00044 #include "geom/vec3.h"
00045
00046 #include "gfx/bbox.h"
00047 #include "gfx/canvas.h"
00048
00049 #include "io/reader.h"
00050 #include "io/writer.h"
00051
00052 #include "rutz/trace.h"
00053 #include "rutz/debug.h"
00054 GVX_DBG_REGISTER
00055
00056 namespace
00057 {
00058 const io::version_id GXTRANSFORM_SVID = 1;
00059 }
00060
00062
00063
00064
00066
00067 struct GxTransformImpl
00068 {
00069 GxTransformImpl(GxTransform* p) :
00070 owner(p),
00071 txformCache(geom::txform::identity())
00072 {}
00073
00074 GxTransform* owner;
00075
00076 private:
00077 mutable geom::txform txformCache;
00078
00079 public:
00080 const geom::txform& getTxform() const
00081 {
00082 txformCache = geom::txform(owner->translation,
00083 owner->scaling,
00084 owner->rotationAxis,
00085 owner->itsRotationAngle);
00086
00087 return txformCache;
00088 }
00089 };
00090
00092
00093
00094
00096
00097 const FieldMap& GxTransform::classFields()
00098 {
00099 static const Field FIELD_ARRAY[] =
00100 {
00101 Field("translation", Field::ValueType(), &GxTransform::translation,
00102 "0. 0. 0.", "-10. -10. -10.", "10. 10. 10.", "0.1 0.1 0.1",
00103 Field::NEW_GROUP | Field::MULTI),
00104 Field("scaling", Field::ValueType(), &GxTransform::scaling,
00105 "1. 1. 1.", "0.1 0.1 0.1", "10. 10. 10.", "0.1 0.1 0.1",
00106 Field::MULTI),
00107 Field("rotationAxis", Field::ValueType(), &GxTransform::rotationAxis,
00108 "0. 0. 1.", "-1. -1. -1.", "1. 1. 1.", "0.1 0.1 0.1", Field::MULTI),
00109 Field("rotationAngle",
00110 &GxTransform::itsRotationAngle, 0., 0., 360., 1.),
00111 Field("mtxMode", &GxTransform::itsMtxMode, 0, 0, 1, 1,
00112 Field::TRANSIENT | Field::BOOLEAN),
00113 Field("jackSize", &GxTransform::itsJackSize, 0, 0, 100, 1, Field::TRANSIENT)
00114 };
00115
00116 static FieldMap POS_FIELDS(FIELD_ARRAY);
00117
00118 return POS_FIELDS;
00119 }
00120
00121 GxTransform* GxTransform::make()
00122 {
00123 GVX_TRACE("GxTransform::make");
00124 return new GxTransform;
00125 }
00126
00127 GxTransform::GxTransform() :
00128 FieldContainer(&sigNodeChanged),
00129 translation(0.0, 0.0, 0.0),
00130 scaling(1.0, 1.0, 1.0),
00131 rotationAxis(0.0, 0.0, 1.0),
00132 itsRotationAngle(0.0),
00133 itsMtxMode(0),
00134 itsJackSize(0),
00135 rep(new GxTransformImpl(this))
00136 {
00137 GVX_TRACE("GxTransform::GxTransform");
00138
00139 dbg_eval_nl(3, rep);
00140
00141 setFieldMap(GxTransform::classFields());
00142 }
00143
00144 GxTransform::~GxTransform() throw()
00145 {
00146 GVX_TRACE("GxTransform::~GxTransform");
00147 delete rep;
00148 }
00149
00150 io::version_id GxTransform::class_version_id() const
00151 {
00152 GVX_TRACE("GxTransform::class_version_id");
00153 return GXTRANSFORM_SVID;
00154 }
00155
00156 void GxTransform::read_from(io::reader& reader)
00157 {
00158 GVX_TRACE("GxTransform::read_from");
00159
00160 reader.ensure_version_id("GxTransform", 1,
00161 "Try cvs tag xml_conversion_20040526",
00162 SRC_POS);
00163
00164 readFieldsFrom(reader, classFields());
00165 }
00166
00167 void GxTransform::write_to(io::writer& writer) const
00168 {
00169 GVX_TRACE("GxTransform::write_to");
00170
00171 writer.ensure_output_version_id("GxTransform",
00172 GXTRANSFORM_SVID, 1,
00173 "Try groovx0.8a4", SRC_POS);
00174
00175 writeFieldsTo(writer, classFields(), GXTRANSFORM_SVID);
00176 }
00177
00179
00181
00182 const geom::txform& GxTransform::getTxform() const
00183 {
00184 GVX_TRACE("GxTransform::getTxform");
00185
00186 return rep->getTxform();
00187 }
00188
00190
00192
00193 void GxTransform::getBoundingCube(Gfx::Bbox& bbox) const
00194 {
00195 GVX_TRACE("GxTransform::getBoundingCube");
00196
00197 bbox.transform(getTxform());
00198 }
00199
00200 void GxTransform::draw(Gfx::Canvas& canvas) const
00201 {
00202 GVX_TRACE("GxTransform::draw");
00203
00204 if (itsMtxMode == 0)
00205 {
00206 GVX_TRACE("GxTransform::draw::native-transform");
00207 canvas.translate(translation);
00208 canvas.scale(scaling);
00209 canvas.rotate(rotationAxis, itsRotationAngle);
00210 }
00211 else
00212 {
00213 GVX_TRACE("GxTransform::draw::custom-transform");
00214 canvas.transform(rep->getTxform());
00215 }
00216
00217 if (itsJackSize > 0)
00218 {
00219 Gfx::LinesBlock block(canvas);
00220
00221 const double d = itsJackSize / 10.0;
00222
00223 canvas.vertex3(geom::vec3<double>(-d, 0.0, 0.0));
00224 canvas.vertex3(geom::vec3<double>( d, 0.0, 0.0));
00225
00226 canvas.vertex3(geom::vec3<double>(0.0, -d, 0.0));
00227 canvas.vertex3(geom::vec3<double>(0.0, d, 0.0));
00228
00229 canvas.vertex3(geom::vec3<double>(0.0, 0.0, -d));
00230 canvas.vertex3(geom::vec3<double>(0.0, 0.0, d));
00231 }
00232 }
00233
00234 static const char __attribute__((used)) vcid_groovx_gfx_gxtransform_cc_utc20050626084023[] = "$Id: gxtransform.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00235 #endif // !GROOVX_GFX_GXTRANSFORM_CC_UTC20050626084023_DEFINED