Author Topic: Please help me in creating a room layout in JPCT 3D Java engine  (Read 1600 times)

Offline kiran.hereu

  • byte
  • *
  • Posts: 4
    • View Profile
Please help me in creating a room layout in JPCT 3D Java engine
« on: September 05, 2014, 09:56:49 am »
Hi All,

I am new to coding and I do know few basics of java. Now I am trying to create a room layout with floor and walls, and searching for a sample code which might give me some understanding and did not find one.

If anyone has worked on this type of project, please help me with the sample code so that I will from there.

Thanks in advance.


Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #1 on: September 05, 2014, 03:19:14 pm »
Do you mean something like the following?

Code: [Select]
Object3D floor = Primitives.getPlane(1, 10f);
Object3D wall1 = Primitives.getPlane(1, 10f);
Object3D wall2 = Primitives.getPlane(1, 10f);
Object3D wall3 = Primitives.getPlane(1, 10f);
Object3D wall4 = Primitives.getPlane(1, 10f);
//NOW ROTATE EACH PLANE INTO POSITION WITH plane.rotate_(float)
wall1.translate(-5f, 0, 0);
wall2.translate(5f, 0, 0);
wall3.translate(0, 0, 5f);
wall4.translate(0, 0, -5f);
world.addObject(floor);
world.addObject(wall1);
world.addObject(wall2);
world.addObject(wall3);
world.addObject(wall4);
world.buildAllObjects();

Offline kiran.hereu

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #2 on: September 05, 2014, 09:03:30 pm »
Hi AGP,

Thanks for the reply.

I tried using the code, but all I could see is a parallel vertical  planes facing each other. Am I missing something?

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #3 on: September 06, 2014, 01:00:45 am »
Did you rotate the planes, as per the comment in the middle of the code?

Offline kiran.hereu

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #4 on: September 06, 2014, 10:26:57 am »
Hi,

I did rotate the plane, first I am trying to connect two planes like a wall and floor. below is my code

Object3D floor = Primitives.getPlane(9, 10f);
Object3D wall1 = Primitives.getPlane(9, 10f);
floor.rotateX((float) Math.PI / 2f);
wall1.translate(-40f, 0, 0);
world.addObject(floor);
world.addObject(wall1);
world.buildAllObjects();

it is bisecting the floor, instead of adding at the end of the floor. Do I need to rotate wall as well? If yes how much I need to rotate it and on which axis?

Thank You.


Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #5 on: September 07, 2014, 09:32:56 am »
You're creating insanely large planes. They are, if I'm not mistaken, 90 units in size. Then you're translating wall by 40 units, which is close to the edge (it should, if they really are 90 units in size, be 45). Of course since you created both planes in the same place and you never translated floor down, floor would, along the y axis, be in the middle of wall. Do floor.translate(0, 45f, 0) to set the floor to just under the wall. That should do it.

Offline kiran.hereu

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #6 on: September 07, 2014, 03:13:28 pm »
Hi,

I tried floor.translate(0,45,0) still the wall bisecting the floor. I tried different combinations for positioning the wall, I could say I was 40% succeeding it. Is it a kind of hit and trail to position an object?

Now I am using the collision demo example given in the wiki and trying to place walls across the plane given there. I just added the single plane as wall and it was not at the edge of the plane. The code is below. I tried several combinations to move it to the edge. There is no issue with floor now, still do I need to translate the floor? Attached the screenshot for your reference.

plane = Primitives.getPlane(20, 10);
plane.rotateX((float) Math.PI / 2f);
Object3D wall = Primitives.getPlane(10, 20);
wall.rotateZ((float) Math.PI / 2f);
wall.translate(40,-20,70);

Thank You.

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Please help me in creating a room layout in JPCT 3D Java engine
« Reply #7 on: September 10, 2014, 08:09:13 am »
Have a look at the docs to see by exactly how much you ought to translate the planes. I think that it's a safe assumption that the rotation pivots of the planes are in their middle. So then, all that you need to know is how big they are in order to determine by how much they should be translated.