From 4060ceaf2d59746335d5aceee4b65c9da50304cd Mon Sep 17 00:00:00 2001 From: Brendan Date: Fri, 8 May 2015 20:36:26 -0600 Subject: [PATCH] adds yaw zeroing button and much more --- Display3D.java | 13 ++++++--- DisplayQuad.java | 18 +++++++------ Makefile | 2 +- Tester3D.java | 69 ++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 84 insertions(+), 18 deletions(-) diff --git a/Display3D.java b/Display3D.java index 4d305f5..b2c37ef 100644 --- a/Display3D.java +++ b/Display3D.java @@ -60,10 +60,14 @@ class Display3D extends PApplet { ///// Draw methods ///// //////////////////////// + public void drawBackground() { + + } + public void drawObject() { noFill(); 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 ); 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)1.0, (float)0.0 ); } @@ -82,10 +86,11 @@ class Display3D extends PApplet { public void draw() { background( BACKGROUND_COLOR ); + drawBackground(); // draw image rotateZ( yaw ); rotateX( pitch ); - rotateY( roll ); + rotateY( -roll ); drawObject(); if( keyPressed ) { @@ -105,7 +110,7 @@ class Display3D extends PApplet { // 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)1.0, (float)0.0 ); // up axis } diff --git a/DisplayQuad.java b/DisplayQuad.java index e42c46b..3c74a88 100644 --- a/DisplayQuad.java +++ b/DisplayQuad.java @@ -8,6 +8,16 @@ class DisplayQuad extends Display3D { 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*25, 0, 0 ); endShape(); - - // sphere - pushMatrix(); - rotateX((float)(Math.PI/2)); - noFill(); - stroke(100); - sphere(280); - popMatrix(); } } \ No newline at end of file diff --git a/Makefile b/Makefile index 3efd01b..f62cffa 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: build run run: run_tester3d 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: java -cp '.:core.jar:gluegen-rt.jar:jogl-all.jar:gluegen-rt-natives-macosx-universal.jar:jogl-all-natives-macosx-universal.jar' tester diff --git a/Tester3D.java b/Tester3D.java index 4df186a..d72e74c 100644 --- a/Tester3D.java +++ b/Tester3D.java @@ -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.io.*; import java.net.*; 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) { + 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 { Socket skt = new Socket("localhost", 7777); BufferedReader in = new BufferedReader(new InputStreamReader(skt.getInputStream())); - System.out.print("Received string: '"); + Scanner in2 = new Scanner( skt.getInputStream() ); + System.out.println("STARTING..."); - while (!in.ready()) {} - System.out.println(in.readLine()); // Read one line and output it + while( !in.ready() ) {} - System.out.print("'\n"); - in.close(); + String inString; + 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) { System.out.print("Whoops! It didn't work!\n");