Posts

Showing posts with the label 2D

Calculating A 2D Vector's Cross Product

Answer : Implementation 1 returns the magnitude of the vector that would result from a regular 3D cross product of the input vectors, taking their Z values implicitly as 0 (i.e. treating the 2D space as a plane in the 3D space). The 3D cross product will be perpendicular to that plane, and thus have 0 X & Y components (thus the scalar returned is the Z value of the 3D cross product vector). Note that the magnitude of the vector resulting from 3D cross product is also equal to the area of the parallelogram between the two vectors, which gives Implementation 1 another purpose. In addition, this area is signed and can be used to determine whether rotating from V1 to V2 moves in an counter clockwise or clockwise direction. It should also be noted that implementation 1 is the determinant of the 2x2 matrix built from these two vectors. Implementation 2 returns a vector perpendicular to the input vector still in the same 2D plane. Not a cross product in the classical sense but c...

Changing The Coordinate System In LibGDX (Java)

Answer : If you use a Camera (which you should) changing the coordinate system is pretty simple: camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); If you use TextureRegions and/or a TextureAtlas, all you need to do in addition to that is call region.flip(false, true). The reasons we use y-up by default (which you can easily change as illustrated above) are as follows: your simulation code will most likely use a standard euclidian coordinate system with y-up if you go 3D you have y-up The default coordinate system is a right handed one in OpenGL, with y-up. You can of course easily change that with some matrix magic. The only two places in libgdx where we use y-down are: Pixmap coordinates (top upper left origin, y-down) Touch event coordinates which are given in window coordinates (top upper left origin, y-down) Again, you can easily change the used coord...