Author Topic: How to draw a rectangle  (Read 7481 times)

Offline luispablo

  • byte
  • *
  • Posts: 6
    • View Profile
    • http://www.luispablo.com.ar
How to draw a rectangle
« on: September 04, 2006, 04:39:30 am »
Hi,
  I know this is a VERY newie question :oops:, but I can't draw a rectangle with, for example, one side with 10 and another one with 3. I'm only able to draw squares, with all side with the same length!   :roll:
  Thanks in advance

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
How to draw a rectangle
« Reply #1 on: September 04, 2006, 06:49:57 pm »
Hi, jpct is not a 2d engine so you  can draw only the 3d primitives pre defined, as I remember there is not a rectangular prism, only cubes, if you need it you bay think on drawing a cube and extruding it by some methid that  I dont know or even draw many cubes until get thye desired rectangles and merge all of them into a higher whole shape.
Nada por ahora

Offline luispablo

  • byte
  • *
  • Posts: 6
    • View Profile
    • http://www.luispablo.com.ar
How to draw a rectangle
« Reply #2 on: September 04, 2006, 06:59:42 pm »
I know it's 3D, but I'm trying to build a corridor, and it must have its walls, floor and ceiling in the form of rectangles.
I'm using Primitives.getPlane(), but this method only creates squares. How can I transform them to set its mesures?

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
How to draw a rectangle
« Reply #3 on: September 04, 2006, 07:02:12 pm »
If you want to build a 3d scence you better use a 3d modeling software like 3ds max and load it into jpct.
Nada por ahora

Offline luispablo

  • byte
  • *
  • Posts: 6
    • View Profile
    • http://www.luispablo.com.ar
How to draw a rectangle
« Reply #4 on: September 04, 2006, 07:05:59 pm »
Thanks a lot. I'll take your advice and try to use a modeling soft.
But, anyway, can I draw a rectangle somehow?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
How to draw a rectangle
« Reply #5 on: September 04, 2006, 08:16:55 pm »
Yes, but only by building it yourself. This can either be done by using Object3D.addTriangle() or by merging multiple planes as returned by getPlane() into a rectangle. But that one may not have the texture properties you want. I may add a method to create a rectangle. I can give you the code of Primitves.getPlane(). It should be easy for you to change it in a way that it creates rectangles instead:

 
Code: [Select]

public static Object3D getPlane(int quads, float scale) {
      float startx=-scale*(float) quads/2f;
      float starty=startx;
      float tx=0f;
      float ty=0f;
      float dtex=(1f/(float) quads);
      Object3D obj=new Object3D(quads*quads*2+8);
      for (int i=0; i<quads; i++) {
         for (int p=0; p<quads; p++) {
            float dtx=tx+dtex;
            float dty=ty+dtex;
            if (dtx>1f) {
               dtx=1f;
            }
            if (dty>1f) {
               dty=1f;
            }
            obj.addTriangle(startx, starty, 0, tx, ty, startx, starty+scale, 0, tx, dty, startx+scale, starty, 0,
                            dtx, ty);
            obj.addTriangle(startx, starty+scale, 0, tx, dty, startx+scale, starty+scale, 0, dtx, dty, startx+scale,
                            starty, 0, dtx, ty);
            startx+=scale;
            tx+=dtex;
         }
         starty+=scale;
         startx=-scale*quads/2;
         tx=0;
         ty+=dtex;
      }
      return obj;
   }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
How to draw a rectangle
« Reply #6 on: September 04, 2006, 08:18:31 pm »
BTW: Melssj5 is right when he suggests to use a modelling software instead because building a level out of primitives is very inefficient rendering wise.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
How to draw a rectangle
« Reply #7 on: September 04, 2006, 08:49:53 pm »
:wink:   8)
Nada por ahora

Offline hantu

  • byte
  • *
  • Posts: 1
    • View Profile
Re: How to draw a rectangle
« Reply #8 on: March 13, 2012, 03:12:07 pm »
mark~