Okis!!! thanks very much again!!
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 Menu
if (!wireframe)
{
cursorMouse.setVisibility(false);
shadowHelper.updateShadowMap();
buffer.clear(java.awt.Color.GRAY);
shadowHelper.drawScene();
}
else
{
buffer.clear(java.awt.Color.BLACK);
world.drawWireframe(buffer, colorWireFrame);
}
buffer.update();
buffer.displayGLOnly();
canvas.repaint();
cursorMouse.setVisibility(true);
}
import java.awt.*;
import javax.swing.JFrame;
import java.awt.Canvas;
import com.threed.jpct.*;
import com.threed.jpct.util.*;
public class SimpleShadows extends JFrame{
private Canvas canvas = null;
private boolean fin = false;
private FrameBuffer fb = null;
private World world = null;
private Object3D plane = null;
private Object3D cube = null;
private Object3D sphere = null;
private Projector projector=null;
private ShadowHelper sh = null;
private Light sun=null;
public SimpleShadows() {
super("TEST JNJ");
Config.glColorDepth = 24;
Config.glFullscreen = false;
Config.farPlane = 1000;
Config.glShadowZBias = 0.8f;
Config.glTrilinear=true;
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initStuff() throws Exception {
fb = new FrameBuffer(640, 480, FrameBuffer.SAMPLINGMODE_NORMAL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
world = new World();
plane = Primitives.getPlane(20, 30);
plane.rotateX((float) Math.PI / 2f);
cube=Primitives.getCube(15);
cube.setAdditionalColor(Color.RED);
cube.translate(0, -30, -10);
sphere=Primitives.getSphere(12);
sphere.translate(0, 0, -50);
sphere.setAdditionalColor(new Color(0,0,50));
world.addObject(sphere);
world.addObject(plane);
world.addObject(cube);
TextureManager tm = TextureManager.getInstance();
projector = new Projector();
sh = new ShadowHelper(world, fb, projector, 512);
sh.addCaster(cube);
sh.addReceiver(plane);
sh.addReceiver(sphere);
sh.setAmbientLight(new Color(30,30,30));
sh.setFiltering(true);
world.setAmbientLight(90,90,90);
world.buildAllObjects();
sun=new Light(world);
sun.setIntensity(50, 50, 50);
canvas = fb.enableGLCanvasRenderer();
System.out.println("listo canvas");
System.out.println("Poniendo canvas");
this.getContentPane().add(canvas);
}
private void doIt() throws Exception {
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.lookAt(plane.getTransformedCenter());
projector.setFOV(0.5f);
projector.setYFOV(0.5f);
SimpleVector pos=cube.getTransformedCenter();
projector.setPosition(pos);
projector.moveCamera(Camera.CAMERA_MOVEUP, 200);
projector.lookAt(pos);
SimpleVector offset=new SimpleVector(1,0,-1).normalize();
projector.moveCamera(offset, 215);
while (!fin) {
projector.lookAt(cube.getTransformedCenter());
offset.rotateY(0.007f);
projector.setPosition(pos);
projector.moveCamera(new SimpleVector(0,-1,0), 200);
projector.moveCamera(offset, 215);
sun.setPosition(projector.getPosition());
sh.updateShadowMap();
fb.clear();
sh.drawScene();
fb.update();
fb.displayGLOnly();
canvas.repaint();
Thread.sleep(10);
}
fb.disableRenderer(IRenderer.RENDERER_OPENGL);
fb.dispose();
System.exit(0);
}
public static void main(String[] args) throws Exception {
SimpleShadows cd = new SimpleShadows();
cd.initStuff();
cd.setVisible(true);
cd.pack();
cd.setBounds(new Rectangle(640,480));
cd.doIt();
}
}
In object creation:
buffer = new FrameBuffer(width, height, defaultFrameBufferMode);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
canvas = buffer.enableGLCanvasRenderer();
In loop method:
buffer.clear(java.awt.Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();
package engine3D;
import com.threed.jpct.*;
public class TerrainObject3D{
private Object3D terrain;
public TerrainObject3D(int maxPol){
terrain = new Object3D(maxPol);
}
public void addNewTerrainCell(Object3D obj, int posX, int posY){
PolygonManager polMan = obj.getPolygonManager();
int maxPolyID = polMan.getMaxPolygonID();
System.out.println("MaxPolyID = "+ Integer.toString(maxPolyID));
for (int poly = 0; poly < maxPolyID; poly++)
{
//Cada polígono tiene 3 vértices.
SimpleVector vect1 = polMan.getTransformedVertex( poly, 0);
SimpleVector vect2 = polMan.getTransformedVertex( poly, 1);
SimpleVector vect3 = polMan.getTransformedVertex( poly, 2);
//Cada vértice de cada polígono tiene asociado un par de valores U,V para la textura.
SimpleVector uv1 = polMan.getTextureUV(poly , 0);
SimpleVector uv2 = polMan.getTextureUV(poly , 1);
SimpleVector uv3 = polMan.getTextureUV(poly , 2);
//Cada polígono tiene una textura asociada, la optenemos.
int texID = polMan.getPolygonTexture(poly);
//Vemos que no haya un error en la textura.
if (texID == -1)
{
texID = 0;
}
vect1.set(vect1.x+posX,vect1.y, vect1.z+posY);
vect2.set(vect2.x+posX,vect2.y, vect2.z+posY);
vect3.set(vect3.x+posX,vect3.y, vect3.z+posY);
//Lo unimos al objeto terrain.
terrain.addTriangle(vect1, uv1.x, uv1.y, vect2, uv2.x, uv2.y, vect3, uv3.x, uv3.y, texID);
}
}
}
Page created in 0.017 seconds with 13 queries.