mirror of
https://github.com/brendanhaines/javaProcessing.git
synced 2024-12-25 10:26:59 -07:00
Initial Commit
This commit is contained in:
commit
11aacd9488
134
Display3D.java
Normal file
134
Display3D.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import processing.core.*;
|
||||
import java.lang.Math;
|
||||
|
||||
class Display3D extends PApplet {
|
||||
private final int BACKGROUND_COLOR;
|
||||
private final int xDim, yDim;
|
||||
|
||||
public float yaw = 0;
|
||||
public float pitch = 0;
|
||||
public float roll = 0;
|
||||
public double camAngle = 0.75;
|
||||
|
||||
////////////////////////
|
||||
///// Constructors /////
|
||||
////////////////////////
|
||||
|
||||
/**
|
||||
* No-args constructor
|
||||
*/
|
||||
public Display3D() {
|
||||
xDim = 480;
|
||||
yDim = 480;
|
||||
BACKGROUND_COLOR = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param w - width
|
||||
* @param h - height
|
||||
*/
|
||||
public Display3D( int w, int h ) {
|
||||
xDim = w;
|
||||
yDim = h;
|
||||
BACKGROUND_COLOR = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bkgnd - background color
|
||||
*/
|
||||
public Display3D( int bkgnd ) {
|
||||
xDim = 480;
|
||||
yDim = 480;
|
||||
BACKGROUND_COLOR = bkgnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param w - width
|
||||
* @param h - height
|
||||
* @param bkgnd - background color
|
||||
*/
|
||||
public Display3D( int w, int h, int bkgnd ) {
|
||||
xDim = w;
|
||||
yDim = h;
|
||||
BACKGROUND_COLOR = bkgnd;
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
///// Draw methods /////
|
||||
////////////////////////
|
||||
|
||||
public void drawObject() {
|
||||
noFill();
|
||||
stroke( 255 );
|
||||
box( xDim / 5, xDim / 3, xDim / 20 );
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
///// PApplet methods /////
|
||||
///////////////////////////
|
||||
|
||||
public void setup() {
|
||||
size( xDim, yDim, P3D );
|
||||
background( BACKGROUND_COLOR );
|
||||
|
||||
camera( (float)0.0, (float)( -xDim * Math.sin( camAngle )), (float)( xDim * Math.cos( camAngle ) ),
|
||||
(float)0.0, (float)0.0, (float)0.0,
|
||||
(float)0.0, (float)1.0, (float)0.0 );
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background( BACKGROUND_COLOR );
|
||||
|
||||
// draw image
|
||||
rotateZ( yaw );
|
||||
rotateX( pitch );
|
||||
rotateY( roll );
|
||||
drawObject();
|
||||
|
||||
if( keyPressed ) {
|
||||
if( keyCode == LEFT )
|
||||
roll -= 0.02;
|
||||
else if( keyCode == RIGHT )
|
||||
roll += 0.02;
|
||||
else if( keyCode == UP )
|
||||
pitch -= 0.02;
|
||||
else if( keyCode == DOWN )
|
||||
pitch += 0.02;
|
||||
else if( key == 'a' )
|
||||
yaw -= 0.02;
|
||||
else if( key == 'd' )
|
||||
yaw += 0.02;
|
||||
}
|
||||
|
||||
// set camera
|
||||
|
||||
camera( (float)0.0, (float)( xDim * Math.sin( camAngle )), (float)( xDim * 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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class tester {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame( "tester" );
|
||||
frame.setResizable( true );
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Display3D thing = new DisplayQuad( 80 );
|
||||
frame.add( thing );
|
||||
thing.init();
|
||||
while (thing.defaultSize&&!thing.finished)
|
||||
try {Thread.sleep(5);} catch (Exception e) {}
|
||||
|
||||
frame.pack();
|
||||
frame.setVisible( true );
|
||||
while( true ) {
|
||||
System.out.printf( "\rFrames: %8d\tRate: %8f", thing.frameCount, thing.frameRate );
|
||||
try{Thread.sleep(10);}catch(Exception ex){}
|
||||
}
|
||||
}
|
||||
}
|
115
DisplayQuad.java
Normal file
115
DisplayQuad.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
class DisplayQuad extends Display3D {
|
||||
|
||||
public DisplayQuad() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DisplayQuad( int bkgnd) {
|
||||
super( bkgnd );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void drawObject() {
|
||||
int s = 1;
|
||||
noFill();
|
||||
|
||||
beginShape();
|
||||
stroke( 250 );
|
||||
vertex( s*25, 0, 0 );
|
||||
vertex( s*100, s*75, 0 );
|
||||
vertex( s*100, s*85, 0 );
|
||||
|
||||
// leg
|
||||
vertex( s*100, s*85, 0 );
|
||||
vertex( s*100, s*85, -s*15 );
|
||||
vertex( s*100, s*75, -s*10 );
|
||||
vertex( s*100, s*75, 0 );
|
||||
vertex( s*100, s*85, 0 );
|
||||
vertex( s*100, s*85, -s*15 );
|
||||
vertex( s*90, s*85, 0 );
|
||||
vertex( s*100, s*85, -s*15 );
|
||||
vertex( s*90, s*85, -s*10 );
|
||||
vertex( s*90, s*85, 0 );
|
||||
vertex( s*100, s*85, 0 );
|
||||
|
||||
// arm
|
||||
vertex( s*100, s*85, 0 );
|
||||
vertex( s*90, s*85, 0 );
|
||||
vertex( 0, s*25, 0 );
|
||||
vertex( -s*90, s*85, 0 );
|
||||
vertex( -s*100, s*85, 0 );
|
||||
|
||||
// leg
|
||||
vertex( -s*100, s*85, 0 );
|
||||
vertex( -s*100, s*85, -s*15 );
|
||||
vertex( -s*100, s*75, -s*10 );
|
||||
vertex( -s*100, s*75, 0 );
|
||||
vertex( -s*100, s*85, 0 );
|
||||
vertex( -s*100, s*85, -s*15 );
|
||||
vertex( -s*90, s*85, 0 );
|
||||
vertex( -s*100, s*85, -s*15 );
|
||||
vertex( -s*90, s*85, -s*10 );
|
||||
vertex( -s*90, s*85, 0 );
|
||||
vertex( -s*100, s*85, 0 );
|
||||
|
||||
// arm
|
||||
vertex( -s*100, s*85, 0 );
|
||||
vertex( -s*100, s*75, 0 );
|
||||
vertex( -s*25, 0, 0 );
|
||||
|
||||
stroke( 255, 0, 0 );
|
||||
|
||||
vertex( -s*25, 0, 0 );
|
||||
vertex( -s*100, -s*75, 0 );
|
||||
vertex( -s*100, -s*85, 0 );
|
||||
|
||||
// leg
|
||||
vertex( -s*100, -s*85, 0 );
|
||||
vertex( -s*100, -s*85, -s*15 );
|
||||
vertex( -s*100, -s*75, -s*10 );
|
||||
vertex( -s*100, -s*75, 0 );
|
||||
vertex( -s*100, -s*85, 0 );
|
||||
vertex( -s*100, -s*85, -s*15 );
|
||||
vertex( -s*90, -s*85, 0 );
|
||||
vertex( -s*100, -s*85, -s*15 );
|
||||
vertex( -s*90, -s*85, -s*10 );
|
||||
vertex( -s*90, -s*85, 0 );
|
||||
vertex( -s*100, -s*85, 0 );
|
||||
|
||||
// arm
|
||||
vertex( -s*100, -s*85, 0 );
|
||||
vertex( -s*90, -s*85, 0 );
|
||||
vertex( 0, -s*25, 0 );
|
||||
vertex( s*90, -s*85, 0 );
|
||||
vertex( s*100, -s*85, 0 );
|
||||
|
||||
// leg
|
||||
vertex( s*100, -s*85, 0 );
|
||||
vertex( s*100, -s*85, -s*15 );
|
||||
vertex( s*100, -s*75, -s*10 );
|
||||
vertex( s*100, -s*75, 0 );
|
||||
vertex( s*100, -s*85, 0 );
|
||||
vertex( s*100, -s*85, -s*15 );
|
||||
vertex( s*90, -s*85, 0 );
|
||||
vertex( s*100, -s*85, -s*15 );
|
||||
vertex( s*90, -s*85, -s*10 );
|
||||
vertex( s*90, -s*85, 0 );
|
||||
vertex( s*100, -s*85, 0 );
|
||||
|
||||
// arm
|
||||
vertex( s*100, -s*85, 0 );
|
||||
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();
|
||||
}
|
||||
}
|
11
Makefile
Normal file
11
Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
all: build run
|
||||
|
||||
build: newVersion_build
|
||||
|
||||
run: run_tester
|
||||
|
||||
newVersion_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
|
||||
|
||||
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
|
BIN
gluegen-rt-natives-macosx-universal.jar
Normal file
BIN
gluegen-rt-natives-macosx-universal.jar
Normal file
Binary file not shown.
BIN
gluegen-rt.jar
Normal file
BIN
gluegen-rt.jar
Normal file
Binary file not shown.
BIN
jogl-all-natives-macosx-universal.jar
Normal file
BIN
jogl-all-natives-macosx-universal.jar
Normal file
Binary file not shown.
BIN
jogl-all.jar
Normal file
BIN
jogl-all.jar
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user