Adventure Game Studio

Community => General Discussion => Topic started by: matt on Thu 29/01/2009 08:12:30

Title: 3d maths
Post by: matt on Thu 29/01/2009 08:12:30
on my current game i need to have a 3d objects size i have got the distance and akk of that info but i need the ratio for it to scale at.
Title: Re: 3d maths
Post by: IndieBoy on Thu 29/01/2009 10:29:37
Can you rephrase that? I don't understand what you are asking at all.
Title: Re: 3d maths
Post by: paolo on Thu 29/01/2009 13:27:35
Well, AGS has built-in scaling for walkable areas (and regions too? I don't remember) so you can just say "scale my object to 20% at the top of the walkable area and 100% at the bottom", and then characters that walk on that area get scaled depending on how far up the area they are.

If this isn't what you need, and you simply mean how do you scale a 3D object to the right size depending on the distance away, the maths is very simple:

scaled size = object size / distance

where "distance" is how far back the object is along a line pointing into the screen at right angles to it.

Be careful you don't divide by zero, because this won't work. It's probably better to use a revised form of this equation instead:

scaled size = object size / (distance + 1)

where distance = 0 when the object is as close as it can be, at which point it will be drawn full size. If you don't want it full size at this point, you can multiply by a scale factor (experiment until you get the value that works best for you - the number must be greater than 0; less than 1 will make your object smaller; greater than 1 will make it bigger):

scaled size = scale factor * object size / (distance + 1)

I hope that helps.

Title: Re: 3d maths
Post by: Oliwerko on Thu 29/01/2009 14:30:09
Please, matt, use capital letters and punctuation.
Title: Re: 3d maths
Post by: matt on Fri 30/01/2009 01:57:40
Thanks for the tip of the scale factor but I know about the scripting side of it alreadybut the actual factor is what I am looking for.
Title: Re: 3d maths
Post by: Khris on Fri 30/01/2009 02:24:05
There's no "actual factor", as soon as a 3D point has been transformed into the camera's coordinate system, getting its 2D equivalent is calculated exactly as paolo says: (2d_x; 2d_y) = (3d_x / 3d_z; 3d_y / 3d_z)

What doesn't work? Consider showing us a screen shot.