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

add views & swing Java 3d demos #829

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions demoProjects/ViewsGraph3d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions demoProjects/ViewsGraph3d/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demoProjects/ViewsGraph3d/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions demoProjects/ViewsGraph3d/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
id 'com.android.application'
}

android {
namespace 'android.support.viewsgraph3d'
compileSdk 33

defaultConfig {
applicationId "android.support.viewsgraph3d"
minSdk 25
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
21 changes: 21 additions & 0 deletions demoProjects/ViewsGraph3d/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package android.support.viewsgraph3d;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("android.support.viewsgraph3d", appContext.getPackageName());
}
}
25 changes: 25 additions & 0 deletions demoProjects/ViewsGraph3d/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.ViewsGraph3d"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package android.support.constraintLayout.extlib.graph3d;


import android.support.constraintLayout.extlib.graph3d.objects.AxisBox;
import android.support.constraintLayout.extlib.graph3d.objects.Surface3D;

public class Graph {
Scene3D mScene3D = new Scene3D();

int mGraphType = 2;
private float mLastTouchX0 = Float.NaN;
private float mLastTouchY0;
private float mLastTrackBallX;
private float mLastTrackBallY;
double mDownScreenWidth;
Surface3D mSurface;
AxisBox mAxisBox;
float range = 20;
float minZ = -10;
float maxZ = 10;
float mZoomFactor = 1;
long nanoTime;
float time = 0;
int graphWidth;
int graphHeight;
ImageSupport image;

public interface ImageSupport {
void makeImage(int w, int h);
int[] getBacking();
}

public Graph(ImageSupport image) {
this.image = image;
mAxisBox = new AxisBox();
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
mScene3D.addPostObject(mAxisBox);
buildSurface(DEFAULT);
resetCamera();
}

public static Surface3D DEFAULT = new Surface3D((x, y, t) -> {
double d = Math.sqrt(x * x + y * y);
return 0.3f * (float) (Math.cos(d) * (y * y - x * x) / (1 + d));
});

public void buildSurface(Surface3D surface3D) {
mSurface = surface3D;
mSurface.setRange(-range, range, -range, range, minZ, maxZ);
mScene3D.setObject(mSurface);
}

public void resetCamera() {
mScene3D.resetCamera();
}

public void setStartTime() {
nanoTime = System.nanoTime();
}

public void tick(long now) {
time += (now - nanoTime) * 1E-9f;
nanoTime = now;
mSurface.calcSurface(time, false);
mScene3D.update();
}

public void resize(int width, int height) {
graphHeight = height;
graphWidth = width;
image.makeImage(width, height);
mScene3D.setScreenDim(width, height, image.getBacking(), 0x00AAAAAA);
}

public void trackDown(float x, float y) {
mDownScreenWidth = mScene3D.getScreenWidth();
mLastTouchX0 = x;
mLastTouchY0 = y;
mScene3D.trackBallDown(mLastTouchX0, mLastTouchY0);
mLastTrackBallX = mLastTouchX0;
mLastTrackBallY = mLastTouchY0;
}

public void trackDrag(float x, float y) {
if (Float.isNaN(mLastTouchX0)) {
return;
}
float tx = x;
float ty = y;
float moveX = (mLastTrackBallX - tx);
float moveY = (mLastTrackBallY - ty);
if (moveX * moveX + moveY * moveY < 4000f) {
mScene3D.trackBallMove(tx, ty);
}
mLastTrackBallX = tx;
mLastTrackBallY = ty;
}

public void trackDone() {
mLastTouchX0 = Float.NaN;
mLastTouchY0 = Float.NaN;
}

public void wheel(float rotation, boolean control) {
if (control) {
mZoomFactor *= (float) Math.pow(1.01, rotation);
mScene3D.setZoom(mZoomFactor);
mScene3D.setUpMatrix(graphWidth, graphHeight);
mScene3D.update();
} else {
range = range * (float) Math.pow(1.01, rotation);
mSurface.setArraySize(Math.min(300, (int) (range * 5)));
mSurface.setRange(-range, range, -range, range, minZ, maxZ);
mAxisBox.setRange(-range, range, -range, range, minZ, maxZ);
mScene3D.update();
}
}

public static final Surface3D BLACK_HOLE_MERGE = new Surface3D((x, y, t) -> {
float d = (float) Math.sqrt(x * x + y * y);
float d2 = (float) Math.pow(x * x + y * y, 0.125);
float angle = (float) Math.atan2(y, x);
float s = (float) Math.sin(d + angle - t * 5);
float s2 = (float) Math.sin(t);
float c = (float) Math.cos(d + angle - t * 5);
return (s2 * s2 + 0.1f) * d2 * 5 * (s + c) / (1 + d * d / 20);
// return (float) (s*s+0.1) * (float) (Math.cos(d-time*5) *(y*y-x*x) /(1+d*d));
});

public void render() {
if (mScene3D.notSetUp()) {
mScene3D.setUpMatrix(graphWidth, graphHeight);
}

mScene3D.render(mGraphType);
}

public void lightMovesWithCamera(boolean doesMove) {
mScene3D.mLightMovesWithCamera = doesMove;
}

public void setSaturation(float sat) {
mSurface.mSaturation = sat;
mScene3D.update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.support.constraintlayout.extlib.graph3d;
package android.support.constraintLayout.extlib.graph3d;

import java.text.DecimalFormat;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.support.constraintlayout.extlib.graph3d;
package android.support.constraintLayout.extlib.graph3d;

/**
* This represents 3d Object in this system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.support.constraintlayout.extlib.graph3d;
package android.support.constraintLayout.extlib.graph3d;

/**
* This is a class that represents a Quaternion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.support.constraintlayout.extlib.graph3d;
package android.support.constraintLayout.extlib.graph3d;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.support.constraintlayout.extlib.graph3d;
package android.support.constraintLayout.extlib.graph3d;

import java.text.DecimalFormat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.support.constraintlayout.extlib.graph3d;
package android.support.constraintLayout.extlib.graph3d;

import java.text.DecimalFormat;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.support.constraintlayout.extlib.graph3d.objects;
package android.support.constraintLayout.extlib.graph3d.objects;

import android.support.constraintLayout.extlib.graph3d.Object3D;
import android.support.constraintLayout.extlib.graph3d.Scene3D;
import android.support.constraintLayout.extlib.graph3d.VectorUtil;

import com.support.constraintlayout.extlib.graph3d.Object3D;
import com.support.constraintlayout.extlib.graph3d.Scene3D;
import com.support.constraintlayout.extlib.graph3d.VectorUtil;

/**
* Draws box along the axis
Expand Down
Loading