Skip to main content
GameDev.net gamedev.net
🔒 Locked

World origin

Started by King_DuckZ Mar 11, 2005 at 6:26 PM 1 replies 950+ views
Original Post
King_DuckZ
King_DuckZ
Hello. I'm writing an editor, which has a perspecive viewport of un unknown size. The window size, and therefore the device size, is 640x480. The same device is used to render on both the top view and the perspective view, every time by switching the render target. The problem is, those render targets can be any size, smaller or bigger than 640x480, and with any aspect ratio. The problem is, when I render on the perspective target, my geometry is centered to the surface. When I load a bitmap as a background, the size of the render target changes according to the bitmap, but the geometry is still rendered at the old center, that is 320x240. How do I update the axis origin, when I change the render target?
[ King_DuckZ out-- ]
King_DuckZ
King_DuckZ
I update the viewport, but... Well, what I need to do is not to move the camera, as 3D Studio and other programs do (I think I forgot to say this, before), but to render everything that falls in the view frustrum, and as big as the render target is, and centered.
I use the viewport as a clipper, since even if the render target is 1000x1000, I only need to show a 320x240 portion to the user.
Basically what I need is to show a portion of the rendered surface.
I'm putting a bitmap rendered with 3D Studio to compare its results with mine, and what I'm experiencing is non-centered geometry, unless the render target is 640x480, and geometry that is smaller than the one rendered in 3D Studio.

Giva a look at this:
http://duckz.altervista.org/graphicz/stageeditor3.jpg
http://duckz.altervista.org/graphicz/stageeditor4.jpg

It works like this:
I put a background to the left viewport, I set my vertices following the path on the background, then the resulting shape is shown in the right viewport. This shape is always centered to the origin, and within (-0.5,0.5)-(0.5,-0.5) in the XZ plane. I did the same in 3D Studio, but as you can see the results are different.

In the first picture the background bitmap (and and the render target) is 640x480, and the shape is well centered, but too small.
In the second picture, the render target is bigger, with a 16:9 ratio, but the shape is still drawn in the old center. Again, it's too small.

This is my initilization code

D3DXMatrixIdentity (&m_matView);
D3DXMatrixPerspectiveFovLH (&m_matProj, D3DX_PI/4.0f, 4.0f/3.0f, 1.0f, 100.0f);
D3DXMatrixLookAtLH (&m_matCam, &m_vEye, &m_vLookAt, &m_vUp);

When I load a new image I just change the aspect ratio for m_matProj.
I don't update the viewport, since it is updated by the rendering functions, which sets it to 320x240 and restores it back to 640x480 before returning.

In conclusion, my rendering is smaller (compared to MAX) and non-centered (compared to the render target). I don't know if those problems are related, but I need to fix both them. Please let me know if I wasn't clear enough.
Can you help me please?
[ King_DuckZ out-- ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.