Home > jiglibflash, papervision3d > creating a room in jiglibflash

creating a room in jiglibflash

 

jiglib_room1

 

Alright, so I finally got a few hours to nail down my first demo with jiglibflash. This one shows a room with 4 walls and a floor to contain the ball. I left in some “debris” to knock around. This could be the basics for a racquet ball game or similar. The set up is pretty straight forward. I grabbed the current rev from here which was rev 25. I read through as much of the class code as I could quickly get my head around and dove in. 

 

Space bar to jump, arrows to move ball around.

So the first thing to realize when setting up walls is that the code is well a little funky.

plane3.MoveTo(new JNumber3D(-250, 300,0),JMatrix3D.rotationY(90  * Math.PI/180));

Ok so whats this do? Well, this is using the MoveTo method of the JPlane class to position in the world. (Yeah the syntax could use some help). So there are 2 tricks:

  1. the second parameter of MoveTo uses the SetOrientation method which expects a JMatrix3D value. Some examples are JMatrix3D.IDENTITY and then various rotations (rotationX,rotationY,rotationZ) The thing to remember is these are radians. The easiest way to convert degress to radians is: degrees * (Math.PI /180)So step 1, get the walls oriented correctly. You need 2 rotated about the X-axis and 2 rotated about the Y.
  2. position objects for the first parameter by their centers.  In my example above you see, I have set that wall to be the wall on the left at -250 on the x and at 0 on the Z. The opposite wall is at 250 on the x and 0 on the Z.

That’s about it, nothing too fancy; my version of a quick hello jiglibgflash.

Categories: jiglibflash, papervision3d Tags:
  1. January 22nd, 2009 at 08:34 | #1

    wicked stuff!

  2. January 22nd, 2009 at 18:11 | #2

    Hey i have a question on using jiglib and PV3D.
    Have a look at this pool table i made. I took the example from the jiglib website and modified it to make this pool table.

    The problem is, some times the balls on the table jump out even though i have a wall around it(the wall is 500 height so its definitely not going over the wall). could you please help me with this?

    you can find the code at
    http://www.thivy.com/blog/index.php/archive/jiglibflash-3d-physics-engine/

  3. January 22nd, 2009 at 19:37 | #3

    Hey Thivy,

    It looks like the walls are not high enough. You say they are, but the walls in your table are short and visually the balls can get over the walls. Make sure both the PaperVision object (im assuming thats what you’re using) and the jiglib object are the same dimensions; that they correspond. I’m guessing they are different right now. I’d start by making sure they are the same and then test. After that experiment with them being different. The other approach might be to place “invisible” walls around the table as well. So ones with a skin that is on the back side of the PV wall only for example. That’s how I created my “4th wall” in my room example. The wall closest is transparent because I flipped it away from the camera. HTH

  4. January 22nd, 2009 at 21:22 | #4

    Hey i tried your ways but it’s still going out of the wall. When i tried with the example they gave in the jiglib page it does the same thing. If you keep moving the ball towards the back wall you will see what i mean.

  5. January 22nd, 2009 at 21:40 | #5

    @thivy . If you mean this demo here http://www.flashbookmarks.com/demos/jiglibtimestep/ then I can see what you mean. I do not see this occurring in my example here. Let me know if you do. It might be easier to help you out having a peek at your code. Join us at irc server freenode at channel #jiglibflash. Thanks for your interest, see you there!

  6. February 2nd, 2009 at 07:15 | #6

    Hey
    At first good Job !
    I am trying to use this library and i have a problem with the rotation!
    i understood that it is in radian but how can i do to define X Y and Z rotation in the same time
    for exemple if you have only a X rotation i write:
    planePhysic.MoveTo(PlanePosition, JMatrix3D.rotationX(_plane.rotationX*(180/Math.PI) ));
    And it works !
    but if i want X Y AND Z Rotation , i dont know how i can do, this is my solution :
    planePhysic.MoveTo(PlanePosition, JMatrix3D.rotationY(_plane.rotationY*(180/Math.PI) ));
    planePhysic.MoveTo(PlanePosition, JMatrix3D.rotationZ(_plane.rotationZ*(180/Math.PI) ));

    But it doesnt work.
    Could you help me ?

  7. February 2nd, 2009 at 09:18 | #7

    Hey Jey,
    Great question. This is something we hope to get simplified in the code syntax soon. For now try using the multiply function of the JMatrix3D class, like so:
    planePhysic.MoveTo(PlanePosition , JMatrix3D.multiply(JMatrix3D.rotationY(-90* Math.PI / 180), JMatrix3D.rotationX(-90 * Math.PI/180)));

    HTH

  8. February 3rd, 2009 at 06:26 | #8

    Tks A lot, i am going to try !
    Otherwise, how can i get the position of an object, should i get it from the 3d object or can i have it from the PhysikObject ( i would have it )
    tks Richard

  9. wvxvw
    February 5th, 2009 at 17:40 | #9

    Hi. Firstly, great job!
    I’ve a question… are your Matrix3D and Number3D to different from analogues in PV3D, that you need your own? IMO, if they aren’t too different, it’d be better to use those of PVD, or somehow make them compatible… like, maybe, extending PVD classes? (org.papervision3d.core.math.Number3D looks very much the same as jiglib.math.JNumber3D)
    and org.papervision3d.core.math.Matrix3D – jiglib.math.JMatrix3D).

  10. February 5th, 2009 at 20:33 | #10

    @wvxvw, you’re right some of the core classes for 3d are based on some of the pv3d core classes. You can see which ones by having a look inside some of them. We are working through the process of architecting things a little better. One avenue we are considering is how best to make the engine more modular so that it easily works with any 3d rendering engine (Sandy, Away or PV). So while some core 3d math may be taken directly from one engine, it may be that in future it gets tailored more specifically to the physics needs of the engine, and also retains its identity as unique from a similar class from one of the engines. Thanks for the comments!

  11. wvxvw
    February 6th, 2009 at 07:06 | #11

    Hi Richard.
    Thanks for reply!
    Another thing… and, I know it sounds like a pain in the rear place… but, can you by any chance reconsider naming of methods / properties to conform to the conventions? I know, it takes just a few minutes to run your code through some “beautifier” to get all those things sorted out, but, at some point you’d probably like to document it all / make updates / distribute it via SWC etc… so, that’d be a pain to rewrite the code… Or am I asking to much? :)

  1. No trackbacks yet.