--- /dev/null
+pass ""
+{
+ material
+ {
+ diffuse 1.0 1.0 1.0 1.0;
+ };
+
+ texunit 0
+ {
+ texture2d
+ {
+ storage RGB 2 1;
+ min_filter NEAREST;
+ mag_filter NEAREST;
+ raw_data "\x40\x40\x40\xD0\xD0\xD0";
+ };
+ };
+};
for(Catalogue::TrackMap::const_iterator i=trks.begin(); i!=trks.end(); ++i)
track_added(*i->second);
- ballast_material.set_diffuse(GL::Color(0.25, 0.25, 0.25));
- rail_material.set_diffuse(GL::Color(0.85, 0.85, 0.85));
-
build_endpoint_mesh();
}
Catalogue &catalogue;
std::map<const TrackType *, TrackType3D *> tracks;
std::map<const VehicleType *, VehicleType3D *> vehicles;
- Msp::GL::Material ballast_material;
- Msp::GL::Material rail_material;
Msp::GL::Mesh endpoint_mesh;
public:
const Catalogue &get_catalogue() const { return catalogue; }
const TrackType3D &get_track(const TrackType &) const;
const VehicleType3D &get_vehicle(const VehicleType &) const;
- const Msp::GL::Material &get_ballast_material() const { return ballast_material; }
- const Msp::GL::Material &get_rail_material() const { return rail_material; }
const Msp::GL::Mesh &get_endpoint_mesh() const { return endpoint_mesh; }
private:
void track_added(const TrackType &);
#define R2C2_3D_LAYOUT_H_
#include <sigc++/trackable.h>
+#include <msp/gl/instancescene.h>
#include <msp/gl/simplescene.h>
#include "libr2c2/layout.h"
#include "catalogue.h"
Catalogue3D catalogue;
TrackMap tracks;
VehicleMap vehicles;
- Msp::GL::SimpleScene scene;
+ Msp::GL::InstanceScene scene;
Msp::GL::SimpleScene ep_scene;
Msp::GL::SimpleScene path_scene;
if(!mask)
return;
- GL::PushMatrix push_mat;
- track.apply_matrix();
- GL::translate(0, 0, z_offs);
+ GL::MatrixStack::Push push_mtx(GL::MatrixStack::modelview());
+ GL::Matrix matrix = track.get_matrix();
+ matrix.translate(0, 0, z_offs);
+ GL::MatrixStack::modelview() *= matrix;
glColor4f(color.r, color.g, color.b, color.a);
for(unsigned i=0; mask; ++i, mask>>=1)
namespace R2C2 {
Track3D::Track3D(Layout3D &l, Track &t):
+ GL::ObjectInstance(l.get_catalogue().get_track(t.get_type()).get_object()),
layout(l),
track(t),
type(layout.get_catalogue().get_track(track.get_type())),
return Point(pos.x+c*center.x-s*center.y, pos.y+s*center.x+c*center.y, pos.z+0.02);
}
-void Track3D::apply_matrix() const
+GL::Matrix Track3D::get_matrix() const
{
const Point &pos = track.get_position();
float rot = track.get_rotation();
- GL::translate(pos.x, pos.y, pos.z);
- GL::rotate(rot*180/M_PI, 0, 0, 1);
- GL::rotate(track.get_slope()/track.get_type().get_total_length()*180/M_PI, 0, -1, 0);
+ GL::Matrix matrix;
+ matrix.translate(pos.x, pos.y, pos.z);
+ matrix.rotate(rot, 0, 0, 1);
+ matrix.rotate(track.get_slope()/track.get_type().get_total_length(), 0, -1, 0);
+
+ return matrix;
}
-void Track3D::render(const GL::Tag &tag) const
+void Track3D::setup_render(const GL::Tag &) const
{
- GL::PushMatrix push_mat;
-
- apply_matrix();
-
+ GL::MatrixStack::modelview().push();
+ GL::MatrixStack::modelview() *= get_matrix();
glPushName(reinterpret_cast<unsigned>(this));
+}
- type.render(tag);
-
+void Track3D::finish_render(const GL::Tag &) const
+{
glPopName();
+ GL::MatrixStack::modelview().pop();
}
} // namespace R2C2
#define R2C2_3D_TRACK_H_
#include <list>
-#include <msp/gl/renderable.h>
-#include <msp/gl/vertexarray.h>
-#include <msp/gl/vertexarraybuilder.h>
+#include <msp/gl/matrix.h>
+#include <msp/gl/objectinstance.h>
#include "libr2c2/track.h"
#include "libr2c2/trackpart.h"
#include "object.h"
class Path3D;
class TrackType3D;
-class Track3D: public Object3D, public Msp::GL::Renderable
+class Track3D: public Object3D, public Msp::GL::ObjectInstance
{
private:
Layout3D &layout;
virtual Point get_node() const;
virtual bool is_visible() const { return true; }
- void apply_matrix() const;
- virtual void render(const Msp::GL::Tag &) const;
+ Msp::GL::Matrix get_matrix() const;
+ virtual void setup_render(const Msp::GL::Tag &) const;
+ virtual void finish_render(const Msp::GL::Tag &) const;
};
} // namespace R2C2
#include <algorithm>
#include <cmath>
-#include <msp/gl/meshbuilder.h>
+#include <msp/gl/technique.h>
#include "catalogue.h"
#include "tracktype.h"
namespace R2C2 {
-TrackType3D::TrackType3D(const Catalogue3D &cat3d, const TrackType &tt):
+TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt):
catalogue(cat3d),
- ballast_mesh((GL::NORMAL3, GL::COLOR4_UBYTE, GL::VERTEX3)),
- rail_mesh((GL::NORMAL3, GL::COLOR4_UBYTE, GL::VERTEX3))
+ mesh((GL::NORMAL3, GL::TEXCOORD2, GL::VERTEX3))
{
const Catalogue &cat = cat3d.get_catalogue();
const vector<TrackPart> &parts = tt.get_parts();
{
unsigned index = 0;
- GL::MeshBuilder bld(ballast_mesh);
- bld.color(0.25f, 0.25f, 0.25f);
+ GL::MeshBuilder bld(mesh);
+ bld.texcoord(0.25, 0.5);
for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
build_part(*i, ballast_profile, Point(0, -ballast_min.y), bld, index);
- }
- {
- unsigned index = 0;
- GL::MeshBuilder bld(rail_mesh);
- bld.color(0.85f, 0.85f, 0.85f);
+ bld.texcoord(0.75, 0.5);
float y = ballast_h-rail_min.y;
for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
build_part(*i, rail_profile, Point(-gauge/2-rail_max.x, y), bld, index);
for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
build_part(*i, rail_profile, Point(gauge/2-rail_min.x, y), bld, index);
}
+
+ object.set_mesh(&mesh);
+ object.set_technique(catalogue.get<GL::Technique>(cat.get_track_technique()));
unsigned paths = tt.get_paths();
for(unsigned i=0; paths; ++i, paths>>=1)
{
- GL::Mesh *mesh = 0;
+ GL::Mesh *m = 0;
if(paths&1)
{
- mesh = new GL::Mesh(GL::VERTEX3);
- GL::MeshBuilder bld(*mesh);
+ m = new GL::Mesh(GL::VERTEX3);
+ GL::MeshBuilder bld(*m);
unsigned index = 0;
for(vector<TrackPart>::const_iterator j=parts.begin(); j!=parts.end(); ++j)
if(j->get_path()==i)
build_part(*j, cat.get_path_profile(), Point(0, ballast_h+1.5*rail_h), bld, index);
}
- path_meshes.push_back(mesh);
+ path_meshes.push_back(m);
}
min_z = max_z = border.front().z;
return *path_meshes[p];
}
-void TrackType3D::render(const GL::Tag &tag) const
-{
- if(tag==0)
- {
- catalogue.get_ballast_material().bind();
- ballast_mesh.draw();
- catalogue.get_rail_material().bind();
- rail_mesh.draw();
- }
-}
-
void TrackType3D::build_part(const TrackPart &part, const Profile &profile, const Point &offset, GL::MeshBuilder &bld, unsigned &base_index)
{
float plen = part.get_length();
#include <msp/gl/mesh.h>
#include <msp/gl/meshbuilder.h>
-#include <msp/gl/renderable.h>
+#include <msp/gl/object.h>
#include "libr2c2/profile.h"
#include "libr2c2/tracktype.h"
class Catalogue3D;
-class TrackType3D: public Msp::GL::Renderable
+class TrackType3D
{
private:
- const Catalogue3D &catalogue;
- Msp::GL::Mesh ballast_mesh;
- Msp::GL::Mesh rail_mesh;
+ Catalogue3D &catalogue;
+ Msp::GL::Mesh mesh;
+ Msp::GL::Object object;
std::vector<Msp::GL::Mesh *> path_meshes;
std::vector<Point> border;
float min_z;
float max_z;
public:
- TrackType3D(const Catalogue3D &, const TrackType &);
+ TrackType3D(Catalogue3D &, const TrackType &);
~TrackType3D();
void get_bounds(float, Point &, Point &) const;
+ const Msp::GL::Object &get_object() const { return object; }
const Msp::GL::Mesh &get_path_mesh(unsigned) const;
- virtual void render(const Msp::GL::Tag &) const;
-
private:
void build_part(const TrackPart &, const Profile &, const Point &, Msp::GL::MeshBuilder &, unsigned &);
};
add("scale", &Loader::scale);
add("track", static_cast<void (Loader::*)(unsigned)>(&Loader::track));
add("track", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::track));
+ add("track_technique", &Catalogue::track_technique);
add("vehicle", static_cast<void (Loader::*)(unsigned)>(&Loader::vehicle));
add("vehicle", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::vehicle));
}
Profile rail_profile;
Profile ballast_profile;
Profile path_profile;
+ std::string track_technique;
TrackMap tracks;
VehicleMap vehicles;
Layout layout;
const Profile &get_rail_profile() const { return rail_profile; }
const Profile &get_ballast_profile() const { return ballast_profile; }
const Profile &get_path_profile() const { return path_profile; }
+ const std::string &get_track_technique() const { return track_technique; }
void add_track(TrackType &);
const TrackType &get_track(const ArticleNumber &) const;
point -20.0 0.0;
};
+track_technique "track.technique";
+
// Straight
track 24064