Revision 84ddf691
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
39 | 39 |
|
40 | 40 |
public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener |
41 | 41 |
{ |
42 |
static final float CAMERA_DISTANCE = 0.6f; // 0.6 of the length of min(scrHeight,scrWidth) |
|
43 | 42 |
public static final int NODE_FBO_SIZE = 600; |
44 | 43 |
|
45 | 44 |
private RubikSurfaceView mView; |
... | ... | |
311 | 310 |
{ |
312 | 311 |
if( mNewObject!=null ) mNewObject.createTexture(); |
313 | 312 |
|
314 |
double halfFOVInRadians = Math.atan( 1.0f/(2*CAMERA_DISTANCE) ); |
|
315 |
float fovInDegrees = (float)(2*halfFOVInRadians*(180/Math.PI)); |
|
316 |
|
|
317 |
mScreen.setProjection( fovInDegrees, 0.1f); |
|
318 | 313 |
mScreen.resize(width, height); |
319 | 314 |
mView.setScreenSize(width,height); |
320 | 315 |
|
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
45 | 45 |
// Every 1/12 the distance of min(scrWidth,scrHeight) the direction of cube rotation will reset. |
46 | 46 |
private final static int DIRECTION_SENSITIVITY= 12; |
47 | 47 |
|
48 |
private final Static4D CAMERA_POINT = new Static4D(0, 0, RubikRenderer.CAMERA_DISTANCE, 0); |
|
48 |
// Where did we get this sqrt(3)/2 ? From the (default, i.e. 60 degrees - see InternalOutputSurface!) |
|
49 |
// FOV of the projection matrix of the Node onto the Screen. |
|
50 |
// Take a look how the CAMERA_POINT is used in onTouchEvent - (x,y) there are expressed in sort of |
|
51 |
// 'half-NDC' coordinates i.e. they range from +0.5 to -0.5; thus CAMERA_POINT also needs to be |
|
52 |
// in 'half-NDC'. Since in this coordinate system the height of the screen is equal to 1, then the |
|
53 |
// Z-distance from the center of the object to the camera is equal to (scrHeight/2)/tan(FOV/2) = |
|
54 |
// 0.5/tan(30) = sqrt(3)/2. |
|
55 |
// Why is the Z-distance between the camera and the object equal to (scrHeight/2)/tan(FOV/2)? |
|
56 |
// Because of the way the View part of the ModelView matrix is constructed in EffectQueueMatrix.send(). |
|
57 |
private final Static4D CAMERA_POINT = new Static4D(0, 0, (float)Math.sqrt(3)*0.5f, 0); |
|
49 | 58 |
|
50 | 59 |
private RubikRenderer mRenderer; |
51 | 60 |
private RubikObjectMovement mMovement; |
Also available in: Unified diff
Fixes for the Projection matrix, FOV.
There was a confusion between the Projection of the Node onto the Screen, and the Projection of the Cubits on the Node.