--- /dev/null
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/gl/matrix.h>
+#include <msp/gl/renderer.h>
+#include "axle.h"
+#include "vehicle.h"
+#include "vehicletype.h"
+
+using namespace Msp;
+
+namespace R2C2 {
+
+Axle3D::Axle3D(const Vehicle3D &v, unsigned a):
+ GL::ObjectInstance(*v.get_type().get_axle_object(a)),
+ vehicle(v.get_vehicle()),
+ bogie(0),
+ axle(vehicle.get_axle(a))
+{ }
+
+Axle3D::Axle3D(const Vehicle3D &v, unsigned b, unsigned a):
+ GL::ObjectInstance(*v.get_type().get_bogie_axle_object(b, a)),
+ vehicle(v.get_vehicle()),
+ bogie(&vehicle.get_bogie(b)),
+ axle(bogie->axles[a])
+{ }
+
+void Axle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
+{
+ if(!vehicle.get_track())
+ return;
+
+ ObjectInstance::render(renderer, tag);
+}
+
+void Axle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
+{
+ GL::Matrix matrix;
+
+ const Point &pos = vehicle.get_position();
+ matrix.translate(pos.x, pos.y, pos.z);
+ matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+
+ if(bogie)
+ {
+ matrix.translate(bogie->type->position, 0, 0);
+ matrix.rotate(bogie->direction, 0, 0, 1);
+ }
+
+ matrix.translate(axle.type->position, 0, axle.type->wheel_dia/2);
+ matrix.rotate(axle.angle, 0, 1, 0);
+
+ renderer.matrix_stack() *= matrix;
+}
+
+} // namespace R2C2
--- /dev/null
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef LIBR2C23D_AXLE_H_
+#define LIBR2C23D_AXLE_H_
+
+#include <msp/gl/objectinstance.h>
+#include "libr2c2/vehicle.h"
+
+namespace R2C2 {
+
+class Vehicle3D;
+
+class Axle3D: public Msp::GL::ObjectInstance
+{
+private:
+ const Vehicle &vehicle;
+ const Vehicle::Bogie *bogie;
+ const Vehicle::Axle &axle;
+
+public:
+ Axle3D(const Vehicle3D &, unsigned);
+ Axle3D(const Vehicle3D &, unsigned, unsigned);
+
+ virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+ virtual void setup_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+};
+
+} // namespace R2C2
+
+#endif
--- /dev/null
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/gl/matrix.h>
+#include <msp/gl/renderer.h>
+#include "bogie.h"
+#include "vehicle.h"
+#include "vehicletype.h"
+
+using namespace Msp;
+
+namespace R2C2 {
+
+Bogie3D::Bogie3D(const Vehicle3D &v, unsigned b):
+ GL::ObjectInstance(*v.get_type().get_bogie_object(b)),
+ vehicle(v.get_vehicle()),
+ bogie(vehicle.get_bogie(b))
+{ }
+
+void Bogie3D::render(Msp::GL::Renderer &renderer, const GL::Tag &tag) const
+{
+ if(!vehicle.get_track())
+ return;
+
+ ObjectInstance::render(renderer, tag);
+}
+
+void Bogie3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
+{
+ GL::Matrix matrix;
+
+ const Point &pos = vehicle.get_position();
+ matrix.translate(pos.x, pos.y, pos.z);
+ matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+
+ matrix.translate(bogie.type->position, 0, 0);
+ matrix.rotate(bogie.direction, 0, 0, 1);
+
+ renderer.matrix_stack() *= matrix;
+}
+
+} // namespace R2C2
--- /dev/null
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef LIBR2C23D_BOGIE_H_
+#define LIBR2C23D_BOGIE_H_
+
+#include <msp/gl/objectinstance.h>
+#include "libr2c2/vehicle.h"
+
+namespace R2C2 {
+
+class Vehicle3D;
+
+class Bogie3D: public Msp::GL::ObjectInstance
+{
+private:
+ const Vehicle &vehicle;
+ const Vehicle::Bogie &bogie;
+
+public:
+ Bogie3D(const Vehicle3D &, unsigned);
+
+ virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+ virtual void setup_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+};
+
+} // namespace R2C2
+
+#endif
--- /dev/null
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/gl/matrix.h>
+#include <msp/gl/renderer.h>
+#include "rod.h"
+#include "vehicle.h"
+#include "vehicletype.h"
+
+using namespace Msp;
+
+namespace R2C2 {
+
+Rod3D::Rod3D(const Vehicle3D &v, unsigned r):
+ GL::ObjectInstance(*v.get_type().get_rod_object(r)),
+ vehicle(v.get_vehicle()),
+ rod(vehicle.get_rod(r))
+{ }
+
+void Rod3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
+{
+ if(!vehicle.get_track())
+ return;
+
+ ObjectInstance::render(renderer, tag);
+}
+
+void Rod3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
+{
+ GL::Matrix matrix;
+ const Point &pos = vehicle.get_position();
+ matrix.translate(pos.x, pos.y, pos.z);
+ matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+
+ matrix.translate(rod.position.x, rod.position.y, rod.position.z);
+ if(rod.type->mirror_object)
+ matrix.scale(1, -1, 1);
+ matrix.rotate(rod.angle, 0, -1, 0);
+
+ renderer.matrix_stack() *= matrix;
+}
+
+} // namespace R2C2
--- /dev/null
+/* $Id$
+
+This file is part of R²C²
+Copyright © 2011 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef LIBR2C23D_ROD_H_
+#define LIBR2C23D_ROD_H_
+
+#include <msp/gl/objectinstance.h>
+#include "libr2c2/vehicle.h"
+
+namespace R2C2 {
+
+class Vehicle3D;
+
+class Rod3D: public Msp::GL::ObjectInstance
+{
+private:
+ const Vehicle &vehicle;
+ const Vehicle::Rod &rod;
+
+public:
+ Rod3D(const Vehicle3D &, unsigned);
+
+ virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+ virtual void setup_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+};
+
+} // namespace R2C2
+
+#endif
/* $Id$
This file is part of R²C²
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <cmath>
#include <msp/gl/matrix.h>
#include <msp/gl/misc.h>
+#include <msp/gl/renderer.h>
#include "libr2c2/tracktype.h"
#include "endpoint.h"
#include "layout.h"
return matrix;
}
-void Track3D::setup_render(const GL::Tag &) const
+void Track3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const
{
- GL::MatrixStack::modelview().push();
- GL::MatrixStack::modelview() *= get_matrix();
+ renderer.matrix_stack() *= get_matrix();
glPushName(reinterpret_cast<unsigned>(this));
}
-void Track3D::finish_render(const GL::Tag &) const
+void Track3D::finish_render(Msp::GL::Renderer &, const GL::Tag &) const
{
glPopName();
- GL::MatrixStack::modelview().pop();
}
} // namespace R2C2
/* $Id$
This file is part of R²C²
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
virtual bool is_visible() const { return true; }
Msp::GL::Matrix get_matrix() const;
- virtual void setup_render(const Msp::GL::Tag &) const;
- virtual void finish_render(const Msp::GL::Tag &) const;
+ virtual void setup_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+ virtual void finish_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
};
} // namespace R2C2
/* $Id$
This file is part of R²C²
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <cmath>
#include <msp/gl/matrix.h>
+#include <msp/gl/renderer.h>
+#include "axle.h"
+#include "bogie.h"
#include "layout.h"
+#include "rod.h"
#include "vehicle.h"
#include "vehicletype.h"
namespace R2C2 {
Vehicle3D::Vehicle3D(Layout3D &l, Vehicle &v):
+ GL::ObjectInstance(*l.get_catalogue().get_vehicle(v.get_type()).get_body_object()),
layout(l),
vehicle(v),
type(layout.get_catalogue().get_vehicle(vehicle.get_type()))
{
+ unsigned n_axles = vehicle.get_type().get_axles().size();
+ for(unsigned i=0; i<n_axles; ++i)
+ if(type.get_axle_object(i))
+ {
+ Axle3D *a = new Axle3D(*this, i);
+ axles.push_back(a);
+ layout.get_scene().add(*a);
+ }
+
+ unsigned n_bogies = vehicle.get_type().get_bogies().size();
+ for(unsigned i=0; i<n_bogies; ++i)
+ if(type.get_bogie_object(i))
+ {
+ Bogie3D *b = new Bogie3D(*this, i);
+ bogies.push_back(b);
+ layout.get_scene().add(*b);
+
+ n_axles = vehicle.get_type().get_bogie(i).axles.size();
+ for(unsigned j=0; j<n_axles; ++j)
+ if(type.get_bogie_axle_object(i, j))
+ {
+ Axle3D *a = new Axle3D(*this, i, j);
+ axles.push_back(a);
+ layout.get_scene().add(*a);
+ }
+ }
+
+ unsigned n_rods = vehicle.get_type().get_rods().size();
+ for(unsigned i=0; i<n_rods; ++i)
+ if(type.get_rod_object(i))
+ {
+ Rod3D *r = new Rod3D(*this, i);
+ rods.push_back(r);
+ layout.get_scene().add(*r);
+ }
+
layout.add_vehicle(*this);
layout.get_scene().add(*this);
}
{
layout.remove_vehicle(*this);
layout.get_scene().remove(*this);
+ for(vector<Axle3D *>::iterator i=axles.begin(); i!=axles.end(); ++i)
+ delete *i;
+ for(vector<Bogie3D *>::iterator i=bogies.begin(); i!=bogies.end(); ++i)
+ delete *i;
+ for(vector<Rod3D *>::iterator i=rods.begin(); i!=rods.end(); ++i)
+ delete *i;
}
Point Vehicle3D::get_node() const
return vehicle.get_track();
}
-void Vehicle3D::render(const GL::Tag &tag) const
+void Vehicle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const
{
if(!vehicle.get_track())
return;
- if(tag==0)
+ ObjectInstance::render(renderer, tag);
+
+ /*if(tag==0)
{
GL::PushMatrix push_mat;
GL::rotate(vehicle.get_direction()*180/M_PI, 0, 0, 1);
if(const GL::Object *obj = type.get_body_object())
- obj->render(tag);
+ obj->render(tag);*/
- const vector<VehicleType::Axle> &axles = vehicle.get_type().get_axles();
+ /*const vector<VehicleType::Axle> &axles = vehicle.get_type().get_axles();
for(unsigned i=0; i<axles.size(); ++i)
if(const GL::Object *obj = type.get_axle_object(i))
{
GL::rotate(180, 0, 0, 1);
if(const GL::Object *obj = type.get_bogie_object(i))
obj->render(tag);
- }
+ }*/
- const vector<VehicleType::Rod> &rods = vehicle.get_type().get_rods();
+ /*const vector<VehicleType::Rod> &rods = vehicle.get_type().get_rods();
for(unsigned i=0; i<rods.size(); ++i)
if(const GL::Object *obj = type.get_rod_object(i))
{
GL::scale(1, -1, 1);
GL::rotate(angle*180/M_PI, 0, -1, 0);
obj->render(tag);
- }
- }
+ }*/
+ //}
+}
+
+void Vehicle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const
+{
+ GL::Matrix matrix;
+ const Point &pos = vehicle.get_position();
+ matrix.translate(pos.x, pos.y, pos.z);
+ matrix.rotate(vehicle.get_direction(), 0, 0, 1);
+ renderer.matrix_stack() *= matrix;
}
} // namespace R2C2
/* $Id$
This file is part of R²C²
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
namespace R2C2 {
+class Axle3D;
+class Bogie3D;
class Layout3D;
+class Rod3D;
class VehicleType3D;
-class Vehicle3D: public Object3D, public Msp::GL::Renderable
+class Vehicle3D: public Object3D, public Msp::GL::ObjectInstance
{
private:
Layout3D &layout;
Vehicle &vehicle;
const VehicleType3D &type;
+ std::vector<Axle3D *> axles;
+ std::vector<Bogie3D *> bogies;
+ std::vector<Rod3D *> rods;
public:
Vehicle3D(Layout3D &, Vehicle &);
~Vehicle3D();
Vehicle &get_vehicle() const { return vehicle; }
+ const VehicleType3D &get_type() const { return type; }
virtual Point get_node() const;
virtual bool is_visible() const;
- virtual void render(const Msp::GL::Tag &) const;
+ virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
+ virtual void setup_render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
};
} // namespace R2C2
/* $Id$
This file is part of R²C²
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
front_sensor(0),
back_sensor(0)
{
- layout.add_vehicle(*this);
-
axles.assign(type.get_axles().begin(), type.get_axles().end());
bogies.assign(type.get_bogies().begin(), type.get_bogies().end());
rods.assign(type.get_rods().begin(), type.get_rods().end());
+
+ layout.add_vehicle(*this);
}
Vehicle::~Vehicle()