Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Edgar_Herrera, VoroneTZ, Akow), 973 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Smooth vec_lerp #481313
08/25/20 23:42
08/25/20 23:42
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Is there a way to smooth out a vec_lerp calculation, so the rate at which one vector moves towards the other is at a consistent pace?

Right now, it moves very quickly at first, then it slows down as it approaches the other.

I am thinking the "factor" could somehow be adjusted based on the difference between the two vectors, but I have no earthly idea how to accomplish that.

Re: Smooth vec_lerp [Re: Dooley] #481315
08/26/20 05:33
08/26/20 05:33
Joined: Aug 2020
Posts: 2
K
kumarwaar Offline
Guest
kumarwaar  Offline
Guest
K

Joined: Aug 2020
Posts: 2
Nice Information

Re: Smooth vec_lerp [Re: Dooley] #481317
08/26/20 07:51
08/26/20 07:51
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
'vec_accelerate' is the function you need.

You can also write your own function. Something like the following:

Code
BOOL vec_move_to(VECTOR *vFrom, VECTOR *vTo, var speed) // It returns TRUE upon arrival, otherway returns FALSE
{
   VECTOR vRay;
   vec_diff(&vRay, vTo, vFrom); // Get movement ray
   if(abs(vRay.x) + abs(vRay.y) + abs(vRay.z) == 0) // Early return on null rays
      return TRUE;
   
   var length = vec_length(&vRay); // Get ray length
   var step = abs(speed) * time_step; // Get movement step with negative speed guard
   if(length > step) // If the ray is longer than the step
   {
      vec_scale(&vRay, step / length); // Shorten the ray to the length of the step. WARNING: The result of the division of the factor can be zero on low speeds or high frame rates.
      vec_add(vFrom, &vRay); // Add the result to the origin vector

      return FALSE;
   }
   
   // Otherway, the ray is shorter or equal to the step
   vec_set(&vFrom, vTo); // Copy vTo into vFrom

   return TRUE;
}


Salud!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1