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

Viewspace unit

Started by KalleKlovn Apr 18, 2006 at 5:16 AM 7 replies 700+ views
Original Post
KalleKlovn
KalleKlovn
Hi, How can I set up my view space so that the screen is 100 units wide?
Evil Steve
Evil Steve
Is there a reason you don't want to set the backbuffer size to 100x100?
KalleKlovn
KalleKlovn
Maybe I need to explain a little better. I use the direct3d sample framework. When I run the empty_project sample the screen is less than 10 units wide I think (I don't rembember, because it isn't important). How can I change the size of it, making it 100 units wide? I know I can zoom out the camera to make it wider, but thats not what I want. I have a mesh which is 10 units wide and I want to make room for 10 of these on the screen at the same time. I think the question I'm asking is how to define what a unit is? Meter, centimeter, millimeter, inch ... Maybe settings the size of the backbuffer is the answer to this, but I don't understand how. Can you explain?
Evil Steve
Evil Steve
1 unit is always 1 unit. You can move the camera back to fit more on the screen, or you can position your objects further into the screen.
If you have 10 objects that are 10 units wide, you need to move the camera back to see them all. The only other way would be to use a larger FOV for the projection matrix, but that'll cause distortion.

If you can only fit 50m wide on to a view with a camera in real life. The only way around that is to use a fisheye lens (change FOV) or move the camera back to fit more onscreen. Changing what 1 unit represents won't help. If you can only fit 50cm onscreen, and each object is 10cm wide, it still doesn't help.

I'm useless at explaining things [smile]
KalleKlovn
KalleKlovn
I think I understand. Thank you. The model I'm loading is about 50x50x50 cm in the 3d modeling program, but when I load it into direct3d it's about 10 units wide. 1 unit is then 5 cm. Can I change this. I want my model to be 1 unit wide. I know I can scale it when rendering it, but is this the only way?
Evil Steve
Evil Steve
Quote:
Original post by KalleKlovn
I think I understand. Thank you. The model I'm loading is about 50x50x50 cm in the 3d modeling program, but when I load it into direct3d it's about 10 units wide. 1 unit is then 5 cm. Can I change this. I want my model to be 1 unit wide. I know I can scale it when rendering it, but is this the only way?
You'd have to either scale it when you render it, or scale it just after loading (change the position of all the vertices), yes.
KalleKlovn
KalleKlovn
Thank you:) Scale it just after loading it seems like a good idea? How can I do that? I know how to scale it before rendering, but how can i scale it after loading it. It seems like a good idea to scale it once, instead of fore every frame. Sorry for wasting your time with stupid questions.. It helps me a lot:)
Evil Steve
Evil Steve
I'm not too sure about the details of ID3DXMesh (Which I presume is what you're using), but you need to lock the vertex buffer, divide each of the X, Y and Z components of the vertex by 10, then unlock the vertex buffer.

EDIT: Something like (untested):
struct Vertex{   float x, y z;};BYTE* pVertex;DWORD dwVerts = pMesh->GetNumVertices();DWORD dwStride = D3DXGetFVFVertexSize(pMesh->GetFVF());pMesh->LockVertexBuffer(D3DLOCK_READONLY,&pVertex);for(DWORD i=0; i<dwVerts; ++i){   Vertex* pVert = (Vertex*)pVertex;   pVert->x /= 10.0f;   pVert->y /= 10.0f;   pVert->z /= 10.0f;   pVertex += dwStride;}pMesh->UnlockVertexBuffer();
KalleKlovn
KalleKlovn
Thank you very much. I'll try that:)

Topic Locked

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

Sign in to reply to this topic.