mirror of
https://github.com/brendanhaines/javaProcessing.git
synced 2024-12-25 18:37:32 -07:00
adds yaw zeroing button and much more
This commit is contained in:
parent
d4c05c3ec5
commit
4060ceaf2d
|
@ -60,10 +60,14 @@ class Display3D extends PApplet {
|
||||||
///// Draw methods /////
|
///// Draw methods /////
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
|
public void drawBackground() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void drawObject() {
|
public void drawObject() {
|
||||||
noFill();
|
noFill();
|
||||||
stroke( 255 );
|
stroke( 255 );
|
||||||
box( xDim / 5, xDim / 3, xDim / 20 );
|
box( width / 5, width / 3, width / 20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
|
@ -74,7 +78,7 @@ class Display3D extends PApplet {
|
||||||
size( xDim, yDim, P3D );
|
size( xDim, yDim, P3D );
|
||||||
background( BACKGROUND_COLOR );
|
background( BACKGROUND_COLOR );
|
||||||
|
|
||||||
camera( (float)0.0, (float)( -xDim * Math.sin( camAngle )), (float)( xDim * Math.cos( camAngle ) ),
|
camera( (float)0.0, (float)( -width * Math.sin( camAngle )), (float)( width * Math.cos( camAngle ) ),
|
||||||
(float)0.0, (float)0.0, (float)0.0,
|
(float)0.0, (float)0.0, (float)0.0,
|
||||||
(float)0.0, (float)1.0, (float)0.0 );
|
(float)0.0, (float)1.0, (float)0.0 );
|
||||||
}
|
}
|
||||||
|
@ -82,10 +86,11 @@ class Display3D extends PApplet {
|
||||||
public void draw() {
|
public void draw() {
|
||||||
background( BACKGROUND_COLOR );
|
background( BACKGROUND_COLOR );
|
||||||
|
|
||||||
|
drawBackground();
|
||||||
// draw image
|
// draw image
|
||||||
rotateZ( yaw );
|
rotateZ( yaw );
|
||||||
rotateX( pitch );
|
rotateX( pitch );
|
||||||
rotateY( roll );
|
rotateY( -roll );
|
||||||
drawObject();
|
drawObject();
|
||||||
|
|
||||||
if( keyPressed ) {
|
if( keyPressed ) {
|
||||||
|
@ -105,7 +110,7 @@ class Display3D extends PApplet {
|
||||||
|
|
||||||
// set camera
|
// set camera
|
||||||
|
|
||||||
camera( (float)0.0, (float)( xDim * Math.sin( camAngle )), (float)( xDim * Math.cos( camAngle ) ), // camera position
|
camera( (float)0.0, (float)( width * Math.sin( camAngle )), (float)( width * Math.cos( camAngle ) ), // camera position
|
||||||
(float)0.0, (float)0.0, (float)0.0, // center
|
(float)0.0, (float)0.0, (float)0.0, // center
|
||||||
(float)0.0, (float)1.0, (float)0.0 ); // up axis
|
(float)0.0, (float)1.0, (float)0.0 ); // up axis
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,16 @@ class DisplayQuad extends Display3D {
|
||||||
super( bkgnd );
|
super( bkgnd );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawBackground() {
|
||||||
|
// sphere
|
||||||
|
pushMatrix();
|
||||||
|
rotateX((float)(Math.PI/2));
|
||||||
|
noFill();
|
||||||
|
stroke(100, 127 );
|
||||||
|
sphere( width );
|
||||||
|
popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -103,13 +113,5 @@ class DisplayQuad extends Display3D {
|
||||||
vertex( s*100, -s*75, 0 );
|
vertex( s*100, -s*75, 0 );
|
||||||
vertex( s*25, 0, 0 );
|
vertex( s*25, 0, 0 );
|
||||||
endShape();
|
endShape();
|
||||||
|
|
||||||
// sphere
|
|
||||||
pushMatrix();
|
|
||||||
rotateX((float)(Math.PI/2));
|
|
||||||
noFill();
|
|
||||||
stroke(100);
|
|
||||||
sphere(280);
|
|
||||||
popMatrix();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ all: build run
|
||||||
run: run_tester3d
|
run: run_tester3d
|
||||||
|
|
||||||
build:
|
build:
|
||||||
javac -cp '.:core.jar:gluegen-rt.jar:jogl-all.jar:gluegen-rt-natives-macosx-universal.jar:jogl-all-natives-macosx-universal.jar' Display3D.java DisplayQuad.java Tester3D.java Serial.java
|
javac -cp '.:core.jar:gluegen-rt.jar:jogl-all.jar:gluegen-rt-natives-macosx-universal.jar:jogl-all-natives-macosx-universal.jar' Display3D.java DisplayQuad.java Tester3D.java
|
||||||
|
|
||||||
run_tester:
|
run_tester:
|
||||||
java -cp '.:core.jar:gluegen-rt.jar:jogl-all.jar:gluegen-rt-natives-macosx-universal.jar:jogl-all-natives-macosx-universal.jar' tester
|
java -cp '.:core.jar:gluegen-rt.jar:jogl-all.jar:gluegen-rt-natives-macosx-universal.jar:jogl-all-natives-macosx-universal.jar' tester
|
||||||
|
|
|
@ -1,20 +1,79 @@
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
import java.lang.*;
|
import java.lang.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
class Tester3D {
|
class Tester3D {
|
||||||
|
public static Display3D area3d;
|
||||||
|
public static JFrame frame;
|
||||||
|
public static JSlider slider;
|
||||||
|
public static JButton button;
|
||||||
|
public static double rawYaw;
|
||||||
|
public static double yawAdjust = 0.0;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
frame = new JFrame( "Tester3D" );
|
||||||
|
frame.setResizable( true );
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setLayout( new BorderLayout() );
|
||||||
|
|
||||||
|
area3d = new DisplayQuad( 80 );
|
||||||
|
frame.add( area3d, BorderLayout.CENTER );
|
||||||
|
area3d.init();
|
||||||
|
while( area3d.defaultSize && !area3d.finished )
|
||||||
|
try { Thread.sleep( 5 ); } catch( Exception e ) {}
|
||||||
|
|
||||||
|
slider = new JSlider( JSlider.VERTICAL, 0, 157, 79 );
|
||||||
|
slider.addChangeListener( new ChangeListener() {
|
||||||
|
public void stateChanged( ChangeEvent evt ) {
|
||||||
|
Tester3D.area3d.camAngle = (float)( 157 - Tester3D.slider.getValue() ) / 100;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frame.add( slider, BorderLayout.EAST );
|
||||||
|
|
||||||
|
button = new JButton( "reset yaw" );
|
||||||
|
button.addActionListener( new ActionListener() {
|
||||||
|
public void actionPerformed( ActionEvent evt ) {
|
||||||
|
Tester3D.yawAdjust = rawYaw;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frame.add( button, BorderLayout.NORTH );
|
||||||
|
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible( true );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Socket skt = new Socket("localhost", 7777);
|
Socket skt = new Socket("localhost", 7777);
|
||||||
BufferedReader in = new BufferedReader(new
|
BufferedReader in = new BufferedReader(new
|
||||||
InputStreamReader(skt.getInputStream()));
|
InputStreamReader(skt.getInputStream()));
|
||||||
System.out.print("Received string: '");
|
Scanner in2 = new Scanner( skt.getInputStream() );
|
||||||
|
System.out.println("STARTING...");
|
||||||
|
|
||||||
while (!in.ready()) {}
|
while( !in.ready() ) {}
|
||||||
System.out.println(in.readLine()); // Read one line and output it
|
|
||||||
|
|
||||||
System.out.print("'\n");
|
String inString;
|
||||||
in.close();
|
while( true ) {
|
||||||
|
//while( !in.ready() ) {}
|
||||||
|
//inString = in.readLine();
|
||||||
|
if( in2.hasNext() ) {
|
||||||
|
if( in2.next().equals( "ypr" ) ) {
|
||||||
|
while( !in2.hasNext() ) {}
|
||||||
|
rawYaw = (float)( 0.01745329251 * in2.nextFloat() );
|
||||||
|
area3d.yaw = (float)( rawYaw - yawAdjust );
|
||||||
|
while( !in2.hasNext() ) {}
|
||||||
|
area3d.pitch = (float)( 0.01745329251 * in2.nextFloat() );
|
||||||
|
while( !in2.hasNext() ) {}
|
||||||
|
area3d.roll = (float)( 0.01745329251 * in2.nextFloat() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.print("'\n");
|
||||||
|
//in.close();
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
System.out.print("Whoops! It didn't work!\n");
|
System.out.print("Whoops! It didn't work!\n");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user