|
15 | 15 | */ |
16 | 16 | package com.projecttango.rajawali.renderables; |
17 | 17 |
|
| 18 | +import android.graphics.Color; |
| 19 | + |
18 | 20 | import org.rajawali3d.Object3D; |
| 21 | +import org.rajawali3d.materials.Material; |
19 | 22 | import org.rajawali3d.math.vector.Vector3; |
| 23 | +import org.rajawali3d.primitives.Line3D; |
| 24 | + |
| 25 | +import java.util.Arrays; |
| 26 | +import java.util.Collections; |
| 27 | +import java.util.Stack; |
20 | 28 |
|
21 | 29 | /** |
22 | 30 | *A primitive which represents a combination of Frustum and Axes. |
23 | 31 | */ |
24 | | -public class FrustumAxes extends Object3D { |
25 | | - private Frustum mFrustum; |
26 | | - private Axes mAxes; |
27 | | - public FrustumAxes() { |
28 | | - mFrustum = new Frustum(0.8f, 0.6f, 0.5f); |
29 | | - addChild(mFrustum); |
30 | | - mAxes = new Axes(); |
31 | | - addChild(mAxes); |
| 32 | +public class FrustumAxes extends Line3D { |
| 33 | + private static final float FRUSTUM_WIDTH = 0.8f; |
| 34 | + private static final float FRUSTUM_HEIGHT = 0.6f; |
| 35 | + private static final float FRUSTUM_DEPTH = 0.5f; |
| 36 | + |
| 37 | + public FrustumAxes(float thickness) { |
| 38 | + super(makePoints(), thickness, makeColors()); |
| 39 | + Material material = new Material(); |
| 40 | + material.useVertexColors(true); |
| 41 | + setMaterial(material); |
| 42 | + } |
| 43 | + |
| 44 | + private static Stack<Vector3> makePoints() { |
| 45 | + Vector3 o = new Vector3(0, 0, 0); |
| 46 | + Vector3 a = new Vector3(-FRUSTUM_WIDTH / 2f, FRUSTUM_HEIGHT / 2f, -FRUSTUM_DEPTH); |
| 47 | + Vector3 b = new Vector3(FRUSTUM_WIDTH / 2f, FRUSTUM_HEIGHT / 2f, -FRUSTUM_DEPTH); |
| 48 | + Vector3 c = new Vector3(FRUSTUM_WIDTH / 2f, -FRUSTUM_HEIGHT / 2f, -FRUSTUM_DEPTH); |
| 49 | + Vector3 d = new Vector3(-FRUSTUM_WIDTH / 2f, -FRUSTUM_HEIGHT / 2f, -FRUSTUM_DEPTH); |
| 50 | + |
| 51 | + Vector3 x = new Vector3(1, 0, 0); |
| 52 | + Vector3 y = new Vector3(0, 1, 0); |
| 53 | + Vector3 z = new Vector3(0, 0, 1); |
| 54 | + |
| 55 | + Stack<Vector3> points = new Stack<Vector3>(); |
| 56 | + Collections.addAll(points, new Vector3[]{o, x, o, y, o, z, o, a, b, o, b, c, o, c, d, o, d, a}); |
| 57 | + |
| 58 | + return points; |
| 59 | + } |
| 60 | + |
| 61 | + private static int[] makeColors() { |
| 62 | + int[] colors = new int[18]; |
| 63 | + Arrays.fill(colors, Color.BLACK); |
| 64 | + colors[0] = Color.RED; |
| 65 | + colors[1] = Color.RED; |
| 66 | + colors[2] = Color.GREEN; |
| 67 | + colors[3] = Color.GREEN; |
| 68 | + colors[4] = Color.BLUE; |
| 69 | + colors[5] = Color.BLUE; |
| 70 | + return colors; |
32 | 71 | } |
33 | 72 | } |
0 commit comments