No problem and again, thanks for the prompt reply.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menuimport java.applet.*;
import java.awt.*;
import java.net.*;
import com.threed.jpct.*;
import java.awt.event.*;
// coord system for jpct
// +z - in front of you
// +x - to the right
// +y - to the bottom
public class test3D extends Applet implements Runnable, KeyListener
{
public class DemoVertexController extends GenericVertexController
{
int count;
DemoVertexController()
{
count=0;
}
public void apply()
{
SimpleVector[] srcMesh=this.getSourceMesh();
SimpleVector[] dstMesh=this.getDestinationMesh();
int size=this.getMeshSize();
for (int i=0; i<size; i++)
{
float z=srcMesh[i].y;
float y=srcMesh[i].z;
dstMesh[i].z=z;
dstMesh[i].y=-y;
}
count++;
}
}
private Thread loopThread;
private World world=null;
private Object3D obj=null;
private Camera camera=null;
private FrameBuffer buffer=null;
private boolean exit=false;
private final static float MOVE_SPEED=2.5f;
private final static float PLAYER_HEIGHT=30f;
private final static float TURN_SPEED=0.06f;
private Matrix playerDirection=new Matrix();
URL base;
Graphics bufferGraphics;
Image offscreen;
Dimension dim;
Object3D mLevel;
public test3D() {}
public void init()
{
getAppletContext().showStatus("Initializing...");
buffer=new FrameBuffer(480, 300, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
world=new World();
world.setAmbientLight(200,200,200);
obj=Primitives.getCube(3);
world.addObject(obj);
obj.translate(0.0f, 30.0f, 0.0f);
world.getCamera().setPosition(new SimpleVector(0,0,0));
camera = world.getCamera();
base = getDocumentBase();
Image myImage = getImage(base,"data/EarthTex.jpg");
Texture myTexture = new Texture(myImage);
TextureManager.getInstance().addTexture("EARTHTEX.JPG", myTexture);
Object3D[] levelParts=Loader.load3DS(base, "data/testmesh.3ds", 1f);
mLevel=new Object3D(0);
for (int i=0; i<levelParts.length; i++)
{
Object3D part=levelParts[i];
mLevel=Object3D.mergeObjects(mLevel, part);
}
IVertexController demoControl=new DemoVertexController();
mLevel.getMesh().setVertexController(demoControl, IVertexController.PRESERVE_SOURCE_MESH);
mLevel.getMesh().applyVertexController();
world.addObject(mLevel);
addKeyListener( this );
dim = getSize();
offscreen = createImage(dim.width,dim.height);
bufferGraphics = offscreen.getGraphics();
}
public void destroy() {
TextureManager.getInstance().flush();
Object3D.resetNextID();
exit=true;
super.destroy();
}
public void paint(Graphics g)
{
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.display(bufferGraphics);
g.drawImage(offscreen,0,0,this);
}
public void update(Graphics g)
{
paint(g);
}
public String getAppletInfo()
{
return ("Example Applet ");
}
public void run()
{
}
public void start()
{
}
/** Handle the key pressed event from the text field. */
public void keyPressed(KeyEvent e)
{
int code=e.getKeyCode();
switch (code)
{
case (KeyEvent.VK_UP):
{
SimpleVector camPos=camera.getPosition();
camPos.add(playerDirection.getZAxis());
camera.setPosition(camPos);
repaint();
break;
}
case (KeyEvent.VK_DOWN):
{
SimpleVector camPos=camera.getPosition();
SimpleVector direction = playerDirection.getZAxis();
direction.scalarMul(-1f);
camPos.add(direction);
camera.setPosition(camPos);
repaint();
break;
}
case (KeyEvent.VK_LEFT):
{
camera.rotateAxis(camera.getBack().getYAxis(), -TURN_SPEED);
playerDirection.rotateY(-TURN_SPEED);
repaint();
break;
}
case (KeyEvent.VK_RIGHT):
{
camera.rotateAxis(camera.getBack().getYAxis(), TURN_SPEED);
playerDirection.rotateY(TURN_SPEED);
repaint();
break;
}
}
}
/** Handle the key released event from the text field. */
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
}
Page created in 0.021 seconds with 13 queries.