예제 #1
0
void SplineTrack::merge(IMeshBufferPtr buf) const
{
   Vector<float> off = make_vector(
      static_cast<float>(origin.x),
      height,
      static_cast<float>(origin.y));

   buf->merge(rail_buf, off, 0.0f);

   // Draw the sleepers

   const float sleeper_sep = 0.25f;

   float delta = 0;
   int n = 0;
   do {
      ++n;
      delta = ((curve.length - sleeper_sep) / n) - sleeper_sep;
   } while (delta > sleeper_sep / n);

   for (int i = 0; i <= n; i++) {
      float pos = (sleeper_sep / 2) + i * (sleeper_sep + delta);

      float u_curve_delta;
      Vector<float> v = curve.linear(pos / curve.length, &u_curve_delta);

      const Vector<float> deriv = curve.deriv(u_curve_delta);
      const float angle =
         rad_to_deg<float>(atanf(deriv.z / deriv.x));

      merge_sleeper(buf, off + v, -angle);
   }
}
예제 #2
0
void SlopeTrack::merge(IMeshBufferPtr buf) const
{
   Vector<float> off = make_vector(
      static_cast<float>(origin.x),
      height,
      static_cast<float>(origin.y));

   float y_angle = axis == axis::Y ? -90.0f : 0.0f;

   off += rotateY(make_vector(-0.5f, 0.0f, 0.0f), y_angle);

   buf->merge(rail_buf, off, y_angle);

   // Draw the sleepers
   for (float t = 0.1f; t < 1.0f; t += 0.25f) {
      float u_curve_value;
      const Vector<float> curve_value = curve.linear(t, &u_curve_value);

#if 0
      // Should the sleepers be at the same angle as the slope?
      const Vector<float> deriv = curve.deriv(u_curve_value);
      const float angle =
         rad_to_deg<float>(atanf(deriv.y / deriv.x));
#endif

      Vector<float> v = make_vector(curve_value.x, curve_value.y, 0.0f);

      merge_sleeper(buf, off + rotateY(v, y_angle), y_angle);
   }
}
예제 #3
0
파일: Points.cpp 프로젝트: nickg/traingame
void Points::merge(IMeshBufferPtr buf) const
{
   static IMeshBufferPtr rail_buf = make_bezier_rail_mesh(my_curve);
   static IMeshBufferPtr reflect_buf = make_bezier_rail_mesh(my_reflected_curve);

   VectorF off = make_vector_f(myX, height, myY);

   float y_angle = 0.0f;

   if (my_axis == -axis::X)
      y_angle = 180.0f;
   else if (my_axis == -axis::Y)
      y_angle = 90.0f;
   else if (my_axis == axis::Y)
      y_angle = 270.0f;

   // Render the rails

   buf->merge(reflected ? reflect_buf : rail_buf,
      off + rotateY(make_vector(-0.5f, 0.0f, 0.0f), y_angle),
      y_angle);

   {
      VectorF t = off;

      for (int i = 0; i < 3; i++) {
         const float a = y_angle + 90.0f;
         merge_straight_rail(buf, t, a);

         t += rotateY(make_vector(0.0f, 0.0f, 1.0f), a);
      }
   }

   // Draw the curved sleepers
   for (float i = 0.25f; i < 1.0f; i += 0.08f) {
      float u_i;
      const BezierCurve<float>& c = reflected ? my_reflected_curve : my_curve;
      const VectorF v = c.linear(i, &u_i);

      const VectorF t = make_vector(v.x - 0.5f, 0.0f, v.z);
      const VectorF soff = off + rotateY(t, y_angle);
      const VectorF deriv =
         (reflected ? my_reflected_curve : my_curve).deriv(u_i);
      const float angle =
         rad_to_deg<float>(atanf(deriv.z / deriv.x));

      merge_sleeper(buf, soff, y_angle - angle);
   }

   // Draw the straight sleepers
   off -= rotateY(make_vector(0.4f, 0.0f, 0.0f), y_angle);

   for (int i = 0; i < 12; i++) {
      merge_sleeper(buf, off, y_angle);
      off += rotateY(make_vector(0.25f, 0.0f, 0.0f), y_angle);
   }
}