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

Commit 1d1c668

Browse files
committed
add views & swing Java 3d demos
1 parent c4ae22d commit 1d1c668

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3586
-125
lines changed

demoProjects/ViewsGraph3d/.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

demoProjects/ViewsGraph3d/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'android.support.viewsgraph3d'
7+
compileSdk 33
8+
9+
defaultConfig {
10+
applicationId "android.support.viewsgraph3d"
11+
minSdk 25
12+
targetSdk 33
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.9.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
36+
testImplementation 'junit:junit:4.13.2'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package android.support.viewsgraph3d;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("android.support.viewsgraph3d", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/Theme.ViewsGraph3d"
13+
tools:targetApi="31">
14+
<activity
15+
android:name=".MainActivity"
16+
android:exported="true">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package android.support.constraintLayout.extlib.graph3d;
2+
3+
4+
import android.support.constraintLayout.extlib.graph3d.objects.AxisBox;
5+
import android.support.constraintLayout.extlib.graph3d.objects.Surface3D;
6+
7+
public class Graph {
8+
Scene3D mScene3D = new Scene3D();
9+
10+
int mGraphType = 2;
11+
private float mLastTouchX0 = Float.NaN;
12+
private float mLastTouchY0;
13+
private float mLastTrackBallX;
14+
private float mLastTrackBallY;
15+
double mDownScreenWidth;
16+
Surface3D mSurface;
17+
AxisBox mAxisBox;
18+
float range = 20;
19+
float minZ = -10;
20+
float maxZ = 10;
21+
float mZoomFactor = 1;
22+
long nanoTime;
23+
float time = 0;
24+
int graphWidth;
25+
int graphHeight;
26+
ImageSupport image;
27+
28+
public interface ImageSupport {
29+
void makeImage(int w, int h);
30+
int[] getBacking();
31+
}
32+
33+
public Graph(ImageSupport image) {
34+
this.image = image;
35+
mAxisBox = new AxisBox();
36+
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
37+
mScene3D.addPostObject(mAxisBox);
38+
buildSurface(DEFAULT);
39+
resetCamera();
40+
}
41+
42+
public static Surface3D DEFAULT = new Surface3D((x, y, t) -> {
43+
double d = Math.sqrt(x * x + y * y);
44+
return 0.3f * (float) (Math.cos(d) * (y * y - x * x) / (1 + d));
45+
});
46+
47+
public void buildSurface(Surface3D surface3D) {
48+
mSurface = surface3D;
49+
mSurface.setRange(-range, range, -range, range, minZ, maxZ);
50+
mScene3D.setObject(mSurface);
51+
}
52+
53+
public void resetCamera() {
54+
mScene3D.resetCamera();
55+
}
56+
57+
public void setStartTime() {
58+
nanoTime = System.nanoTime();
59+
}
60+
61+
public void tick(long now) {
62+
time += (now - nanoTime) * 1E-9f;
63+
nanoTime = now;
64+
mSurface.calcSurface(time, false);
65+
mScene3D.update();
66+
}
67+
68+
public void resize(int width, int height) {
69+
graphHeight = height;
70+
graphWidth = width;
71+
image.makeImage(width, height);
72+
mScene3D.setScreenDim(width, height, image.getBacking(), 0x00AAAAAA);
73+
}
74+
75+
public void trackDown(float x, float y) {
76+
mDownScreenWidth = mScene3D.getScreenWidth();
77+
mLastTouchX0 = x;
78+
mLastTouchY0 = y;
79+
mScene3D.trackBallDown(mLastTouchX0, mLastTouchY0);
80+
mLastTrackBallX = mLastTouchX0;
81+
mLastTrackBallY = mLastTouchY0;
82+
}
83+
84+
public void trackDrag(float x, float y) {
85+
if (Float.isNaN(mLastTouchX0)) {
86+
return;
87+
}
88+
float tx = x;
89+
float ty = y;
90+
float moveX = (mLastTrackBallX - tx);
91+
float moveY = (mLastTrackBallY - ty);
92+
if (moveX * moveX + moveY * moveY < 4000f) {
93+
mScene3D.trackBallMove(tx, ty);
94+
}
95+
mLastTrackBallX = tx;
96+
mLastTrackBallY = ty;
97+
}
98+
99+
public void trackDone() {
100+
mLastTouchX0 = Float.NaN;
101+
mLastTouchY0 = Float.NaN;
102+
}
103+
104+
public void wheel(float rotation, boolean control) {
105+
if (control) {
106+
mZoomFactor *= (float) Math.pow(1.01, rotation);
107+
mScene3D.setZoom(mZoomFactor);
108+
mScene3D.setUpMatrix(graphWidth, graphHeight);
109+
mScene3D.update();
110+
} else {
111+
range = range * (float) Math.pow(1.01, rotation);
112+
mSurface.setArraySize(Math.min(300, (int) (range * 5)));
113+
mSurface.setRange(-range, range, -range, range, minZ, maxZ);
114+
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
115+
mScene3D.update();
116+
}
117+
}
118+
119+
public static final Surface3D BLACK_HOLE_MERGE = new Surface3D((x, y, t) -> {
120+
float d = (float) Math.sqrt(x * x + y * y);
121+
float d2 = (float) Math.pow(x * x + y * y, 0.125);
122+
float angle = (float) Math.atan2(y, x);
123+
float s = (float) Math.sin(d + angle - t * 5);
124+
float s2 = (float) Math.sin(t);
125+
float c = (float) Math.cos(d + angle - t * 5);
126+
return (s2 * s2 + 0.1f) * d2 * 5 * (s + c) / (1 + d * d / 20);
127+
// return (float) (s*s+0.1) * (float) (Math.cos(d-time*5) *(y*y-x*x) /(1+d*d));
128+
});
129+
130+
public void render() {
131+
if (mScene3D.notSetUp()) {
132+
mScene3D.setUpMatrix(graphWidth, graphHeight);
133+
}
134+
135+
mScene3D.render(mGraphType);
136+
}
137+
138+
public void lightMovesWithCamera(boolean doesMove) {
139+
mScene3D.mLightMovesWithCamera = doesMove;
140+
}
141+
142+
public void setSaturation(float sat) {
143+
mSurface.mSaturation = sat;
144+
mScene3D.update();
145+
}
146+
}

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/Matrix.java demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/Matrix.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.support.constraintlayout.extlib.graph3d;
16+
package android.support.constraintLayout.extlib.graph3d;
1717

1818
import java.text.DecimalFormat;
1919
import java.util.Arrays;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.support.constraintlayout.extlib.graph3d;
17+
package android.support.constraintLayout.extlib.graph3d;
1818

1919
/**
2020
* This represents 3d Object in this system.

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/Quaternion.java demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/Quaternion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.support.constraintlayout.extlib.graph3d;
17+
package android.support.constraintLayout.extlib.graph3d;
1818

1919
/**
2020
* This is a class that represents a Quaternion

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/Scene3D.java demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/Scene3D.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.support.constraintlayout.extlib.graph3d;
17+
package android.support.constraintLayout.extlib.graph3d;
1818

1919
import java.util.ArrayList;
2020
import java.util.Arrays;

desktop/graph3d/com/support/constraintlayout/extlib/graph3d/VectorUtil.java demoProjects/ViewsGraph3d/app/src/main/java/android/support/constraintLayout/extlib/graph3d/VectorUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.support.constraintlayout.extlib.graph3d;
16+
package android.support.constraintLayout.extlib.graph3d;
1717

1818
import java.text.DecimalFormat;
1919

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.support.constraintlayout.extlib.graph3d;
17+
package android.support.constraintLayout.extlib.graph3d;
1818

1919
import java.text.DecimalFormat;
2020
import java.util.Arrays;

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.support.constraintlayout.extlib.graph3d.objects;
16+
package android.support.constraintLayout.extlib.graph3d.objects;
17+
18+
import android.support.constraintLayout.extlib.graph3d.Object3D;
19+
import android.support.constraintLayout.extlib.graph3d.Scene3D;
20+
import android.support.constraintLayout.extlib.graph3d.VectorUtil;
1721

18-
import com.support.constraintlayout.extlib.graph3d.Object3D;
19-
import com.support.constraintlayout.extlib.graph3d.Scene3D;
20-
import com.support.constraintlayout.extlib.graph3d.VectorUtil;
2122

2223
/**
2324
* Draws box along the axis

0 commit comments

Comments
 (0)