POV-Ray : Newsgroups : povray.general : Please Help with coding problem! (long post) : Please Help with coding problem! (long post) Server Time
12 Aug 2024 21:18:43 EDT (-0400)
  Please Help with coding problem! (long post)  
From: Josh English
Date: 7 Jan 1999 22:43:53
Message: <36957FC4.7175D4B9@spiritone.com>
I am working on an animation of a chess game, and one of the Knights is
causing trouble. I want the Knights jump to be rather comical, so it
gets shorter and fatter, then thins out as it springs up, breaking into
three component parts, flies through the air and lands again a few
squares away.

I had a good jump and made a Quicktime movie out of it which can be seen
at http://www.spiritone.com/~english/sproing.mov. The bad jump is at
http://www.spiritone.com/badsproing.mov. When I started to alter the
shape it moved the piece during the first part of the jump.

here is the code:

#declare JumpPoint = a place on the board;
#declare Target = a nother place n the board
#declare midPoint = a point on the board directly between target and
jumpPoint
#declare roation = rotation value along y axis to align Knight with new
square

/// Use 0 to 1 for clock

#declare anim_clock = clock;

#declare Trans_1 = 0.25; // stop looking and jump
#declare Trans_2 = 0.50; // bounce up
#declare Trans_3 = 0.75; // bounce down

#switch (anim_clock)
#range (0,Trans_1) // normalize to target
   //   rotates the knight to face the direction of the jump
#break

#range(Trans_1,Trans_2) // decelerate up
  // sets to be in normalized range
  #declare temp_clock = (anim_clock - Trans_1) / (Trans_2 - Trans_1);
  #declare bounce_time = 3/7;     // transition between prep and jump

// There are two segments, preparing to jump, and jumping up to the apex
of
// the movement
#switch(temp_clock)
  #range(0,bounce_time)
   // create a new normalized clock variable
    #declare really_temp_clock = temp_clock / bounce_time;

    #declare squish_value = sin(really_temp_clock * pi * 1.5)/5;

    #declare newWidth = 1 + squish_value; // get fatter then thinner
    #declare newHeight =1 - squish_value; // get shorter then taller

    object { base
             pigment { rgb 1 }
             scale <newWidth,newHeight,newWidth>
             rotate rotation
             translate JumpPoint }

    object { body
             pigment { rgb 1 }
             scale <newWidth,newHeight,newWidth>
             rotate rotation
             translate JumpPoint }

    object { knight_head
             pigment { rgb 1 }
             translate (1.2 - squish_value)*y
             rotate rotation
             translate JumpPoint }

  #break

#range (bounce_time,1.001)   ////   ***************** The problem is
here somewhere
   // create a new normalized clock variable
    #declare really_temp_clock = (temp_clock - bounce_time) / (1 -
bounce_time);

    #declare temp_pos = <0,0,-1>;   // begins to setup the position
    #declare jump_clock = pow (really_temp_clock,1/2);
    #declare temp_rot = 90 * x * jump_clock;

    #declare temp_pos = vrotate(really_temp_clock,temp_rot); // move
along jump path
    #declare temp_pos = vrotate(really_temp_clock,rotation);  // rotate
into position
    #declare temp_pos = temp_pos + midPoint; // final placement of parts


    object { base
             pigment { rgb 1 }
             rotate really_temp_clock *15*x
             rotate rotation
             translate temp_pos }

    object { body
             pigment { rgb 1 }
             rotate really_temp_clock *8*x
             rotate rotation
             translate temp_pos * <1,1.25,1> }

    object { knight_head
             pigment { rgb 1 }
             rotate really_temp_clock *-15*x // Nose goes up during
upward movement
             translate 1.2*y
             rotate rotation
             translate temp_pos * <1,1.75,1> }
    #break
  #end
#break

#range(Trans_2,Trans_3) // accerlarate down

  #declare temp_clock = (anim_clock - Trans_2) / (Trans_3 - Trans_2);

  #render concat ("Temp Clock is ",str(temp_clock,3,3))
  #declare temp_pos = <0,0,-1>;
  #declare temp_clock = pow (temp_clock,2);
  #declare temp_rot = ((90*temp_clock)+90)*x;

  #declare temp_pos = vrotate(temp_pos,temp_rot);
  #declare temp_pos = vrotate(temp_pos,rotation);
  #declare temp_pos = temp_pos + midPoint;

  object { base pigment { rgb 1 }
           rotate (15-(temp_clock*15))*x
           rotate rotation
           translate temp_pos }

  object { body pigment { rgb 1 }
           rotate (8-(temp_clock*8))*x
           rotate rotation
           translate temp_pos * <1,1.25,1> }

  object { knight_head
           pigment { rgb 1 }
           rotate (-15+(temp_clock*15))*x
           translate 1.2*y
           rotate rotation
           translate temp_pos * <1,1.75,1> }

#break

#range (Trans_3,1.01) // normalize to target

 // rotate back

#break
#end
-----------------------------------------------------------------------------------------------------------

Now, during the second part of the second segment, is where the problem
lies. It starts the jumpat the midpoint and behaves as if it's rotating
around the target position, then during the third segment, it appears
above the midpoint and rotates around the midpoint down to the target.
The code is exactly the same except that I add 90 degrees to the
rotation. This code also did not change from the successful version
except in the following ways: since I broke the second segment up  with
a second #switch statement, I created the really_temp_clock variable and
used that instead of temp_clock in the first part of that bit of code.
This is the confusing part, and I'm asking if anyone can see the
mistake, since I can't.

Thanks for any aide.

Josh English
eng### [at] spiritonecom
http://www.spiritone.com/~english


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.