Project

General

Profile

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

magiccube / src / main / java / org / distorted / control / RubikControlWhole.java @ 8badfe2a

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.control;
21

    
22
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
24

    
25
import org.distorted.library.effect.MatrixEffectMove;
26
import org.distorted.library.effect.MatrixEffectScale;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedNode;
29
import org.distorted.library.main.DistortedScreen;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshQuad;
32
import org.distorted.library.type.Dynamic;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static3D;
35
import org.distorted.main.R;
36
import org.distorted.main.RubikActivity;
37

    
38
import java.io.IOException;
39
import java.io.InputStream;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
class RubikControlWhole
44
  {
45
  private static final int NUM_NODE = 4;
46
  private static final int NUM_EFFE = 4;
47

    
48
  private final RubikControl mControl;
49
  private DistortedEffects[] mEffects;
50
  private DistortedNode[] mNodes;
51
  private long mEffectID;
52
  private MeshQuad mQuad;
53

    
54
  private Dynamic3D mDynamicHand1;
55
  private MatrixEffectMove mMoveHand1;
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
   private Bitmap openBitmap(RubikActivity act, int resource)
60
     {
61
     try( InputStream is = act.getResources().openRawResource(resource) )
62
       {
63
       return BitmapFactory.decodeStream(is);
64
       }
65
     catch( IOException e )
66
       {
67
       // ignore
68
       }
69

    
70
     return null;
71
     }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  private void createEffects()
76
    {
77
    if( mEffects==null )
78
      {
79
      mEffects = new DistortedEffects[NUM_EFFE];
80
      for(int i=0; i<NUM_EFFE; i++) mEffects[i]= new DistortedEffects();
81

    
82
      DistortedScreen screen = mControl.getScreen();
83
      int wid = screen.getWidth();
84
      int hei = screen.getHeight();
85

    
86
      float x1 = wid*0.35f;
87
      float y1 = hei*0.28f;
88
      float z  = 0;
89

    
90
      Static3D point0 = new Static3D(-x1,-y1,z);
91
      Static3D point1 = new Static3D(  0,-y1,z);
92
      Static3D point2 = new Static3D(+x1,-y1,z);
93
      Static3D point3 = new Static3D(+x1,  0,z);
94
      Static3D point4 = new Static3D(+x1,+y1,z);
95
      Static3D point5 = new Static3D(  0,  0,z);
96

    
97
      mDynamicHand1 = new Dynamic3D(15000,0.5f);
98
      mDynamicHand1.add(point0);
99
      mDynamicHand1.add(point0);
100
      mDynamicHand1.add(point1);
101
      mDynamicHand1.add(point2);
102
      mDynamicHand1.add(point2);
103
      mDynamicHand1.add(point3);
104
      mDynamicHand1.add(point4);
105
      mDynamicHand1.add(point4);
106
      mDynamicHand1.add(point5);
107
      mDynamicHand1.add(point0);
108
      mDynamicHand1.add(point0);
109
      mDynamicHand1.setMode(Dynamic.MODE_PATH);
110
      mDynamicHand1.setConvexity(0.0f);
111

    
112
      mMoveHand1 = new MatrixEffectMove(mDynamicHand1);
113
      mMoveHand1.notifyWhenFinished(mControl);
114
      mEffectID = mMoveHand1.getID();
115

    
116
      mEffects[0].apply( new MatrixEffectScale(150));
117
      mEffects[0].apply(mMoveHand1);
118
      mEffects[2].apply( new MatrixEffectScale(300));
119
      mEffects[2].apply(mMoveHand1);
120
      }
121
    else
122
      {
123
      mDynamicHand1.resetToBeginning();
124
      mMoveHand1.notifyWhenFinished(mControl);
125
      }
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  private void createNodes()
131
    {
132
    if( mNodes==null )
133
      {
134
      mNodes = new DistortedNode[NUM_NODE];
135
      mQuad  = new MeshQuad();
136
      }
137

    
138
    RubikActivity act = mControl.getActivity();
139

    
140
    if( act!=null )
141
      {
142
      Bitmap bmpCirc = openBitmap(act, R.drawable.ui_fading_circle);
143
      DistortedTexture textureCirc = new DistortedTexture();
144
      textureCirc.setTexture(bmpCirc);
145
      mNodes[0]= new DistortedNode(textureCirc,mEffects[0],mQuad);
146
      mNodes[1]= new DistortedNode(textureCirc,mEffects[1],mQuad);
147

    
148
      Bitmap bmpHand = openBitmap(act, R.drawable.ui_hand_pointer);
149
      DistortedTexture textureHand = new DistortedTexture();
150
      textureHand.setTexture(bmpHand);
151
      mNodes[2]= new DistortedNode(textureHand,mEffects[2],mQuad);
152
      mNodes[3]= new DistortedNode(textureHand,mEffects[3],mQuad);
153
      }
154
    else
155
      {
156
      android.util.Log.e("D", "Activity NULL!!");
157
      }
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  long getEffectID()
163
    {
164
    return mEffectID;
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  DistortedNode[] getNodes()
170
    {
171
    createEffects();
172
    createNodes();
173

    
174
    return mNodes;
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  DistortedNode[] returnNodes()
180
    {
181
    return mNodes;
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  RubikControlWhole(RubikControl control)
187
    {
188
    mControl = control;
189
    }
190
  }
(3-3/3)