Пример #1
0
//-----------------------------------------------------------------------------
// build a surface 
void Wreck::buildSurface(
  mgBezier& bodySpline,
  double bodyScale,
  int bodySteps,
  mgBezier& lenSpline,
  double lenScale,
  int lenSteps,
  const mgMatrix4& xform,
  BOOL outwards,
  int texture)
{
  double bodyLen = bodySpline.getLength();
  double lenLen = lenSpline.getLength();

  mgVertexTA* points = new mgVertexTA[(bodySteps+1) * (lenSteps+1)];

  mgPoint3 lenPt, bodyPt, xpt;
  for (int i = 0; i <= lenSteps; i++)
  {
    lenSpline.splinePt((lenLen * i)/lenSteps, lenPt);
    double ht = lenPt.y - lenPt.z;
    for (int j = 0; j <= bodySteps; j++)
    {
      bodySpline.splinePt((bodyLen * j)/bodySteps, bodyPt);

      mgVertexTA* v = &points[i*(bodySteps+1)+j];
      mgPoint3 pt(lenScale * (ht * bodyScale * bodyPt.x), 
                  lenScale * (lenPt.z + ht * bodyScale * bodyPt.y), 
                  lenScale * lenPt.x);
      xform.mapPt(pt, xpt);
      v->setPoint(xpt.x, xpt.y, xpt.z);

      v->setTexture(2*j/(double) bodySteps, 2*i/(double) lenSteps, texture);
    }
  }

  // set all the normals
  setNormals(points, lenSteps+1, bodySteps+1, outwards);

  int vertexBase = m_vertexes->getLength();
  for (int i = 0; i < (lenSteps+1)*(bodySteps+1); i++)
    m_vertexes->addVertex(&points[i]);

  m_indexes->addGrid(vertexBase, bodySteps+1, lenSteps, bodySteps, outwards);

  delete points;
}
Пример #2
0
//-----------------------------------------------------------------------------
// find x value on spline
double Tower::findSplineX(
  mgBezier& spline,
  double target,
  int count,
  double dist)
{
  mgPoint3 pt;
  double step = dist;
  for (int i = 0; i < count; i++)
  {
    spline.splinePt(dist, pt);
    if (pt.x > target)
      dist -= step;
    else if (pt.x < target)
      dist += step;
    else break;  // if equal 
    step /= 2;
  }
  return dist;
}