   Catmull Rom in Shmups
  Hi guys, hope this is the right forum.I have a quick question about catmull-rom interpolation. I've read the posts in this site and I've figured out how to interpolate using 4 control points and 1 parameter (I'm using D3DXVec2CatmullRom from d3dx). The point is: how should I use this interpolation to move my objects? (ships, bullets, camera, whatever). Given a default set of points which compose a full path I can use CatmullRom to compute new intermediate points between the fixed ones, but what's next?Since I'm able to move an object over a straight line, I would try to move my object between a fixed point and an intermediate (computed with catmullrom) and so on. But doing so I fear it will not have a "smooth" effect and moreover using the interpolation would be useless since I would simply use the fixed points of my waypoint.Hope someone can answer or redirect me. I've read a lot but they just explain how to compute new points and give no clues on what's next.thanksdav   
  If you think about how you would do interpolation and movement along a linestrip (a collection of connected segment points), then the mental leap to splines should be relatively easy. You could always decompose your spline into many segments, and travel using linear interpolation between segments. There is a catch with parametric curves, using their parametric form, you will not achieve a consistent speed, but that's another matter.   ;Quote:Original post by oliiiIf you think about how you would do interpolation and movement along a linestrip (a collection of connected segment points), then the mental leap to splines should be relatively easy. You could always decompose your spline into many segments, and travel using linear interpolation between segments.So you would suggest to set a fixed amount of points describing a curve, interpolate among them to obtain smaller segments and move over these segments?Quote:Original post by oliiiThere is a catch with parametric curves, using their parametric form, you will not achieve a consistent speed, but that's another matter.what do you mean?thanks for your time 8);  he means the distance from 0.0->0.1 could be different than the disatnce from 0.1->0.2 depending on the curve;  everything sounds a bit confusing :P I'll not take in account parametric functions to make things simpler, but still I'm not quite sure how to use catmull-rom or any other interpolation to move objects. D3DXVECTOR2 direction = origin - target;D3DXVec2Normalize(&direction, &direction);return (direction*speed);then I sum/subtract that returned value to my actualPosition and everything moves correctly. How can catmull rom help me?   ;  Assuming a typical 2-d shooter in which enemies follow specific attack patterns (which I assume is what you have in mind), it would probably work to simply compute the entity's position (and orientation, if desired) directly from the spline on a per-update basis.Regarding arc-length reparameterization, it may be that you can do without it (you could set up your paths so that the linear speed remains more or less consistent, or just let the changes in speed be a natural part of the attack pattern).That leaves you with the simple task of interpolating along the spline over time. In this context, the speed of the entity would not be its linear speed in 2-d space, but rather its speed in parameteric space.For example, say the spline runs from t = 0 to t = 1. If you wanted it to take the entity 5 seconds to traverse the length of the spline, you would use a parametric speed of .2. The logic for updating the entity with respect to the spline might look something like this:entity.spline_t += entity.t_speed * delta_time;entity.position = compute_position(entity.spline, entity.spline_t);;  what oliii means by "not having constant speed" is like so:Let's say you have an interpolated spline (using whatever flavor you want), and it's nodes are like this:0--1----2------------------------3-----4Parametrically, this spline goes from 0.0 to 4.0. However, you can clearly see the geometric distance between 0..1 is different than the distance between 1..2. If you did a simple loop to "move" something down the spline, it produces problems:// psuedocodefor ( i = 0.0; i < 4.0; i += 0.05 ) {   vector = spline->ValueAt(i);   // do whatever   }That means you end up going through 0..1 at exactly the same rate (parametrically) as you go through 1..2. but NOT geometrically. If this was a camera gliding down the path, for instance, you would notice the camera moving slow along 0..1 segment and then instantly pick up speed when it got passed 1.0 and through 2.0, then it would change speed again after 2.0, even though the path itself is continuous.That's something you need to watch out for if you intend to implement this as paths for objects in your game. For a schmup, i think it would probably be better to give moving objects a simple velocity vector and then change that vector according some simple rules. Now the RULES can be spline-based for interesting effect.   ;  you guys are wonderful :O!Quote:Original post by leiavoiaThat means you end up going through 0..1 at exactly the same rate (parametrically) as you go through 1..2. but NOT geometrically. If this was a camera gliding down the path, for instance, you would notice the camera moving slow along 0..1 segment and then instantly pick up speed when it got passed 1.0 and through 2.0, then it would change speed again after 2.0, even though the path itself is continuous.that's something i've noticed at first. To avoid this I sampled the fixed points at constant rate, but... this is just a little demo and i can pick up every vector I need... I'll think about this later :PQuote:Original post by leiavoiaFor a schmup, i think it would probably be better to give moving objects a simple velocity vector and then change that vector according some simple rules. Now the RULES can be spline-based for interesting effect.with "velocity vector" you refer to something like my previous code where you give a direction and a speed value and just update each frame? And, please, would you be more specific on "splined-based rules"? I think that's exactly what I'm looking for. (I've been a lot confusing in this post, sorry :P)Quote:Original post by jykAssuming a typical 2-d shooter in which enemies follow specific attack patterns (which I assume is what you have in mind), it would probably work to simply compute the entity's position (and orientation, if desired) directly from the spline on a per-update basis.yes, that's what I have in mind. But again, what's per-update basis spline?can you please give a very short example (note even code)? thanks againdav;Quote:Original post by davj88Quote:Original post by leiavoiaFor a schmup, i think it would probably be better to give moving objects a simple velocity vector and then change that vector according some simple rules. Now the RULES can be spline-based for interesting effect.with "velocity vector" you refer to something like my previous code where you give a direction and a speed value and just update each frame? And, please, would you be more specific on "splined-based rules"? I think that's exactly what I'm looking for. (I've been a lot confusing in this post, sorry :P)Well, keep in mind that a spline need not represent a physical path in space. All it represents is a curve in 1 or more dimensions (and not necessarily dimensions of space). Why would you need a 1-D curve? Consider:Let's say i have a "flashing light". This light is a variable-brightness dimmer sort of light. It can be moved between 0 (full off) and 1 (full on). Now, lets say you want this light to flash in some rather complex pattern: blink, blink, [pause], blink blink.so you might make a 1-D "curve" like so (numbers are brightness values):0-----0--1--0-----0--1--0-------------0--1--0-----0--1--0-----0With this pattern, you end up with a flashing light that "blinks" in a complex pattern that you directly program as a spline! However, it isn't a hard on/off blink, it will ramp smoothly between off and on.Now... you can use that same idea to create an "actuator" or whatever than can affect the movement of an object. Instead of using the value directly as a speed, you could possibly use it to modify the speed.Of course, you could also use it directly. Sometimes smooth speed doesn't matter. Example:Since, we're talking about shmups, let's talk about the greatest shmup ever: Ikaruga.I'm pretty sure the homing lasers (pictured) are spline-based. I notice that they move faster comming out of the front of the ship than the ones in the back do. The also accelerate as they travel long distances. And they have to hit a specific target. That's pretty hard to do using just a velocity vector.But do i care? No! They move really fast anyway. I mean 0.8 seconds to zip from one side of the screen to the other means i won't notice changes in speed. As long as it hits its intended target, i'm pretty happy.Also, as jyk pointed out, you can get around the reparameterization issues if the movement of objects need not be mathmatically accurate. If you space the nodes at regular intervals, it *looks* fairly decent.   ;Quote:Original post by leiavoiaNow... you can use that same idea to create an "actuator" or whatever than can affect the movement of an object. Instead of using the value directly as a speed, you could possibly use it to modify the speed.Maybe, I'm starting to understand. I'm not going to use spline to "draw" the entire movement path but instead I can use the spline (and its values) to modify the behaviour in terms of speed, angle, whatever I may need. (that's what I've figured out).Quote:Original post by leiavoiaSince, we're talking about shmups, let's talk about the greatest shmup ever: Ikaruga.I love you!Quote:Original post by leiavoiaI'm pretty sure the homing lasers (pictured) are spline-based. I notice that they move faster comming out of the front of the ship than the ones in the back do. The also accelerate as they travel long distances. And they have to hit a specific target. That's pretty hard to do using just a velocity vector.But do i care? No! They move really fast anyway. I mean 0.8 seconds to zip from one side of the screen to the other means i won't notice changes in speed. As long as it hits its intended target, i'm pretty happy.to sum up, to "draw" the lasers I'd use vectors but I'd modify these vectors parameters on a spline-base.Quote:Original post by leiavoiaAlso, as jyk pointed out, you can get around the reparameterization issues if the movement of objects need not be mathmatically accurate. If you space the nodes at regular intervals, it *looks* fairly decent.That's what I'll try to do :PThanks for the wonderful reply! Still looking for some tips but I'm pretty much satisfied now.dav