Jump to content
  • Advertisement
Sign in to follow this  
jamcar

TCB path for Camera. How?

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody. I'm a student from Finland and asking for a solution to a problem, that has bothered me for some time now. I am trying to create a camera "path" for a 3D camera which has its keyframe data(including TCB values) ready and waiting. I am using TCB knowledge found from here: http://www.cubic.org/docs/hermite.htm In my program I have a text output writer, and it tells me the coordinates created by my TCB method. THe problem seems to be, that although some coordinates which I create for the camera "path" are getting closer to the next keyframe coordinate, they don't want to get close enough the next keyframe coordinate. For example, I might have: X Y Z 2.222 2.222 2.222 2.555 2.555 2.555 2.666 2.666 2.666 2.668 2.668 2.668 2.669 2.669 2.669 2.669 2.669 2.669 2.670 2.670 2.670 and then comes the next keyframe, and because we haven't reached it yet, the camera will perform the jump. I want to get rid of this jump. The same jump happens before every keyframe. KEYFRAME: 3.000 3.000 3.000 I have attached my code here, in the following, but it is basically the coded knowledge from the mentioned web-page I've been using. Some of the "path" output can be found here: http://users.tkk.fi/~tjturkki/camera_path.txt The code is messy, and if you have any idea of the things I might be doing now, don't look at the code, but recommend your ideas to me right away ;) Thank you!
for(int t=0; t < 1000; t++)
 {
  gCamera1Frame++;
  
  if(gCamera1Frame ==
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].frame)
  {
   myRos2.GetCamera(0).posnumber++;
   Write_Error("\n");
  }

  if(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+2 <
myRos2.GetCamera(0).poskeys && myRos2.GetCamera(0).posnumber-1 >= 0) 
// to stay within the array
  {
   float s = (float)t / (float)1000;    // scale s to go from 0 to 1
   float h1 =  2*s*s*s - 3*s*s + 1;          // calculate basis
function 1
   float h2 = -2*s*s*s + 3*s*s;              // calculate basis
function 2
   float h3 =   s*s*s - 2*s*s + s;         // calculate basis function
3
   float h4 =   s*s*s -  s*s;              // calculate basis function
4
   
   float tens = myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].tens;
   float cont = myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].bias;
   float bias = myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].cont;

   // outgoing tangent vector
   float T1_x = (1-tens)*(1+cont)*(1+bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].x -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber-1].x) +
(1-tens)*(1-cont)*(1-bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].x -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].x);
   float T1_y = (1-tens)*(1+cont)*(1+bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].y -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber-1].y) +
(1-tens)*(1-cont)*(1-bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].y -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].y);
   float T1_z = (1-tens)*(1+cont)*(1+bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].z -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber-1].z) +
(1-tens)*(1-cont)*(1-bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].z -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].z);

   // incoming tangent vector
   float T2_x = (1-tens)*(1-cont)*(1+bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].x -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].x) +
(1-tens)*(1+cont)*(1-bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+2].x -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].x);
   float T2_y = (1-tens)*(1-cont)*(1+bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].y -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].y) +
(1-tens)*(1+cont)*(1-bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+2].y -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].y);
   float T2_z = (1-tens)*(1-cont)*(1+bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].z -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].z) +
(1-tens)*(1+cont)*(1-bias)/2 *
(myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+2].z -
myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].z);

   gCam1Points[t].SetX(h1*myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].x
+                    // multiply and sum all funtions
      h2*myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].x
+                    // together to build the interpolated
      h3*T1_x +                                                  //
point along the curve.
      h4*T2_x);

   gCam1Points[t].SetY(h1*myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].y
+                    // multiply and sum all funtions
      h2*myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].y
+                    // together to build the interpolated
      h3*T1_y +                                                  //
point along the curve.
      h4*T2_y);
                         
   gCam1Points[t].SetZ(h1*myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber].z
+                    // multiply and sum all funtions
      h2*myRos2.GetCamera(0).poslist[myRos2.GetCamera(0).posnumber+1].z
+                    // together to build the interpolated
      h3*T1_z +                                                  //
point along the curve.
      h4*T2_z);

[edit: using
 tags is a great way to paste lots of code - Superpig]</small>
[Edited by - superpig on May 14, 2005 6:49:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!