I have this waypoint based camera system where users can set waypoints and hit play, and then the camera will move in a spline between each of these waypoints.
the code goes like this:
====================================================
Clarification:
p0x = Start Position
p1x = Tangent
p2x = Tangent
p3x = End Position
$i = the step, when $i is 1.0 the point will be p3x
====================================================
"position X" =(1-$i)^3 * $p0x + 3*(1-$i)^2 * $i * $p1x + 3*(1-$i)* $i^2 * $p2x + $i^3 * $p3x)
"position Y" =(1-$i)^3 * $p0y + 3*(1-$i)^2 * $i * $p1y + 3*(1-$i)* $i^2 * $p2y + $i^3 * $p3y)
"position Z" = (1-$i)^3 * $p0z + 3*(1-$i)^2 * $i * $p1z + 3*(1-$i)* $i^2 * $p2z + $i^3 * $p3z)
and same goes for the pitch, roll and yaw...
now the problem here is that this math does not take into account that points have variable distance between eachother.
So if 2 points are close to eachother the camera will move slow, and if they are far from eachother it will move fast.
Question:
How can i make this equation so that the camera will always maintain a constant speed no matter what the distance is between the 2 points is?
Smooth Cubic Pathing?
"Reparametize" your spline. ie. base it on distance instead of time.
The easiest way to do that is to sample your spline with really small "t" intervals and calculate if the distance is above your needed speed. If not go on else store the point in an array. Do this to all your points and you'll soon get a uniformly distanced spline.
http://www.shmup-dev.com/forum/index.php/topic,1638.0.html
A different way to do this is here (I made it in Freebasic but it would still be readable)
http://www.freebasic.net/forum/viewtopic.php?t=16874
The easiest way to do that is to sample your spline with really small "t" intervals and calculate if the distance is above your needed speed. If not go on else store the point in an array. Do this to all your points and you'll soon get a uniformly distanced spline.
http://www.shmup-dev.com/forum/index.php/topic,1638.0.html
A different way to do this is here (I made it in Freebasic but it would still be readable)
http://www.freebasic.net/forum/viewtopic.php?t=16874
Quote:Original post by relsoft
"Reparametize" your spline. ie. base it on distance instead of time.
The easiest way to do that is to sample your spline with really small "t" intervals and calculate if the distance is above your needed speed. If not go on else store the point in an array. Do this to all your points and you'll soon get a uniformly distanced spline.
http://www.shmup-dev.com/forum/index.php/topic,1638.0.html
A different way to do this is here (I made it in Freebasic but it would still be readable)
http://www.freebasic.net/forum/viewtopic.php?t=16874
My math is pretty horrible, i don't quite see what he ment with the:
t = t0 + ((a - a0) / (a1 - a0)) * (t1 - t0) )
He say (a) is the actual arch length but then i don't get what (a0) and (a1) is suppose to be, let alone (t0) and (t1)
It's standard linear interpolation equation. It "lerps" between 2 values.
Try the one I made using freebasic. It does not use lerping since it's just a straight array look-up.
Try the one I made using freebasic. It does not use lerping since it's just a straight array look-up.
Sorry, it was kind of late last night s I wasn't able to give you a good description.
a = supposed linear distance of your camera
t = time value in a spline
a0 = actual distance array value less than "a" in your table
a1 = actual distance array value greater than "a" in your table
t0 = actual time array value less than "t" in your table
t1 = actual time array value greater than "t" in your table
So assuming you have a spline() function...
Should do the trick.
t = t0 + ((a - a0) / (a1 - a0)) * (t1 - t0) )
a = supposed linear distance of your camera
t = time value in a spline
a0 = actual distance array value less than "a" in your table
a1 = actual distance array value greater than "a" in your table
t0 = actual time array value less than "t" in your table
t1 = actual time array value greater than "t" in your table
So assuming you have a spline() function...
t = t0 + ((a - a0) / (a1 - a0)) * (t1 - t0) )vector2d p= spline(t);
Should do the trick.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement