//Title: picker.java
//Version:
//Copyright: Copyright (c) 2000
//Author: SyGem Software
import java.awt.*;
import java.applet.*;
import sygem.jazz3d2_102.*;
public class picker extends Applet implements Runnable {
Thread m_ce;
world p_world;
int light1;
int pid,pid2,pid3,pid4;
Label display;
//Construct the applet
public picker() {
}
//Initialize the applet
public void init() {
resize(320,240);
p_world = new world(this);
display = new Label("No object selected yet...");
setLayout(new BorderLayout());
add("Center", p_world);
add("South", display);
p_world.setMouseTracking(true);
renderfs flat_shader = new renderfs();
rendergs gourard_shader = new rendergs();
torus3d torus = new torus3d(0.4,0.2,0.2,15,15,0.5,0,12);
torus.setColour(255,0,128);
cube3d cube = new cube3d(-0.5,0.5,12);
cube.setColour(75,50,220);
cube.scaleObject(0.8,0.8,0.8);
sphere3d sphere = new sphere3d(10,10,-0.5,-0.5,12);
sphere.setColour(0,255,128);
pid = p_world.addObject(sphere,gourard_shader);
pid2 = p_world.addObject(torus,gourard_shader);
pid3 = p_world.addObject(cube,flat_shader);
light temp_light = new light(0,0,1);
light1 = p_world.addLight(temp_light);
}
//Start the applet
public void start() {
if (m_ce == null) {
m_ce = new Thread(this);
m_ce.start();
}
}
//Stop the applet
public void stop() {
if (m_ce != null) {
m_ce.stop();
m_ce = null;
}
}
//Destroy the applet
public void destroy() {
}
public void run() {
p_world.prep();
while (true) {
p_world.rotateObjectLocal(pid,0,3,0);
p_world.rotateObjectLocal(pid2,1,3,2);
p_world.rotateObjectLocal(pid3,0,2,5);
p_world.redraw();
}
}
public boolean mouseUp(Event e, int x, int y) {
int id = p_world.getObjectAt(x,y);
String click_string = "That's not an object...";
if (id==0) click_string = "You clicked on the green sphere";
if (id==1) click_string = "You clicked on the red torus";
if (id==2) click_string = "You clicked on the blue cube";
display.setText(click_string);
return true;
}
}