In fact, the original question is 1 cast away from the solution.
gluPerspective(60, window.width/window.height, 0.01f, 100.0f)
gluPerspective(60, (float)window.width/window.height, 0.01f, 100.0f)
The problem was that window.width and window....
I've changed the shader according to the article suggested by Seth Battin. Now it performs perspectively correct quad texturing. Phew, bacon delivered:
For the future generations that may never happen. The input is in a form of the line vertexes A1/A2, B1/B2 that creates diagonals (rather then sequential vertexes):
public static Vector3 ...
I think having a FoV of 90deg is what feels natural when you try to mimick 'looking through human eyes'. Your calculations would be correct if you would use the screen to simulate a window into a virtual world, not a first person perspective. Image you would have to see the world trough a 20" frame 80cm away from your head ...
The two matrices are constructed in completely different ways.
There are tons of ways to find more information on that by googling.
You can't get the field of view from the orthographic camera because there is no such thing.
I'm assuming you know how basic matrix math works, so I'm not going to cover that in my answer.
What you eventually want to do is transform the vertices of the object you want to render from the virtual 3D world to the "real" 2D world (your monitor screen). You do that by multiplying the vertices of the object with a camera matrix (some people may use other ...
After some effort, I've found a temporal approach: overlapping the panels and using a shader mask to combine both images in the middle.
Anyway I'm sure there must be a way to make the camera perpendicular in the middle and not on the sides. Hopefully somebody can give us some ideas about how to do it.
This is an old question, so I'm guessing that tom37 may have moved on by now, but I think I have an answer for anyone else with the same problem.
For reference, here is a view of a surface grid using a perspective camera.
Now let's say that we want to render a portion of this current view, but to the entire screen. Let's render the top-left quarter of the ...
Luckily for you, you don't actually have to deal with any of this! Instead of actually creating a top-down world, you can use Unity's built-in 2D mode, and create sprites instead of cubes and planes, to make it look like it is top down. 2D mode makes the camera line up automatically, and have the depth appear to be non-relevant, though it is. Also, there are ...
If you are looking to use any 3D objects (lets say a chessboard with 3d pieces), you could make a series of quads, then manipulate the camera's position and target to get the angle/perspective that you want.
It's somewhere between the vertex and fragment shader (after the geometry shader and right before the fragment shader if you want to be specific). Since the fragment shader runs for each drawn pixel, the positions have to be divided by W by then. The division is automatic, you don't need to do it yourself.
Even if you wanted to, doing transformations after ...
Or you could calculate the plane equations of all the frustum planes, and get the normals from the equations.
A plane equation has the form:
Ax + By + Cz + D = 0
(A, B, C) represents the plane normal.
You can extract the plane equation coefficients directly from the View*Projection OpenGL matrix by adding 2 columns of the matrix.
This method is ...
I don't know what vertex data you're using to draw that, but supposing it is a cube, I wouldn't say that the perspective is VERY wrong, or even wrong at all, on the left picture.
Based on your commented-out code, your ultimate view-projection matrix is getting calculated like this:
identity * translation * projection * rotation
Your drawing is getting ...
These are the two main solutions I can think of:
If you use tilesets, add a rectangle on top of your tiles. You should also move the collision detection up a bit, not to have your character walking on the edge of the blocks. However, this can easily look like the character's feet are passing through the ground but it mostly depends on the quality of the ...
A lot of the effect of FOV is on how fast you seem to move through the world (it's still the same speed; this is purely perceptional). With too wide a horizontal FOV you'll seem to move very fast, with too narrow you'll seem to move very slow. 90 degrees horizontal appears to be the "sweet spot", and the game developer can tune a desired movement speed for ...
I want to thank everyone who took their time to respond to my question. I finally came up with my own solution, which nevertheless was inspired by the suggestions here.
Especially this comment from Ali.S turned out to be particularly useful:
Just an idea, but you can provide your shader with another texture, representing the height of that pixel, and ...
You can do this in two ways, both of which require 3D cameras and projection:
First, give all of your objects a 3D position in the world.
Next, create a camera with a position and orientation:
// Position of the camera in the world
// Place where the camera is looking
FOV is field of view. Everyone likes to say that there is no camera in OpenGL, but to me that's a silly notion to hold on to even if it might be technically true. When you use the perspectiveCamera function you are essentially creating a camera. So think of the FOV as the type of lens. Is it a wide angle lens or more of a zoom lens?
The FOV is given as ...
GIMP has a "Lens Distortion" filter under Filters / Distorts.
But clearly that is not the preferred option as it leads to data loss. There are cameras (cheap ones too) with lenses that don't produce such strong distortion.
This was caused by an uninitialized variable being fed into the projection function:
static int win_width; //is 0 at initialization
static int win_height; //is 0 at initialization
int renderer_init(int width,int height)
proj_mat = mat4f_projection(45.0f, (float)win_width / (float)win_height, 0.1f, 100.0f);
It becomes much clearer if you draw it from a top-down perspective:
The normal on the right is simply the direction vector of the camera rotated by -90°-fovX/2 around the y axis and the one of the left is the mirrored version of the one on the left. Same with the top two, but they use fovY instead of fovX and you rotate the direction vector around the x ...
Take a look at this MSDN LINK, they tell you all you need to know to create a projection matrix that you can use. And that one is really good.
For your results, the x&y seems correct. indeed the values are supposed to be inside -1 to 1, but the fact is that you also have scaling in place as well as they can endup outside of the screen. To get them into ...
The picture you posted seems to be seen from a 45° angle. This perspective is sometimes informally called "bird view". More formally, it is usually referred to as orthogonal, dimetric projection. Orthogonal means that all the world-axis are all parallel to a screen-axis (world-x is parallel to screen-x, world-y and world-z are parallel to screen-y). Dimetric ...
You want scissor regions. Documentation for this feature in libgdx is here.
Sample code provided on that page is:
Rectangle scissors = new Rectangle();
Rectangle clipBounds = new Rectangle(x,y,w,h);
ScissorStack.calculateScissors(camera, spriteBatch.getTransformMatrix(), clipBounds, scissors);
The problem is actually much simpler than you make it sound. Suppose wx, wy are your "world" coordinates -- that is, the native coordinates of your tiles. In order to transform that into the screen coordinates sx, sy, you apply some matrix transform. This can be written as: (sx, sy) = (dx, dy) + M * (wx, wy). You already have that equation somewhere in your ...
There is no 'flip' here; both coordinate systems are exactly the same. Instead, the two images have been created using two differently oriented cameras. Which direction is 'up' is not defined by the coordinate system, but by an arbitrary mental note you make.
An axonometric projection is basically an orthographic projection with a rotation. You can create an orthographic projection with Matrix.CreateOrthographic or its friend CreateOrthographicOffCenter (MSDN).
Transformation matrices are basically used to take coordinates from one "space" to another. For example, a projection matrix takes points in "view" space ...