Author Topic: How to draw a line...  (Read 5049 times)

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
How to draw a line...
« on: April 03, 2008, 09:54:37 am »
Hi,

I would like to know how can I draw a line in jpct (like in a wireframe mode.. triangles are drawn with lines i suppose?) while I'm in a normal rendering mode.

Thanks in advance.

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to draw a line...
« Reply #1 on: April 03, 2008, 03:20:21 pm »
I think you want the world drawn in wireframe? So, in your rendering loop instead of using world.draw(...) call world.drawWireFrame();

If you want to just draw a line, then get the graphics context from your canvas with getGraphics and then call graphics.drawLine(...);

Jman
« Last Edit: April 03, 2008, 03:24:05 pm by JavaMan »

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
Re: How to draw a line...
« Reply #2 on: April 03, 2008, 03:34:32 pm »
I think you want the world drawn in wireframe? So, in your rendering loop instead of using world.draw(...) call world.drawWireFrame();

If you want to just draw a line, then get the graphics context from your canvas with getGraphics and then call graphics.drawLine(...);

Jman

No, I don't want to draw a world in a wireframe and also I don't want to draw a line on the top of the rendered image... I want to draw a line inside the world... for example behind some object in 3d world... I understand that this could be done with the "Primitives" class (draw a line as a cylinder for example)... but I'm wondering whether this is the only way or there are some other ways... 

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: How to draw a line...
« Reply #3 on: April 03, 2008, 03:41:41 pm »
OH, ok. Well then I guess you could just create an object with one triangle like this. I think this would work.

Code: [Select]
Object3D line = new Object3D(1);

SimpleVector p1 = new SimpleVector(0,0,0);
SimpleVector p2 = new SimpleVector(0,.1,300);
SimpleVector p3 = new SimpleVector(0,0,300);

line.addTriangle(p1,p2,p3);

line.addTriangle(p2,p1,p3);

« Last Edit: April 03, 2008, 03:43:53 pm by JavaMan »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How to draw a line...
« Reply #4 on: April 03, 2008, 05:29:59 pm »
Using a kind of distorted plane (i.e. two triangles) may be a better idea then just one triangle. I think it depends on the scene, what will look good. Maybe two planes forming a cross is required, if the line should look like a line from all angles. Of course, you can use Java2D or OpenGL directly to draw a line but in both cases, you'll run into problems, because the line won't be affected by the zbuffer, which will cause it to overdraw objects that are in front of the line.
What exacty do you want to use that "line" for?

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: How to draw a line...
« Reply #5 on: April 04, 2008, 03:35:48 am »
Here's the code I used;

Code: [Select]
public Object3D createLine3D(SimpleVector from, SimpleVector to)
{
Object3D object=new Object3D(4);

SimpleVector delta=to.calcSub(from);
SimpleVector zaxis=delta.getRotationMatrix().getZAxis();
zaxis=zaxis.normalize();
zaxis.rotateY(1.571f);
SimpleVector from1=new SimpleVector(from);
from1.add(zaxis);
SimpleVector to1=new SimpleVector(to);
to1.add(zaxis);
object.addTriangle(from, 0, 0, from1, 0, 1, to1, 1, 1);
object.addTriangle(to1,1,1,to,1,0,from,0,0);
from1=new SimpleVector(from);
from1.y-=2f;
to1=new SimpleVector(to);
to1.y-=1f;
object.addTriangle(from, 0, 0, from1, 0, 1, to1, 1, 1);
object.addTriangle(to1,1,1,to,1,0,from,0,0);
object.build();
object.setCulling(Object3D.CULLING_DISABLED);
return object;
}


Offline fosb

  • byte
  • *
  • Posts: 9
    • View Profile
Re: How to draw a line...
« Reply #6 on: February 27, 2011, 02:08:10 pm »
Hi,

is there a problem if i draw many cylinders like that:


Code: [Select]
cylinder = Primitives.getCylinder(2, 0.1f, 100000f);

to get many lines in that way (like, to draw a grid)?


thanks
« Last Edit: February 27, 2011, 08:06:25 pm by fosb »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: How to draw a line...
« Reply #7 on: February 27, 2011, 08:16:15 pm »
No problem as far as i can see. If it's the best solution depends on the actual problem. In some cases, a texture might be more appropriate and faster.