Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ 71c7624f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.meshfile;
21

    
22
import android.graphics.Bitmap;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
import android.opengl.GLSurfaceView;
26

    
27
import org.distorted.library.effect.EffectType;
28
import org.distorted.library.effect.MatrixEffectMove;
29
import org.distorted.library.effect.MatrixEffectQuaternion;
30
import org.distorted.library.effect.MatrixEffectScale;
31
import org.distorted.library.effect.VertexEffectDeform;
32
import org.distorted.library.effect.VertexEffectMove;
33
import org.distorted.library.effect.VertexEffectRotate;
34
import org.distorted.library.effect.VertexEffectSink;
35
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.library.main.DistortedScreen;
38
import org.distorted.library.main.DistortedTexture;
39
import org.distorted.library.mesh.MeshBase;
40
import org.distorted.library.mesh.MeshJoined;
41
import org.distorted.library.mesh.MeshRectangles;
42
import org.distorted.library.type.Dynamic1D;
43
import org.distorted.library.type.DynamicQuat;
44
import org.distorted.library.type.Static1D;
45
import org.distorted.library.type.Static3D;
46
import org.distorted.library.type.Static4D;
47

    
48
import javax.microedition.khronos.egl.EGLConfig;
49
import javax.microedition.khronos.opengles.GL10;
50

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

    
53
class MeshFileRenderer implements GLSurfaceView.Renderer
54
{
55
    private GLSurfaceView mView;
56
    private DistortedTexture mTexture;
57
    private DistortedScreen mScreen;
58
    private DistortedEffects mEffects;
59
    private Static3D mScale;
60
    private MeshBase mMesh;
61

    
62
    Static4D mQuat1, mQuat2;
63
    int mScreenMin;
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
    MeshFileRenderer(GLSurfaceView v)
68
      {
69
      mView = v;
70
      mScreen = new DistortedScreen();
71
      mScale= new Static3D(1,1,1);
72
      Static3D center=new Static3D(0,0,0);
73

    
74
      mQuat1 = new Static4D(0,0,0,1);
75
      mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
76

    
77
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
78
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
79

    
80
      quatInt1.add(mQuat1);
81
      quatInt2.add(mQuat2);
82

    
83
      mEffects = new DistortedEffects();
84
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
85
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
86
      mEffects.apply( new MatrixEffectScale(mScale));
87

    
88
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
89
      }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
   
93
    public void onDrawFrame(GL10 glUnused) 
94
      {
95
      mScreen.render( System.currentTimeMillis() );
96
      }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
    
100
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
101
      {
102
      final float SCALE = 0.3f;
103
      mScreenMin = Math.min(width, height);
104
      float factor = SCALE*mScreenMin;
105
      mScale.set(factor,factor,factor);
106
      mScreen.resize(width, height);
107
      }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
    
111
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
112
      {
113
      if( mTexture==null ) mTexture = new DistortedTexture();
114

    
115
      try
116
        {
117
        DistortedLibrary.onCreate(mView.getContext());
118
        }
119
      catch(Exception ex)
120
        {
121
        android.util.Log.e("MeshFile", ex.getMessage() );
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
    void open(String name)
128
      {
129
      mTexture.setTexture( createTexture(name) );
130
      mMesh = createMesh(name);
131

    
132
      mScreen.detachAll();
133
      mScreen.attach(mTexture,mEffects,mMesh);
134
      }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
    private Bitmap createTexture(String name)
139
      {
140
      // TODO
141

    
142
      return null;
143
      }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
    private MeshBase createMesh(String name)
148
      {
149
      // TODO
150

    
151
      return null;
152
      }
153
}
(2-2/3)