java - Orthogonal Projection - Fit Object to Screen? -


im programming opengl (lwjgl) , building own mini-library. camera, takes projection type, builds projection matrix this:

this.aspect = (float) display.getwidth() / (float) display.getheight(); this.top = (float) (math.tan(math.toradians(fov) / 2)); this.bottom = -top; this.right = top * aspect; this.left = -right; if(type == aglprojectiontype.perspective){     float aspect = 800.0f / 600.0f;     final double f = (1.0 / math.tan(math.toradians(fov / 2.0)));     projection = new matrix4f();     projection.m00 = (float) (f / aspect);     projection.m11 = (float) f;     projection.m22 = (far + near) / (near - far);     projection.m23 = -1;     projection.m32 = (2 * far + near) / (near - far);     projection.m33 = 0; } else if(type == aglprojectiontype.orthogonal){     projection.m00 = 2 / (right - left);     projection.m03 = -(right + left) / (right - left);     projection.m11 = 2 / (top - bottom);       projection.m13 = -(top + bottom) / (top - bottom);     projection.m22 = -2 / (far - near); 

}

so far good. now, vbo input, raw meshes of objects - example quad - keep in normalized dimension, values in range of [ -1 | 1 ]. if want scale it, scale model matrix value, , move translate model matrix. problem is: relative values. if "matrix.scale(0.5f, 0.5f, 0.5f)" object take half of previous size. if example want have object 500 pixel width? how can calculate this? or if want object screen.width / heiht, , x = -screen.width * 0.5 , y = -screen.height * 0.5 - object wich fills out screen , has position in upper left corner of screen? have calculate of projection matrix - right? how?

not asking, maybe helps. code camera set screen coordinates match world coordinates , lower left corner of viewport 0 x , y. orthogonal projection.

        case twod:         {             projectionmatrix.resettozero();              projectionmatrix._11 = 2.0f/(float)this.viewport.width;             projectionmatrix._22 = 2.0f/(float)this.viewport.height;             projectionmatrix._33 = -2.0f/(this.farclip-this.nearclip);             projectionmatrix._43 =  -1* this.nearclip;              projectionmatrix._44 = 1.0f;              float tx = -0.5f* (float)this.viewport.width;             float ty = -0.5f* (float)this.viewport.height;               float tz = this.nearclip +0.1f;     //why +0.1f >> object z = 0 still displayed              viewmatrix.setidetity();             viewmatrix._22 = 1.0f;             viewmatrix._41 = tx;             viewmatrix._42 = ty;             viewmatrix._43 = -tz;             break;         } 

as question: have put desired screen coordinates trough inverse of view-projection matrix. , have add depth information on way going 2d 3d. sorry, cant math that.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -