Author Topic: Lights  (Read 1079 times)

Offline ndr123

  • byte
  • *
  • Posts: 14
    • View Profile
Lights
« on: November 29, 2011, 06:54:09 pm »
Hi, I wanted to ask if the lights created through
Code: [Select]
new Light(world) are omnidirectional lights. Cause if they are I'm having a problem.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Lights
« Reply #1 on: November 29, 2011, 07:38:47 pm »
Yes they are. What exactly is your problem?

Offline ndr123

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Lights
« Reply #2 on: November 30, 2011, 02:15:13 pm »
I have a room created through
Code: [Select]
walls = new Object3D[6];

//create and set back wall
walls[0] = new Object3D(2);
walls[0].addTriangle(new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
walls[0].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
walls[0].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
//walls[0].setAdditionalColor(wall);
walls[0].calcTextureWrap();
walls[0].setTexture(wall_text);
walls[0].strip();
walls[0].build();

//create and set bottom wall
walls[1] = new Object3D(2);
walls[1].addTriangle(new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
walls[1].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0));
//walls[1].setAdditionalColor(wall);
walls[1].calcTextureWrap();
walls[1].setTexture(wall_text);
walls[1].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
walls[1].strip();
walls[1].build();

//create and set top wall
walls[2] = new Object3D(2);
walls[2].addTriangle(new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0));
walls[2].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
//walls[2].setAdditionalColor(wall);
walls[2].calcTextureWrap();
walls[2].setTexture(wall_text);
walls[2].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
walls[2].strip();
walls[2].build();

//create and set right wall
walls[3] = new Object3D(2);
walls[3].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0));
walls[3].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
//walls[3].setAdditionalColor(wall);
walls[3].calcTextureWrap();
walls[3].setTexture(wall_text);
walls[3].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
walls[3].strip();
walls[3].build();

//create and set left wall
walls[4] = new Object3D(2);
walls[4].addTriangle(new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
walls[4].addTriangle(new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, CARTESIAN_DEPTH));
//walls[4].setAdditionalColor(wall);
walls[4].calcTextureWrap();
walls[4].setTexture(wall_text);
walls[4].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
walls[4].strip();
walls[4].build();

//create and set front wall
walls[5] = new Object3D(2);
walls[5].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0));
walls[5].addTriangle(new SimpleVector(HALF_CARTESIAN_WIDTH, HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(-HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0), new SimpleVector(HALF_CARTESIAN_WIDTH, -HALF_CARTESIAN_HEIGHT, 0));
walls[5].setTransparency(0);
walls[5].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
walls[5].strip();
walls[5].build();
where the macros and the variable are declared in this way:
Code: [Select]
private final int CARTESIAN_WIDTH = 63;
private final int CARTESIAN_HEIGHT = 34;
private final int CARTESIAN_DEPTH = 50;
private final float HALF_CARTESIAN_WIDTH = 31.5f;
private final float HALF_CARTESIAN_HEIGHT = 17f;

private Object3D[] walls = null;

My problem is that is, if I put a light in (0,0,-150) top and bottom wall does not get lighted. So I worked around this by placing 2 lights which are respectively in (0,-50,-200) and in (0,50,-200). With the two lights placed that way, all the walls get lighted. My problem is that I needed to place a new light inside the room (for example, in (12, 5, 29)), but once again the back and top wall does not get lighted by that light. I searched in che Config class to see if the was some variable I could modify to try to make it work but the only one I found is Config.maxLights and I tried increasing it (currently it is set to 24 in my application) but the problem is still there

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Lights
« Reply #3 on: December 01, 2011, 07:03:09 am »
Creating a room out of 6 single wall objects isn't the best way to achieve good lighting. Here's why: When calling build(), jPCT calculates the vertex normals based on the face normals of adjacent polygons within the same object. In this case, either no polygons are adjacent or if they are, they have the same face normal. That means that all vertex normals of a wall are in parallel. Try to merge your walls into a single object instead (or create it as such) and see if that helps to improve the lighting.

Offline ndr123

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Lights
« Reply #4 on: December 01, 2011, 11:04:10 am »
Yes, merging them into a single object helps. The result is still not so good but it is due to the very few triagle used in making the walls (I can see more or less the triangles on the walls). Can you suggest me an easy way to build walls with more triangles?