How to draw a line...

Started by entis, April 03, 2008, 09:54:37 AM

Previous topic - Next topic

entis

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.

JavaMan

#1
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

entis

Quote from: JavaMan 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

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... 

JavaMan

#3
OH, ok. Well then I guess you could just create an object with one triangle like this. I think this would work.


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);


EgonOlsen

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?

Hrolf

Here's the code I used;

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;
}



fosb

#6
Hi,

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


cylinder = Primitives.getCylinder(2, 0.1f, 100000f);


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


thanks

EgonOlsen

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.