Project

General

Profile

Download (5.64 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ 77efd5ad

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
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.bandaged;
21
22 77efd5ad Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24
25 9530f6b0 Leszek Koltunski
import android.opengl.GLSurfaceView;
26
27
import org.distorted.library.main.DistortedLibrary;
28 da56b12f Leszek Koltunski
import org.distorted.library.main.DistortedNode;
29 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
30
31 77efd5ad Leszek Koltunski
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33 9530f6b0 Leszek Koltunski
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
37
{
38 77efd5ad Leszek Koltunski
   private final GLSurfaceView mView;
39 9530f6b0 Leszek Koltunski
   private final DistortedScreen mScreen;
40 77efd5ad Leszek Koltunski
   private final Static3D mScale;
41 9530f6b0 Leszek Koltunski
42 77efd5ad Leszek Koltunski
   private final float[][] POSITIONS = new float[][]
43 da56b12f Leszek Koltunski
        {
44
          {-1.0f, +1.0f, +1.0f},
45
          {-1.0f, +1.0f, +0.0f},
46
          {-1.0f, +1.0f, -1.0f},
47
          {-1.0f,  0.0f, +1.0f},
48
          {-1.0f,  0.0f, +0.0f},
49
          {-1.0f,  0.0f, -1.0f},
50
          {-1.0f, -1.0f, +1.0f},
51
          {-1.0f, -1.0f, +0.0f},
52
          {-1.0f, -1.0f, -1.0f},
53
          { 0.0f, -1.0f, +1.0f},
54
          { 0.0f, -1.0f, +0.0f},
55
          { 0.0f, +1.0f, +1.0f},
56
          { 0.0f, +1.0f, +0.0f},
57
          { 0.0f, +1.0f, -1.0f},
58
          { 0.0f,  0.0f, +1.0f},
59
          { 0.0f,  0.0f, -1.0f},
60
          { 1.0f, +1.0f, +1.0f},
61
          { 1.0f, +1.0f, +0.0f},
62
          { 1.0f, +1.0f, -1.0f},
63
          { 1.0f,  0.0f, +1.0f},
64
          { 1.0f,  0.0f, +0.0f},
65
          { 1.0f, -1.0f, +1.0f},
66
          { 1.0f,  0.0f, -1.0f },
67
          { 1.0f, -1.0f, -1.0f },
68
          { 1.0f, -1.0f, +0.0f },
69
          { 0.0f, -1.0f, -1.0f },
70
        };
71
72
   Static4D mQuat1, mQuat2;
73
   int mScreenMin;
74
75 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
76
77
   BandagedCreatorRenderer(BandagedCreatorView v)
78
     {
79
     final float BRIGHTNESS = 0.333f;
80
81 da56b12f Leszek Koltunski
     mQuat1 = new Static4D(0,0,0,1);
82
     mQuat2 = new Static4D(0,0,0,1);
83
84 9530f6b0 Leszek Koltunski
     mView = v;
85 77efd5ad Leszek Koltunski
86 9530f6b0 Leszek Koltunski
     mScreen = new DistortedScreen();
87
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
88 77efd5ad Leszek Koltunski
     mScale= new Static3D(1,1,1);
89 da56b12f Leszek Koltunski
90 77efd5ad Leszek Koltunski
     BandagedCubit cubit = new BandagedCubit(POSITIONS[0], mQuat1, mQuat2, mScale);
91
     DistortedNode node = cubit.getNode();
92
     mScreen.attach(node);
93 da56b12f Leszek Koltunski
     }
94
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96 77efd5ad Leszek Koltunski
/*
97 da56b12f Leszek Koltunski
   private BandagedCubit[] createCubits()
98
     {
99
     int len = POSITIONS.length;
100
     BandagedCubit[] cubits = new BandagedCubit[len];
101
102
     for(int c=0; c<len; c++)
103
       {
104 77efd5ad Leszek Koltunski
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mScale);
105 da56b12f Leszek Koltunski
       DistortedNode node = cubits[c].getNode();
106
       mScreen.attach(node);
107
       }
108
109
     return cubits;
110 9530f6b0 Leszek Koltunski
     }
111 77efd5ad Leszek Koltunski
*/
112 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114
   @Override
115
   public void onDrawFrame(GL10 glUnused)
116
     {
117
     long time = System.currentTimeMillis();
118
     mScreen.render(time);
119
     }
120
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123
   @Override
124
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
125
      {
126 77efd5ad Leszek Koltunski
      final float Q = 0.3f;
127
128
      if( width<height ) mScale.set( Q*width,   Q*width, 1 );
129
      else               mScale.set( Q*height, Q*height, 1 );
130
131 da56b12f Leszek Koltunski
      mScreenMin = Math.min(width, height);
132 9530f6b0 Leszek Koltunski
      mScreen.resize(width,height);
133
      }
134
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137
   @Override
138
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
139
      {
140
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
141
      }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145
   public void distortedException(Exception ex)
146
     {
147
     android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() );
148
     }
149
}