[gameprogrammer] Re: Scaling Object By Z axis in 2D
- From: Husam Zakaria <hzcppff@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Sat, 21 May 2011 21:34:02 +0300
Well, my little knowledge is this:
let's say that the screen size is 800x600
if we have a point(x, y) in the screen space I mean x is from 0 to 800
and y from 0 to 600
then we can transform the value of x to the [-1,+1] values and y to
the [-1,+1] values, after that we shall give z a value of zero
now we have a point (x, y, z) were values of x is in [-1, +1] and
values of y in [-1,+1] and value of z is zero.
if we transform the last 3d point with the invert of the projection
matrix then we shall have the point in the 3d view space (camera
space) and exactly in the middle plane of the frustum of the view
camera because we have given z a value of zero.
so if we give z a value of -1 then the result point will be in the
near frustum plane of the camera and if we give z a value of +1 the
result point will be in the far frustum plane and so on.
I guess that you have to transform back the edges points of your 2d
shapes to the view space and then you can extrude them in the view
space, and then you transform the new points from the extrusion to the
projection space and then to screen space.
by the way sorry for my bad English specially in math concepts.
On 5/21/11, Alan Wolfe <alan.wolfe@xxxxxxxxx> wrote:
> Hey Agha,
>
> Back before directx and opengl and 3d accelerating video cards you
> used to have to do the 3d to 2d conversion by hand.
>
> You could still use matrices much like they are used today, but back
> then my math sucked so i had a simpler equation that i think should
> help you in this situation :P
>
> Basically it went like this:
>
> X2d = X3d / Z3d
> Y2d = Y3d / Z3d
>
> If you use that equation to transform 3d points into 2d points, then
> render the points in 2d, it looks correct (ie it has perspective etc).
> I made a couple wireframe and flat shaded poly games back in the day
> using that technique :P
>
> Those equations assume 0,0 is the center of your screen though, so
> you'll have to adjust the equations slightly if it isn't such as below
> (which assumes 0,0 is the upper left corner)
>
> X2d = X3d / Z3d + ScreenHalfWidth
> Y2d = Y3d / Z3d + ScreenHalfHeight
>
> Also, if you don't like the perspective transformation that it gives
> you, you can play around with this:
>
> X2d = X3d / Z3d * SomeConstant
> Y2d = Y3d / Z3d * SomeConstant
>
> To put it all together
>
> X2d = X3d / Z3d * SomeConstant + ScreenHalfWidth
> Y2d = Y3d / Z3d * SomeConstant + ScreenHalfHeight
>
> The more complexities you start adding to this transform though, the
> more and more the equation will resemble the math of using a matrix
> though, so there comes a point when you might as well just do that.
>
> For your situation, the above equations should probably work just fine
> it sounds like though, since you aren't doing a full generic 3d scene,
> you are just scaling 2d objects to give the illusion that they are
> getting closer or farther
>
> Hope this helps!
>
> On Sat, May 21, 2011 at 8:45 AM, Robbert de Groot <zekaric@xxxxxxxx> wrote:
>> This page talks about scaling matrix.
>>
>> http://en.wikipedia.org/wiki/Scaling_%28geometry%29
>>
>> But I'm not sure what you are trying to accomplish. A 2D image has not
>> depth information unless you assign some depth in some way to a pixel in
>> the image. So no scaling matrix will do anything unless you have some
>> logic for that. And if you do, and you are using some 3D rendering
>> library, you'll need to create a piece of geometry like triangles or
>> individual pieces of geometry for the pixels to dictate the z direction.
>>
>> Robbert de Groot
>>
>> --- On Sat, 5/21/11, Agha Usman Ahmed <aghausman@xxxxxxxxx> wrote:
>>
>> From: Agha Usman Ahmed <aghausman@xxxxxxxxx>
>>
>> I am working on a 2D image where I have X and Y axis now I want to
>> simulate Z axis by scaling the size of objects in image. but I am stuck
>> with the calculation. I don't know how to scale the objects based on
>> Z-Axis. I red this http://en.wikipedia.org/wiki/Transformation_matrix link
>> but didn't proof very helpful.
>>
>>
>> Can anyone of you forward me to the right direction. I think I have
>> successfully put my question on this email but if there is some thing
>> missing please let me know .
>>
>>
>>
>>
>>
>>
>>
>>
>> Regards,
>>
>> Agha Usman Ahmed
>> Sr . Software Engineer
>> Personal Blog | Official Blog
>>
>>
>>
>>
>>
>>
>>
>>
>> ---------------------
>> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>>
>>
>>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
Other related posts: