-
Notifications
You must be signed in to change notification settings - Fork 0
/
JPCTGraphicsRenderer.java
99 lines (81 loc) · 2.5 KB
/
JPCTGraphicsRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.opencv.samples.markerlessarforandroid.graphics;
import java.io.InputStream;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import org.opencv.markerlessarforandroid.R;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.BitmapHelper;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
public class JPCTGraphicsRenderer implements GLSurfaceView.Renderer{
private Context context;
private final String TAG = "JPCTGraphicsRenderer";
private FrameBuffer fb;
private World world;
private Object3D logo;
public JPCTGraphicsRenderer(Context context) {
this.context = context;
world = new World();
world.setAmbientLight(100, 100, 100);
}
public void init() {
//Load logo
logo = loadModel();
logo.build();
// Add logo to scene
world.addObject(logo);
// Place camera
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(logo.getTransformedCenter());
}
@Override
public void onDrawFrame(GL10 arg0) {
if (logo != null)
logo.rotateY(0.005f);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(width, height);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing
}
private Object3D loadModel() {
InputStream objStream = context.getResources().openRawResource(R.drawable.opencv_logo);
InputStream mtlStream = context.getResources().openRawResource(R.drawable.opencv_logo_texture);
Object3D[] model = Loader.loadOBJ(objStream, mtlStream, 1);
Object3D o3d = new Object3D(0);
Object3D temp = null;
for (int i = 0; i < model.length; i++) {
temp = model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateX((float)( -0.5*Math.PI));
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
}
return o3d;
}
}