| Author |
Message |
eugenk Developer

Joined: 30 Jan 2008 Posts: 29 Location: Russian Federation, Moscow
|
Posted: Sun Feb 10, 2008 7:23 pm Post subject: Automatical OpenGL layout |
|
|
Suppose that we have some complex object, consists of several colored 3D cubes for example. The number of cubes may be vary. Nevertheless, this object is only a part of scene, and must occupy only predefined screen area. How to place it to screen automatically, with manner independent with number of colored 3D cubes, in object ?
Remember about one of OpenGL basics - about projections. Look at start of onDraw() method in Colored 3D cube example.
| Java: |
//get screen physical size in pixels
int w = getWidth();
int h = getHeight();
//setup OpenGL raster area to whole screen
gl.glViewport(0, 0, w, h);
//calculate the ratio between screen width and height (formfactor)
float ratio = (float)w / h;
//switch to operations with projection matrix
gl.glMatrixMode(gl.GL_PROJECTION);
//init projection matrix with trivial matrix
gl.glLoadIdentity();
//setup projection
gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12);
|
The last call is very important. It setups viewing area. glFrustumf() method has the next semantics:
glFrustumf (float left, float right, float bottom, float top, float near, float far)
where left, right, top, bottom, near, far - corresponding bounds of viewing area. So, viewing area is some truncated pyramid, oblique-angled in general case(see picture).
Eye (or camera) is placed in the beginning of coordinates (0,0,0) or in imagine top of this truncated pyramid.
X-axes goes from left to right.
Y - from bottom to top.
Z - from near to far.
If right = - left and top = - bottom, pyramid will be symmetric. Else it will be oblique-angled. In colored 3D cube tutorial left=- ratio, right=ratio, bottom=-1. top=1, near=2, far=12. Hence pyramid is symmetric.
As you can see on the picture, any surface {Z=const} will be a plane, parallel near (z=near] and far(z=far) planes. Particularly near plane is a screen surface, or projection plane. Namely to near plane relays left, right, bottom and top parameters. It sign that if point lays at near plane (has coordinates (x,y,near)), then if x=left then point lays on left screen side, if x=right - on right, if y=bottom on bottom, if y=top on top. This allows to calculate screen coordinates of point that has any value of z.
Be continued tomorrow.
| Description: |
|
| Filesize: |
32.16 KB |
| Viewed: |
1969 Time(s) |

|
|
|
| Back to top |
|
 |
eugenk Developer

Joined: 30 Jan 2008 Posts: 29 Location: Russian Federation, Moscow
|
Posted: Mon Feb 11, 2008 3:59 pm Post subject: |
|
|
Try to calculate screen coordinates of point, with any Z-coordinate between near and far. Suppose for simplicity, that it's Y-coordinate is zero. I.e. point has coordinates (X0, 0, Z0). Dissect our pyramid (picture in previous post) with plane {y=0} (see attached picture). On picture, point OZ is coordinates beginning op plane {Z=Z0}, and ON is coordinates beginning in {Z=near}. Remember, that {Z=near} plane is our physical screen. Hence point ON represents screen coordinates beginning.
Sorry, I'm busy a little. Be continued
| Description: |
|
| Filesize: |
23.98 KB |
| Viewed: |
1960 Time(s) |

|
|
|
| Back to top |
|
 |
tsipoura Freshman

Joined: 09 Feb 2008 Posts: 2
|
Posted: Thu Feb 21, 2008 5:12 pm Post subject: |
|
|
| Quote: | | Sorry, I'm busy a little. Be continued |
|
|
| Back to top |
|
 |
plusminus Site Admin


Joined: 14 Nov 2007 Posts: 2439 Location: College Park, MD
|
Posted: Thu Feb 21, 2008 5:29 pm Post subject: |
|
|
| tsipoura wrote: | | Quote: | | Sorry, I'm busy a little. Be continued |  |
There is someone obviously addicted to you eugene
_________________
Please remember, that this board is give & take 
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
eugenk Developer

Joined: 30 Jan 2008 Posts: 29 Location: Russian Federation, Moscow
|
Posted: Thu Feb 21, 2008 8:10 pm Post subject: |
|
|
| plusminus wrote: | | tsipoura wrote: | | Quote: | | Sorry, I'm busy a little. Be continued |  |
There is someone obviously addicted to you eugene  |
plusminus, sorry, sorry and once more sorry I have not so many time before April 14. But I decide to win. Hardly decide to do it... Today have just upgrade SDK. And application does not works with it:( Now learn about API changes. Maybe week or two and I'll work out at least draft game version. Then continue this topic and begin to say about other interesting things Unfortunately my English is not very well, and I spend some time and efforts to translate from Russian texts which I write... But time and efforts now is critical factor for me
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|