• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ankhd

Centreing a Orthographic projected quad to screen

4 posts in this topic

Hi.

I'm using a orthographic projection view to render my game ui but, can't get the offset from my quad to align to the true centre
of the screen.

this is what Im doing I fist get the size of the quad by finding the min and max vertices of the quad then get the distance from
min and max I use this value to get the percentage of the screen, with this percentage divided by 2 I get the size in relation to the screen, then these locations get projected to 3d world space so they can be added to the unprojected screens 0,0 location in 3d space.
But the quad is not centre its off to the right what could be wrong if its all not wrong.

thanks for any help.

 

The quad we exported from 3dsmax at (0.0.0) in 3ds max world but the quads axis is the topleft of the quad if it helps.

here is the code I use to calculate the percentage and offsets

width and height are the quads size in object space(how its exported.)

//calculate the percentage of the ui quad to the screen
float px = (width / viewport.Width) * 100.0;
float py = (height / viewport.Height) * 100.0;
	
px *= 0.5;//we want half the percentage
py *= 0.5;

//we now want the percentage in size in relation to the screen
float screenpercentx =  (viewport.Width  * px / 100);
float screenpercenty =  (viewport.Height * py / 100);

	
//now we want half and offseted from screen centre
screenpercentx = ((viewport.Width * 0.5)  - (screenpercentx * 0.5));
screenpercenty = ((viewport.Height * 0.5) - (screenpercenty * 0.5));

	
DialogBox_GameLobby->SetCamera(&Cam);


D3DXMATRIX matView ;
Cam.getViewMatrix(&matView);
	
DialogBox_GameLobby->ReSetCam(&Cam);

D3DXVECTOR3 v;
D3DXVECTOR3 rayOrigin(0.0f, 0.0f, 0.0f);


v.x =  screenpercentx;
v.y =  screenpercenty;
v.z = 0.0f;

	
//unproject the screen base ofset 3d space
D3DXVec3Unproject(&rayOrigin,
 &v,
 &viewport,
&OrthograpicProjection,
&matView,
&Identityworld);	

//set the conversion
screenpercentx = rayOrigin.x;
screenpercenty = rayOrigin.y;


	

	
rayOrigin= D3DXVECTOR3 (0.0f, 0.0f, 0.0f);

//the left side of the screen 
v.x =  0.0;
v.y =  0.0;
v.z = 0.0f;

	
//unproject the the left side of the screen to 3d space
D3DXVec3Unproject(&rayOrigin,
 &v,
&viewport,&
OrthograpicProjection,
&matView,
 &Identityworld);	

	

	
//
//we have the left side of the screen projected to 3d world space
//add the quads projected location to the left side
Dialog_GameLobby->SetWorldPosition( rayOrigin.x - screenpercentx ,rayOrigin.y - screenpercenty, -1.0, 1.0, 1.0, 1.0);
0

Share this post


Link to post
Share on other sites

No the above code of mine does not work I changed the screen size and its not centre. it should be as JohnnyCode said but the mesh is to big for some reason.

 

See the meshes (Quad) is 749 units wide so half that is 374, But if I off set that to -374 the end of the screen in ortho is -327 SO the quads centre off set is of the screen to the left

How do I find the scale based on the orthographic projection.

 

This is how I make my Projection
 

float zoom = 2.2;//1.8f;

D3DXMatrixOrthoOffCenterLH(&OrthograpicProjection, (-Width/2)/zoom, (Width/2)/zoom, (-Height/2)/zoom, (Height/2)/zoom, 0.0f,1000.0f);

my projection is zooming out by 2.2

the centre is x-255.2, y159.2 ,

 

found by draging menu by the mouse to the real centre.

 

what should I be doing with the meshes(quad) size to get the -255.2 to centre it

1

Share this post


Link to post
Share on other sites

ortho projection in general (after view matrix position and rotation), spectates a scene of given wide. You define width and height and those 2 numbers devide everything, so that values will fall to scope of -1.0,1.0. The bigger width and height, the more of world space will fall to observation. In a nut shell ortho porjection will just devide x and y by width and height, and devide z component by (far-near). You are using a function D3DXMatrixOrthoOffCenterLH , which , seeing its name, can couse a spooky action at a distance (though unlikely).

 

In case the projection matrix you build provides standard ortho projection, is should be transformation as

T(x,y,z,w)=(x/widh,y/height,z/(far-near),w). With such a matrix, your will put to projection a space 2.0*width and 2.0*height range big, far-near deep.

 

In case you wish to transform your quad by projection matrix and have it result to -1.0,1.0 perfect fit, is should have verticies with respect to +/-width and +/-height, what is volatile in your case (zoom variable). The quad I adviced you with in 3ds max is already in projection space ( likely, depending on corelation between 3ds max object space and exporter postwork). You should be defining objects in projection space straight, wheather by hand, or by help of max, and not transform them, mainly if you alter projection matrix (zoom).

1

Share this post


Link to post
Share on other sites

I'm not getting it its not right. The funny thing is it works when the screen is 1440 x 900, but its out when using 1904 x 1134
just like some 80 pixels or so out.

here is the code now dividing by ht zoom value that seems to work some times

if(mc)
	{
		if(mc->pMesh)
		{
			GetExtentsX(mc->pMesh, min, max);// * zoom;//y value510;//
			width	= GetTheDiemention(min, max)/ zoom;
			//width = 510.0;



			//height	= GetMeshDepth(mc->pMesh) / zoom;//z value318;//
			GetExtentsZ(mc->pMesh, min, max);// * zoom;//y value510;//
			height	= GetTheDiemention(min, max)/  zoom;

			
		}
	}

//calculate the percentage of the ui quad to the screen
float px = (width  / (viewport.Width/zoom))  * 100.0;
float py = (height / (viewport.Height/zoom)) * 100.0;
	
	
//we now want the percentage in size in relation to the screen
float screenpercentx =  ((viewport.Width/zoom)  * px / 100);
float screenpercenty =  ((viewport.Height/zoom) * py / 100);

	
//now we want half and offseted from screen centre
screenpercentx = (((viewport.Width/zoom)  - screenpercentx)/2);//  - (screenpercentx * 0.5));
screenpercenty = (((viewport.Height/zoom) - screenpercenty)/2);

	
DialogBox_GameLobby->SetCamera(&Cam);


D3DXMATRIX matView ;
Cam.getViewMatrix(&matView);
	
DialogBox_GameLobby->ReSetCam(&Cam);

D3DXVECTOR3 v;
D3DXVECTOR3 rayOrigin(0.0f, 0.0f, 0.0f);


v.x =  screenpercentx;
v.y =  screenpercenty;
v.z = -1.0f;//this value here make the y value larger

	
//unproject the screen base ofset 3d space
D3DXVec3Unproject(&rayOrigin,
&v,
&viewport,
									  &OrthograpicProjection,
&matView,
 &Identityworld);	




DialogBox_GameLobby->SetWorldPosition(rayOrigin.x , rayOrigin.y, -1, 1.0, 1.0, 1.0);

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0