Game Development Community

Arrows for path spline in world editor

by Jason Toubia · in Torque Game Engine · 06/29/2004 (6:46 am) · 3 replies

Hello,

This is in regards to the World editor when the rendersplines() is called. I am trying to figure out how to get the arrows to draw according to their current rotation as opposed to the just being drawn at their current location. Why? Cause I'm goofy like that and I am trying to learn opengl programming in order to do a semi-related hack.

Here is the code that does the drawing for each of the splines for the path markers.

while (t < size - 1)
   {
      CameraSpline::Knot k;
      spline.value(t, &k); 
      t = spline.advanceDist(t, 2.0f);

      VectorF a(-0.15f, -0.25f, 0.0f);
      VectorF b( 0.0f,  0.25f, 0.0f);
      VectorF c( 0.15f, -0.25f, 0.0f);
      VectorF t1, t2, t3;

      k.mRotation.mulP(a, &t1); t1 += k.mPosition;
      k.mRotation.mulP(b, &t2); t2 += k.mPosition;
      k.mRotation.mulP(c, &t3); t3 += k.mPosition;

      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glColor4f(0, 1, 0, 1);
      glLineWidth(1);
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glBegin(GL_POLYGON);
      glVertex3f(t1.x, t1.y, t1.z);
      glVertex3f(t2.x, t2.y, t2.z);
      glVertex3f(t3.x, t3.y, t3.z);
      glEnd();

      // FILL
      glColor4f(0, 2, 0, 0.2);
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

      glBegin(GL_TRIANGLES);
      glVertex3f(t1.x, t1.y, t1.z);
      glVertex3f(t2.x, t2.y, t2.z);
      glVertex3f(t3.x, t3.y, t3.z);
      glEnd();
      glDisable(GL_BLEND);
}

Would I want to use glRotatef and if so, how do I retrieve the current rotation of the spline or should make a vector based of the next splines position? It appears that rotation information is there, but I just can't seem to get it to rotate.

Any help would be greatly appreciated!

Thanks

#1
06/29/2004 (6:57 am)
They do draw according to their current rotation. That is why the following code exists:
VectorF a(-0.15f, -0.25f, 0.0f);
      VectorF b( 0.0f,  0.25f, 0.0f);
      VectorF c( 0.15f, -0.25f, 0.0f);
      VectorF t1, t2, t3;

      k.mRotation.mulP(a, &t1); t1 += k.mPosition;
      k.mRotation.mulP(b, &t2); t2 += k.mPosition;
      k.mRotation.mulP(c, &t3); t3 += k.mPosition;

The VectorF's are the points of the "wedge", relative to the wedge's origin (0,0,0) in local coordinates. Then it applies world rotation, and translation of the path-knot to the three points to orient the "wedge" object along the path.

Try making the wedge a little bigger and you'll see what I mean:
VectorF a(-0.50f, -0.75f, 0.0f);
      VectorF b( 0.0f,  0.75f, 0.0f);
      VectorF c( 0.50f, -0.75f, 0.0f);

- Brett

Edit: Whew.. took me 5 tries to get the wording right!
#2
06/29/2004 (7:06 am)
Well, I figured that the above is what applys the position and rotation, however, my arrows always point north. So I was figuring that the spline.value was returning the mRotation as 0 and that is why they weren't rotating. If yours is pointing fine, then I guess I just need to figure out why mine isn't. They weren't even pointing correctly before I opened up worldeditor.cc.

Just goes to show, I can screw things up without even touching it. I'm just that good.
Thanks
#3
06/29/2004 (7:48 am)
Man, I need sleep. Looking at my question now, I realize it doesn't even make sense. It is returning a rotation value which is calculated based on the rotation of the path markers, not next knots. I guess I just assumed that when it calculated the spline path, it was supposed to calculate the rotations for the spline knots to point towards the next knot. Oh well, I'm glad thats the result. Makes things a ton easier. Sorry for wasting forum space all.