> Anceschi Mauro wrote:
>
> Hi.
> I have a little problem in my 3D space game.
> When my ship "fire" from a cannon i use a new local axis for the new
> object i'm firing , for calculate the next point of the laser.
> But this works bad, and i don't have much precision.
> So my question is:
> How can interpolate from 2 point in 3d?
> (x,y,z) and (x',y',z') (suppose the second is an enemy ship).
>
> Thanks,
>
> mauro
Hi,
What you could do is use a simple parametric equation.
for t=0.0 to 1.0
currentpoint = point0 + (point1-point0)*t;
where point0 = (x,y,z) and
point1 = (x',y',z')
when t = 0.0, you are at (x,y,z)
when t = 1.0, you are at (x',y',z')
when t = 0.5, you are half way between.
It can be broken down into:
newx = x + (x'-x)*t;
newy = y + (y'-y)*t;
newz = z + (z'-z)*t;
Hope that helps.
What you can do is depend t on your framerate to get a consistant
velocity.
This is effectively giving you a velocity of (point1-point0) per second.
That's my answer without telling you to do something completely
different like having a given velocity for your cannonfire and yadda
yadda, etc...
- Ray
ra...@gu...
|