Pb with dragging point

Have jReality programming problems or questions? Post them here.
Post Reply
finkel
Posts: 2
Joined: Thu 14. May 2009, 11:26

Pb with dragging point

Post by finkel » Thu 14. May 2009, 16:24

Hi,
first, I would apologize for my bad english.
I'm pretty bad in coding, soo i apologize too if my problem
come from a big mistake.

I'm programming an interface for modeling a 2D figure using
Jreality but I have to face a problem. i choose to use Jreality
although it's for modeling in 2D because there are
great documentation&tutorial.

I create a square using the indexesFaceFactory but
in reduction the dimension to 2 [code1],
then I incorporate your drag method issu from
DragEventTool1.java to give the possibility to modelize the square.
I modify it a bit for not considerate the third dimension [code2]
I also desactivate the rotateTool.
After incorporate the whole thing in a frame, it give a square.

When i move the first and third vertex in the inside of the
square, all is alright, i can merge the two vertices and have a sort of
V with only the edges visible,
but when i try this modification with the second and the last,
i can't create something smaller than a triangle, i.e. i can't create angle bigger
than 180° if the vertex is the second ( index 0) or the fourth( index 2).



I also try to draw another object instead of a indexedFaceSet, a quad mesh with
your quadMeshExample.
I try this time in 3D , and it seems that the problem could be with the dragging
and the third dimension, but I thought that my code deal with this dimension.
But maybe it's not a problem of dimension?

Here is my code.
Of course i try without the modifications about the third dimension,
but it still doesn't work as i wish.


Edit :
i have another question,
is it possible to add a vertex to a face already draw without
redrawing it? i mean, in the case of i want to add a vertex on a edge,
then move the vertex ; creating from this edge two edges.


Code 1

Code: Select all

[...]

SceneGraphComponent myComponent = new SceneGraphComponent();
IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
double[][] vertices = new double[][] { { 0, 0, 0 }, { 3, 0, 0 },{ 3, 3, 0 }, { 0, 3, 0 } };
int[][] faceIndices = new int[][] { { 0, 1, 2, 3 } };

ifsf.setVertexCount(vertices.length);
ifsf.setVertexCoordinates(vertices);
ifsf.setFaceCount(faceIndices.length);
ifsf.setFaceIndices(faceIndices);

[...]

code 2

Code: Select all


public void pointDragged(PointDragEvent e) {
PointSet pointSet = e.getPointSet();
double[][] points = new double[pointSet.getNumPoints()][];
pointSet.getVertexAttributes(Attribute.COORDINATES).toDoubleArrayArray(points);
double[] positionWithoutDepth = e.getPosition();
positionWithoutDepth[2] = 0;
points[e.getIndex()] = positionWithoutDepth; //e.getPosition();
pointSet.setVertexAttributes(Attribute.COORDINATES,StorageModel.DOUBLE_ARRAY.array(3).createReadOnly(
								points));
viewer.render();
			}


User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Re: Pb with dragging point

Post by steffen » Thu 14. May 2009, 16:59

i can't create something smaller than a triangle, i.e. i can't create angle bigger
than 180° if the vertex is the second ( index 0) or the fourth( index 2).
What you see when you move the vertices is some random triangulation that OpenGL does when it should render a polygon. The first thing you can do is to draw edges instead of faces. Do the following:
1. configure the factory to generate edges from faces:

Code: Select all

ifsf.setGenerateEdgesFromFaces(true);
2. disable face drawing (in setupAppearance(Appearance ap)):

Code: Select all

dgs.setShowFaces(false);
Or just use an IndexedLineSetFactory instead of the IndexedFaceSetFactory...
We also have a method that triangulates non-convex polygons, but it doesnt work right now. I will see if we can find the problem...

finkel
Posts: 2
Joined: Thu 14. May 2009, 11:26

Re: Pb with dragging point

Post by finkel » Thu 14. May 2009, 17:32

ok, thank you for this response.
so no faces for non-convex polygons : )
Have a good day.

Post Reply