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

Commit dfdb85b

Browse files
authored
open gles 1.1 graph (#831)
1 parent 5c3feb7 commit dfdb85b

Some content is hidden

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

50 files changed

+3893
-0
lines changed

demoProjects/OpenGLEsGraph3D/.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demoProjects/OpenGLEsGraph3D/.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
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+
<?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+
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</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+
}

0 commit comments

Comments
 (0)