Project

General

Profile

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

magiccube / src / main / java / org / distorted / control / RubikControlWhole.java @ 45ab4482

1 51f51f83 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 45ab4482 Leszek Koltunski
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
24
25 51f51f83 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectScale;
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedNode;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshQuad;
30
import org.distorted.library.type.Dynamic;
31
import org.distorted.library.type.Dynamic3D;
32
import org.distorted.library.type.Static3D;
33 45ab4482 Leszek Koltunski
import org.distorted.main.R;
34
import org.distorted.main.RubikActivity;
35
36
import java.io.IOException;
37
import java.io.InputStream;
38 51f51f83 Leszek Koltunski
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
class RubikControlWhole
42
  {
43 45ab4482 Leszek Koltunski
  private static final int NUM_NODE = 2;
44
  private static final int NUM_EFFE = 2;
45 51f51f83 Leszek Koltunski
46
  private final RubikControl mControl;
47
  private DistortedEffects[] mEffects;
48
  private DistortedNode[] mNodes;
49
  private long mEffectID;
50
51
  private Dynamic3D mDynamic;
52
  private MatrixEffectScale mScale;
53
54 45ab4482 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56
   private Bitmap openBitmap(RubikActivity act, int resource)
57
     {
58
     try(InputStream is = act.getResources().openRawResource(resource) )
59
       {
60
       return BitmapFactory.decodeStream(is);
61
       }
62
     catch(IOException e)
63
       {
64
       // ignore
65
       }
66
67
     return null;
68
     }
69
70 51f51f83 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72
  private void createEffects()
73
    {
74
    if( mEffects==null )
75
      {
76 45ab4482 Leszek Koltunski
      mEffects   = new DistortedEffects[NUM_EFFE];
77 51f51f83 Leszek Koltunski
      mEffects[0]= new DistortedEffects();
78 45ab4482 Leszek Koltunski
      mEffects[1]= new DistortedEffects();
79 51f51f83 Leszek Koltunski
80 45ab4482 Leszek Koltunski
      float scaleCirc = 150;
81
      float scaleHand = 300;
82
83
      Static3D scale0 = new Static3D(scaleCirc,scaleCirc,scaleCirc);
84
      Static3D scale1 = new Static3D(scaleHand,scaleHand,scaleHand);
85 51f51f83 Leszek Koltunski
86
      mDynamic = new Dynamic3D(10000,0.5f);
87 45ab4482 Leszek Koltunski
      mDynamic.add(scale0);
88 51f51f83 Leszek Koltunski
      mDynamic.setMode(Dynamic.MODE_PATH);
89
90
      mScale = new MatrixEffectScale(mDynamic);
91
      mScale.notifyWhenFinished(mControl);
92
      mEffectID = mScale.getID();
93
      mEffects[0].apply(mScale);
94 45ab4482 Leszek Koltunski
      mEffects[1].apply( new MatrixEffectScale(scale1));
95 51f51f83 Leszek Koltunski
      }
96
    else
97
      {
98
      mDynamic.resetToBeginning();
99
      mScale.notifyWhenFinished(mControl);
100
      }
101
    }
102
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
105
  private void createNodes()
106
    {
107
    if( mNodes==null )
108
      {
109
      mNodes = new DistortedNode[NUM_NODE];
110 45ab4482 Leszek Koltunski
      RubikActivity act = mControl.getActivity();
111
112
      if( act!=null )
113
        {
114
        MeshQuad mesh = new MeshQuad();
115
116
        Bitmap bmpCirc = openBitmap(act, R.drawable.ui_fading_circle);
117
        DistortedTexture textureCirc = new DistortedTexture();
118
        textureCirc.setTexture(bmpCirc);
119
        mNodes[0]= new DistortedNode(textureCirc,mEffects[0],mesh);
120
121
        Bitmap bmpHand = openBitmap(act, R.drawable.ui_hand_pointer);
122
        DistortedTexture textureHand = new DistortedTexture();
123
        textureHand.setTexture(bmpHand);
124
        mNodes[1]= new DistortedNode(textureHand,mEffects[1],mesh);
125
        }
126
      else
127
        {
128
        android.util.Log.e("D", "Activity NULL!!");
129
        }
130 51f51f83 Leszek Koltunski
      }
131
    }
132
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135
  long getEffectID()
136
    {
137
    return mEffectID;
138
    }
139
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
142
  DistortedNode[] getNodes()
143
    {
144
    createEffects();
145
    createNodes();
146
147
    return mNodes;
148
    }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152
  DistortedNode[] returnNodes()
153
    {
154
    return mNodes;
155
    }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159
  RubikControlWhole(RubikControl control)
160
    {
161
    mControl = control;
162
    }
163
  }