Project

General

Profile

Download (4.14 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObjectNode.java @ 7ba38dd4

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objectlib.main;
21

    
22
import org.distorted.library.effect.MatrixEffectScale;
23
import org.distorted.library.main.DistortedEffects;
24
import org.distorted.library.main.DistortedNode;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static3D;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class TwistyObjectNode extends DistortedNode
32
  {
33
  private final Static3D mScale;
34
  private int mWidth, mHeight, mMinSize;
35
  private float mCameraDist;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
  public TwistyObjectNode(int surfaceW, int surfaceH)
40
    {
41
    super(new DistortedTexture(),new DistortedEffects(),new MeshSquare(20,20));
42

    
43
    mScale= new Static3D(1,1,1);
44
    setSize(surfaceW,surfaceH);
45
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale);
46
    getEffects().apply(scaleEffect);
47
    getMesh().setComponentCenter(0,0,0,-0.1f);
48
    setFOV(60);
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  void setSize(int surfaceW, int surfaceH)
54
    {
55
    mWidth  = surfaceW;
56
    mHeight = surfaceH;
57
    mMinSize= Math.min(mWidth,mHeight);
58

    
59
    resizeFBO(mWidth,mHeight);
60

    
61
    mScale.set(surfaceW,surfaceH,surfaceW);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  float getCameraDist()
67
    {
68
    return mCameraDist;
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  int getMinSize()
74
    {
75
    return mMinSize;
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
// PUBLIC API
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  public void setFOV(float fov)
83
    {
84
    double halfFOV = fov * (Math.PI/360);
85
    mCameraDist = (0.5f*mHeight) / ((float)Math.tan(halfFOV)*mWidth);
86
    setProjection( fov, 0.1f);
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  public int getWidth()
92
    {
93
    return mWidth;
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  public int getHeight()
99
    {
100
    return mHeight;
101
    }
102
  }
(16-16/17)