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

Commit ee32ade

Browse files
committed
fix previous checkin issue
1 parent 9fd7f00 commit ee32ade

File tree

4 files changed

+92
-59
lines changed

4 files changed

+92
-59
lines changed

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/Graph3dPanel.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ public class Graph3dPanel extends JPanel {
4141
Surface3D mSurface;
4242
AxisBox mAxisBox;
4343
float range = 20;
44+
float minZ = -6;
45+
float maxZ = 40;
46+
float mZoomFactor = 1;
47+
4448
public void buildSurface() {
4549

4650
mSurface = new Surface3D((x, y) -> {
4751
double d = Math.sqrt(x * x + y * y);
48-
return 10 * ((d == 0) ? 1f : (float) (Math.sin(d) / d));
52+
return 10 * ((d == 0) ? 1f : (float) (Math.sin(d)/(1+d) ));
4953
});
5054
mSurface.setRange(-range, range, -range, range);
5155
mScene3D.setObject(mSurface);
5256
mScene3D.resetCamera();
5357
mAxisBox = new AxisBox();
54-
mAxisBox.setRange(-range, range, -range, range,-2,20);
58+
mAxisBox.setRange(-range, range, -range, range, -2, 20);
5559
mScene3D.addPostObject(mAxisBox);
5660
}
5761

@@ -134,24 +138,25 @@ public void onMouseUP(MouseEvent ev) {
134138
mLastTouchY0 = Float.NaN;
135139
}
136140

137-
<<<<<<< Updated upstream
138-
public void onMouseWheel(MouseEvent ev) {
139-
MouseWheelEvent we = (MouseWheelEvent)ev;
140-
range = range * (float) Math.pow(1.01,we.getWheelRotation());
141-
System.out.println(range);
142-
mSurface.setRange(-range, range, -range, range);
143-
mAxisBox.setRange(-range, range, -range, range,-2,20);
144-
mScene3D.update();
145-
=======
141+
142+
public void onMouseWheel(MouseWheelEvent ev) {
143+
if (ev.isControlDown()) {
144+
mZoomFactor *= (float) Math.pow(1.01, ev.getWheelRotation());
145+
mScene3D.setZoom(mZoomFactor);
146+
mScene3D.setUpMatrix(getWidth(),getHeight());
147+
mScene3D.update();
148+
} else {
149+
146150
range = range * (float) Math.pow(1.01, ev.getWheelRotation());
147-
mSurface.setArraySize(Math.min(300,(int) (range * 5)));
151+
mSurface.setArraySize((int) (range * 5));
152+
System.out.println(range);
148153
mSurface.setRange(-range, range, -range, range);
149154
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
150155
mScene3D.update();
151156
}
152-
>>>>>>> Stashed changes
153157
repaint();
154158
}
159+
155160
public void paintComponent(Graphics g) {
156161
int w = getWidth();
157162
int h = getHeight();

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/Scene3D.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ public class Scene3D {
3131
ArrayList<Object3D> mPostObjects = new ArrayList();
3232
float[] zBuff;
3333
int[] img;
34-
<<<<<<< Updated upstream
35-
float[] light = {0, -1, -1}; // The direction of the light source
36-
=======
34+
3735
private float[] light = {0, -0.3f, 1}; // The direction of the light source
3836
public float[] mTransformedLight = {0, -1, -1}; // The direction of the light source
39-
>>>>>>> Stashed changes
37+
4038
int width, height;
41-
float[] tmpVec = new float[3];
39+
public float[] tmpVec = new float[3];
4240
int lineColor = 0xFF000000;
4341
private final float epslonX = 0.000005232f;
4442
private final float epslonY = 0.00000898f;
@@ -170,17 +168,23 @@ public void setScreenDim(int width, int height, int[] img, int background) {
170168
transform();
171169
}
172170

171+
public float getZoom() {
172+
return mZoomZ;
173+
}
174+
175+
public void setZoom(float zoom) {
176+
this.mZoomZ = zoom;
177+
}
178+
173179
public void setUpMatrix(int width, int height) {
174180
setUpMatrix(width, height, false);
175181
}
176182

177183
public void setUpMatrix(int width, int height, boolean resetOrientation) {
178184
double[] look_point = mObject3D.center();
179-
<<<<<<< Updated upstream
180-
double diagonal = mObject3D.size();
181-
=======
185+
182186
double diagonal = mObject3D.size() * mZoomZ;
183-
>>>>>>> Stashed changes
187+
184188
mMatrix.setLookPoint(look_point);
185189
if (resetOrientation) {
186190
double[] eye_point = {look_point[0] - diagonal, look_point[1] - diagonal, look_point[2] + diagonal};
@@ -315,9 +319,6 @@ public static void drawline(float[] zbuff, int[] img, int color, int w, int h,
315319
}
316320
}
317321

318-
<<<<<<< Updated upstream
319-
=======
320-
321322
public static boolean isBackface(
322323
float fx3, float fy3, float fz3,
323324
float fx2, float fy2, float fz2,
@@ -327,7 +328,7 @@ public static boolean isBackface(
327328

328329
}
329330

330-
>>>>>>> Stashed changes
331+
331332
public static void triangle(float[] zbuff, int[] img, int color, int w, int h,
332333
float fx3, float fy3, float fz3,
333334
float fx2, float fy2, float fz2,

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/objects/AxisBox.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.support.constraintlayout.extlib.graph3d.Object3D;
1919
import com.support.constraintlayout.extlib.graph3d.Scene3D;
20+
import com.support.constraintlayout.extlib.graph3d.VectorUtil;
2021

2122
/**
2223
* Draws box along the axis
@@ -48,20 +49,20 @@ void buildBox() {
4849

4950
index = new int[6 * 2* 3]; // 6 sides x 2 triangles x 3 points per triangle
5051
int []sides = { // pattern of clockwise triangles around cube
51-
0,2,1, 2,3,1,
52-
0,1,4, 1,5,4,
53-
0,4,2, 4,6,2,
54-
7,5,6, 5,4,6,
55-
7,6,3, 6,2,3,
56-
7,3,5, 3,1,5
52+
0, 2, 1, 3, 1, 2,
53+
0, 1, 4, 5, 4, 1,
54+
0, 4, 2, 6, 2, 4,
55+
7, 6, 5, 4, 5, 6,
56+
7, 3, 6, 2, 6, 3,
57+
7, 5, 3, 1, 3, 5
5758
};
5859
index = new int[sides.length];
5960
for (int i = 0; i < sides.length; i++) {
6061
index[i] = sides[i]*3;
6162
}
6263
}
6364

64-
public void render(Scene3D s, float[] zbuff, int[] img, int w, int h) {
65+
public void render_old(Scene3D s, float[] zbuff, int[] img, int w, int h) {
6566
for (int i = 0; i < index.length; i += 3) {
6667
int p1 = index[i];
6768
int p2 = index[i + 1];
@@ -82,8 +83,41 @@ public void render(Scene3D s, float[] zbuff, int[] img, int w, int h) {
8283
// tVert[p3], tVert[p3 + 1], tVert[p3 + 2] - 0.01f);
8384
}
8485
}
85-
<<<<<<< Updated upstream
86-
=======
86+
87+
public void render(Scene3D s, float[] zbuff, int[] img, int w, int h) {
88+
raster_color(s, zbuff, img, w, h);
89+
for (int i = 0; i < index.length; i += 3) {
90+
int p1 = index[i];
91+
int p2 = index[i + 1];
92+
int p3 = index[i + 2];
93+
94+
boolean back = Scene3D.isBackface(
95+
tVert[p1], tVert[p1 + 1], tVert[p1 + 2],
96+
tVert[p2], tVert[p2 + 1], tVert[p2 + 2],
97+
tVert[p3], tVert[p3 + 1], tVert[p3 + 2]);
98+
if (back) continue;
99+
100+
Scene3D.drawline(zbuff, img, color, w, h,
101+
tVert[p1], tVert[p1 + 1], tVert[p1 + 2] - 0.01f,
102+
tVert[p2], tVert[p2 + 1], tVert[p2 + 2] - 0.01f);
103+
drawTicks(zbuff, img, color, w, h,
104+
tVert[p1], tVert[p1 + 1], tVert[p1 + 2] - 0.01f,
105+
tVert[p2], tVert[p2 + 1], tVert[p2 + 2] - 0.01f,
106+
tVert[p3]-tVert[p1], tVert[p3 + 1]-tVert[p1+1], tVert[p3 + 2] -tVert[p1+2]
107+
);
108+
Scene3D.drawline(zbuff, img, color, w, h,
109+
tVert[p1], tVert[p1 + 1], tVert[p1 + 2] - 0.01f,
110+
tVert[p3], tVert[p3 + 1], tVert[p3 + 2] - 0.01f);
111+
drawTicks(zbuff, img, color, w, h,
112+
tVert[p1], tVert[p1 + 1], tVert[p1 + 2] - 0.01f,
113+
tVert[p3], tVert[p3 + 1], tVert[p3 + 2] - 0.01f,
114+
tVert[p2]-tVert[p1], tVert[p2 + 1]-tVert[p1+1], tVert[p2 + 2] -tVert[p1+2]);
115+
116+
// Scene3D.drawline(zbuff, img,0x000000, w, h,
117+
// tVert[p2], tVert[p2 + 1], tVert[p2 + 2] - 0.01f,
118+
// tVert[p3], tVert[p3 + 1], tVert[p3 + 2] - 0.01f);
119+
}
120+
}
87121
public static void drawTicks(float[] zbuff, int[] img, int color, int w, int h,
88122
float p1x, float p1y, float p1z,
89123
float p2x, float p2y, float p2z,
@@ -134,5 +168,5 @@ void raster_color(Scene3D s, float[] zbuff, int[] img, int w, int h) {
134168
tVert[p3 + 2]);
135169
}
136170
}
137-
>>>>>>> Stashed changes
171+
138172
}

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/objects/Surface3D.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
* Plots a surface based on Z = f(X,Y)
2222
*/
2323
public class Surface3D extends Object3D {
24-
final int SIZE = 100; // the number of point on the side total points = SIZE*SIZE
2524
private Function mFunction;
2625
private float mZoomZ = 1;
27-
26+
int mSize = 100;
2827
public void setRange(float minX, float maxX, float minY, float maxY) {
2928
mMinX = minX;
3029
mMaxX = maxX;
@@ -33,25 +32,25 @@ public void setRange(float minX, float maxX, float minY, float maxY) {
3332
computeSurface(true);
3433
}
3534

35+
public void setArraySize(int size) {
36+
mSize = size;
37+
computeSurface(true);
38+
}
39+
3640
public interface Function {
3741
float eval(float x, float y);
3842
}
3943

4044
public Surface3D(Function func) {
4145
mFunction = func;
4246
}
43-
47+
4448
public void computeSurface(boolean resetZ) {
45-
<<<<<<< Updated upstream
46-
int n = (SIZE + 1) * (SIZE + 1);
47-
vert = new float[n * 3];
48-
tVert = new float[n * 3];
49-
index = new int[SIZE * SIZE * 6];
50-
=======
49+
5150
int n = (mSize + 1) * (mSize + 1);
5251
makeVert(n);
5352
makeIndexes(mSize * mSize * 2);
54-
>>>>>>> Stashed changes
53+
System.err.println("index "+index.length);
5554
float min_x = mMinX;
5655
float max_x = mMaxX;
5756
float min_y = mMinY;
@@ -61,12 +60,7 @@ public void computeSurface(boolean resetZ) {
6160

6261

6362
int count = 0;
64-
<<<<<<< Updated upstream
65-
for (int iy = 0; iy <= SIZE; iy++) {
66-
float y = min_y + iy * (max_y - min_y) / (SIZE);
67-
for (int ix = 0; ix <= SIZE; ix++) {
68-
float x = min_x + ix * (max_x - min_x) / (SIZE);
69-
=======
63+
7064
for (int iy = 0; iy <= mSize; iy++) {
7165
float y = min_y + iy * (max_y - min_y) / (mSize);
7266
for (int ix = 0; ix <= mSize; ix++) {
@@ -80,7 +74,6 @@ public void computeSurface(boolean resetZ) {
8074
dy/=norm;
8175
dz/=norm;
8276
normal[count] =dx;
83-
>>>>>>> Stashed changes
8477
vert[count++] = x;
8578
normal[count] = dy;
8679
vert[count++] = y;
@@ -134,12 +127,12 @@ public void computeSurface(boolean resetZ) {
134127
}
135128
}
136129
count = 0;
137-
for (int iy = 0; iy < SIZE; iy++) {
138-
for (int ix = 0; ix < SIZE; ix++) {
139-
int p1 = 3 * (ix + iy * (SIZE + 1));
140-
int p2 = 3 * (1 + ix + iy * (SIZE + 1));
141-
int p3 = 3 * (ix + (iy + 1) * (SIZE + 1));
142-
int p4 = 3 * (1 + ix + (iy + 1) * (SIZE + 1));
130+
for (int iy = 0; iy < mSize; iy++) {
131+
for (int ix = 0; ix < mSize; ix++) {
132+
int p1 = 3 * (ix + iy * (mSize + 1));
133+
int p2 = 3 * (1 + ix + iy * (mSize + 1));
134+
int p3 = 3 * (ix + (iy + 1) * (mSize + 1));
135+
int p4 = 3 * (1 + ix + (iy + 1) * (mSize + 1));
143136
index[count++] = p1;
144137
index[count++] = p2;
145138
index[count++] = p3;

0 commit comments

Comments
 (0)