Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 5c3feb7

Browse files
authored
update lib in view Graph (#830)
* add views & swing Java 3d demos * update extlib
1 parent 1d1c668 commit 5c3feb7

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/Object3D.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
public class Object3D {
2323
protected float[] vert;
2424
protected float[] normal;
25-
protected int[] index;
25+
26+
protected short[] index;
27+
2628
protected float[] tVert; // the vertices transformed into screen space
2729
protected float mMinX, mMaxX, mMinY, mMaxY, mMinZ, mMaxZ; // bounds in x,y & z
2830
protected int mType = 4;
@@ -46,7 +48,7 @@ public void makeVert(int n) {
4648
}
4749

4850
public void makeIndexes(int n) {
49-
index = new int[n * 3];
51+
index = new short[n * 3];
5052
}
5153

5254
public void transform(Matrix m) {

demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/ViewMatrix.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public void setLookPoint(double[] mLookPoint) {
7777
this.mLookPoint = mLookPoint;
7878
}
7979

80+
/**
81+
* return the distance from the look point to the eye point
82+
* @return
83+
*/
84+
public double calCameraDistance() {
85+
double[] zv = {
86+
mEyePoint[0] - mLookPoint[0],
87+
mEyePoint[1] - mLookPoint[1],
88+
mEyePoint[2] - mLookPoint[2]
89+
};
90+
return VectorUtil.norm(zv);
91+
}
92+
8093
public double[] getEyePoint() {
8194
return mEyePoint;
8295
}
@@ -271,13 +284,15 @@ public void lookAt(Object3D tri, float[] voxelDim, int w, int h) {
271284
double[] mMoveToV = new double[3];
272285
double[] mStartEyePoint;
273286
double[] mStartUpVector;
287+
double dist = 0;
274288
Quaternion mQ = new Quaternion(0, 0, 0, 0);
275289

276290
public void trackBallUP(float x, float y) {
277291

278292
}
279293

280294
public void trackBallDown(float x, float y) {
295+
dist = calCameraDistance();
281296
mStartx = x;
282297
mStarty = y;
283298
ballToVec(x, y, mStartV);
@@ -304,7 +319,8 @@ public void trackBallMove(float x, float y) {
304319

305320
mEyePoint = mQ.rotateVec(mEyePoint);
306321
mUpVector = mQ.rotateVec(mStartUpVector);
307-
322+
VectorUtil.normalize(mEyePoint);
323+
VectorUtil.mult(mEyePoint,dist,mEyePoint);
308324
VectorUtil.sub(mLookPoint, mEyePoint, mEyePoint);
309325
calcMatrix();
310326

demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/objects/AxisBox.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ void buildBox() {
4848
vert[i * 3 + 2] = (((i >> 2) & 1) == 0) ? mMinZ : mMaxZ; // Z
4949
}
5050

51-
index = new int[6 * 2* 3]; // 6 sides x 2 triangles x 3 points per triangle
52-
int []sides = { // pattern of clockwise triangles around cube
51+
52+
index = new short[6 * 2 * 3]; // 6 sides x 2 triangles x 3 points per triangle
53+
short []sides = { // pattern of clockwise triangles around cube
5354
0, 2, 1, 3, 1, 2,
5455
0, 1, 4, 5, 4, 1,
5556
0, 4, 2, 6, 2, 4,
5657
7, 6, 5, 4, 5, 6,
5758
7, 3, 6, 2, 6, 3,
5859
7, 5, 3, 1, 3, 5
5960
};
60-
index = new int[sides.length];
61+
index = new short[sides.length];
6162
for (int i = 0; i < sides.length; i++) {
62-
index[i] = sides[i]*3;
63+
index[i] = (short) (3*sides[i]);
6364
}
6465
}
6566

demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/objects/Surface3D.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ public void calcSurface(float t, boolean resetZ) {
139139
int p2 = 3 * (1 + ix + iy * (mSize + 1));
140140
int p3 = 3 * (ix + (iy + 1) * (mSize + 1));
141141
int p4 = 3 * (1 + ix + (iy + 1) * (mSize + 1));
142-
index[count++] = p1;
143-
index[count++] = p2;
144-
index[count++] = p3;
142+
index[count++] = (short)p1;
143+
index[count++] = (short)p2;
144+
index[count++] = (short)p3;
145+
146+
index[count++] = (short)p4;
147+
index[count++] = (short)p3;
148+
index[count++] = (short)p2;
145149

146-
index[count++] = p4;
147-
index[count++] = p3;
148-
index[count++] = p2;
149150
}
150151
}
151152
}

0 commit comments

Comments
 (0)