Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObjectNode.java @ 3d093961

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, mMin;
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
    mMin        = 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
// PUBLIC API
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  public void setFOV(float fov)
76
    {
77
    double halfFOV = fov * (Math.PI/360);
78
    //   mCameraDist = (0.5f*mHeight) / ((float)Math.tan(halfFOV)*mWidth);
79
    mCameraDist = 0.5f / ((float)Math.tan(halfFOV));
80

    
81
    setProjection( fov, 0.1f);
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  public int getMinSize()
87
    {
88
    return mMin;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  public int getWidth()
94
    {
95
    return mWidth;
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  public int getHeight()
101
    {
102
    return mHeight;
103
    }
104
  }
(17-17/18)