Plane inside view frustum

Started by
18 comments, last by D3F84U 9 years, 11 months ago

This is an application that renders from 2D buffer on to DirectX. I want to be able to adjust size of the virtual 3D screen showing 2D content to fit DX viewport, maintaining aspect ratio and therefore not always fitting both dimensions.

Virtual screen is at fixed xyz and so far I don't need any other transformations for world expect view and projection

Advertisement


I want to be able to adjust size of the virtual 3D screen showing 2D content to fit DX viewport, maintaining aspect ratio and therefore not always fitting both dimensions.

scaled sprite.

you know w,h for both the sprite (2d content) and screen.

just scale the sprite til its as wide / tall as the screen, whichever comes first.

you can then fake moving it closer or farther in camera space z by further isomorphic scaling.

but as stated above the 3d approach will also work, but is more complex.

as usual with games, there are multiple ways to skin a cat. some are easier to implement than others. some run faster than others. the trick is to try to find the one that is as easy to implement as possible AND runs fast enough.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

just scale the sprite til its as wide / tall as the screen, whichever comes first.

scaling would work if everything was fixed, but both 2D buffer and DX screen change their properties.

just scale the sprite til its as wide / tall as the screen, whichever comes first.

scaling would work if everything was fixed, but both 2D buffer and DX screen change their properties.

I'm not sure if you saw my edit above but i think i found your issue. You were essentially using the view transform twice, so were not in the right space.

However seeing that this is to push a 2d surface onto the screen, it makes sense to just start with 2d coordinates, or coordinates that are pretransformed into normalized device coordinates, which range from -1 to +1 on the x,y,z axii, with +z being the direction away from the camera. By starting with coordinate in NDC space, a full screen quad is simply (-1,1),(1,1)(-1,-1),(1,-1). The vertex shader can be disabled, as there is nothing going on there anyway. During the raster step, your NDC coords will get scaled to the viewport, at which point the pixel shader can map your 2d buffer to the quad.

the trick is to try to find the one that is as easy to implement as possible AND runs fast enough.

The vertex shader can be disabled, as there is nothing going on there anyway. During the raster step, your NDC coords will get scaled to the viewport, at which point the pixel shader can map your 2d buffer to the quad.

I'll try this as soon as I can. DX is still quite new to me...

I ended up leaving everything as is and calculating fixed virtual pixel size factor by trial and error. It is calculated using x dimension if x >= y or using y dimension otherwise multiplied by virtual pixel size factor. viewport and other matrices do the scaling that is always as close to the edge as virtual pixel size is accurate.

I ended up leaving everything as is and calculating fixed virtual pixel size factor by trial and error. It is calculated using x dimension if x >= y or using y dimension otherwise multiplied by virtual pixel size factor. viewport and other matrices do the scaling that is always as close to the edge as virtual pixel size is accurate.

Did you see my post about 6 or 7 up?

When I looked through your code, you were taking the quad the you built, and transforming it by the VP matrix. How ever, this quad was built in view space. so you tried to apply the world to view transform on a plane that was already in viewspace. Your Z pos, of 50, which is almost 1/2 the distance from near to far( 50/99-1) resulting in your quad being 1/2 the screen size give or take, but still following the rule of getting smaller with a greater Z.

Your solution to my original question was on spot. It lead me to conclusion that my assumption that if it is on the edge of view frustum it will be on the edge of the screen was wrong.

Now I'm the confused one, if the quad maps the full height and width of the frustum, it will be the full screen. If you go back to the original setup, and pass just the projection transform when rendering the quad it should map to the full screen.

Your Z pos, of 50, which is almost 1/2 the distance from near to far( 50/99-1) resulting in your quad being 1/2 the screen size

D3DXMatrixPerspectiveFovLH(&Proj, angle, aspect, 1.0f, 100.0f);

or

D3DXMatrixPerspectiveFovLH(&Proj, angle, aspect, 1.0f, 10000.0f);

will draw same quad

that might be an error, but as I see it it just sets clipping.

I changed

WVP = View*Proj; to WVP = Proj;

and only change is a bit larger quad but still not close to full screen.

Whole point is to have full screen quad at any distance withing clip planes.

This topic is closed to new replies.

Advertisement