2021-11-01 10:46:54 +00:00
|
|
|
package sig;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.vecmath.Vector3d;
|
2021-11-01 11:06:22 +00:00
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
import java.awt.event.MouseListener;
|
|
|
|
import java.awt.event.MouseMotionListener;
|
2021-11-01 10:46:54 +00:00
|
|
|
|
2021-11-01 11:06:22 +00:00
|
|
|
public class SigRenderer implements MouseListener,MouseMotionListener{
|
2021-11-01 13:06:20 +00:00
|
|
|
public static Triangle tri;
|
|
|
|
public static Triangle tri2;
|
2021-11-01 11:06:22 +00:00
|
|
|
public final static int SCREEN_WIDTH=1280;
|
|
|
|
public final static int SCREEN_HEIGHT=720;
|
|
|
|
public final static long TIMEPERTICK = 16666667l;
|
|
|
|
public static double DRAWTIME=0;
|
|
|
|
|
2021-11-01 13:06:20 +00:00
|
|
|
Vector3d origin = new Vector3d(0,0,-10);
|
|
|
|
Vector3d dir = new Vector3d(0,0,1);
|
|
|
|
|
2021-11-01 11:06:22 +00:00
|
|
|
public void runGameLoop() {
|
|
|
|
|
|
|
|
}
|
2021-11-01 10:46:54 +00:00
|
|
|
|
|
|
|
SigRenderer(JFrame f) {
|
2021-11-01 13:06:20 +00:00
|
|
|
tri = new Triangle(new Vector3d(-1,-1,0),new Vector3d(1,-1,0),new Vector3d(0,2,0));
|
|
|
|
tri2 = new Triangle(new Vector3d(-1,-1,120),new Vector3d(1,-1,120),new Vector3d(0,2,120));
|
2021-11-01 11:06:22 +00:00
|
|
|
|
|
|
|
Panel p = new Panel();
|
|
|
|
|
|
|
|
new Thread() {
|
|
|
|
public void run(){
|
|
|
|
while (true) {
|
|
|
|
long startTime = System.nanoTime();
|
|
|
|
runGameLoop();
|
|
|
|
p.repaint();
|
|
|
|
long endTime = System.nanoTime();
|
|
|
|
long diff = endTime-startTime;
|
|
|
|
if (diff>TIMEPERTICK) { //Took longer than 1/60th of a second. No sleep.
|
|
|
|
System.err.println("Frame Drawing took longer than "+TIMEPERTICK+"ns to calculate ("+diff+"ns total)!");
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
long sleepTime = TIMEPERTICK - diff;
|
|
|
|
long millis = (sleepTime)/1000000;
|
|
|
|
int nanos = (int)(sleepTime-(((sleepTime)/1000000)*1000000));
|
|
|
|
//System.out.println("FRAME DRAWING: Sleeping for ("+millis+"ms,"+nanos+"ns) - "+(diff)+"ns");
|
|
|
|
DRAWTIME = (double)diff/1000000;
|
|
|
|
f.setTitle("Game Loop: "+DRAWTIME+"ms");
|
|
|
|
Thread.sleep(millis,nanos);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.start();
|
|
|
|
|
|
|
|
f.getContentPane().addMouseListener(this);
|
|
|
|
f.getContentPane().addMouseMotionListener(this);
|
|
|
|
f.add(p);
|
|
|
|
f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT);
|
|
|
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
f.setVisible(true);
|
2021-11-01 10:46:54 +00:00
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
JFrame f = new JFrame("SigRenderer");
|
|
|
|
new SigRenderer(f);
|
|
|
|
}
|
2021-11-01 11:06:22 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseEntered(MouseEvent e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseExited(MouseEvent e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseMoved(MouseEvent e) {
|
|
|
|
}
|
2021-11-01 10:46:54 +00:00
|
|
|
}
|