• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1112
  • Last Modified:

How to implement bending objects with opengl?

Hello,
I need to implement bending of a 3D object.
How can I accomplish that with as much flexibility as possible,
so I'll have the most control over the object's surface.

0
khdani
Asked:
khdani
  • 14
  • 10
1 Solution
 
ikeworkCommented:
Hi khdani,

Do you mean you want to use soft-body physics? There are physics librarys out there that can do it for you, bullet is one.
Please explain a bit more in detail, what you are trying to do.

ike
0
 
khdaniAuthor Commented:
let's say i 've a hollow 3D tube which is composed of small parts (triangles or quads) because i need
to know the normals to the surface as most precise as possible at every almost point.
i need the ability to bend this tube with user input, and after the deformation the normals should point correctly as they should.

i was thinking about using a parametric curve and then forming the tube around that curve,
it's the most simple solution i though so far.

if there's some more simpler I would be more than glad to hear,
or maybe some other implementation without dividing the tube into small parts but with the ability
to get normals at every point (or approximate normals).

if there's non-commercial licence engine for JAVA  which may help it would be great.









0
 
ikeworkCommented:
Sounds like the soft-bodies of "bullet" would do the job. Look at this:

http://www.youtube.com/watch?v=exss517n1I0

at 1:17 there are those soft-body-rings, pretty much what you were talking about. The bending part of your tube would be a soft body, connected to rigid bodies, for each end of the tube. Its not an easy task though, but physics make a lot of fun, it worths :)

Cant help you on the Java part, I'm a C++ guy. Bullet is free, its a C++ library, dont know if there is a Java-Wrapper, a quick google search will help you there.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ikeworkCommented:
Found a Java-Port for "bullet" here:

http://jbullet.advel.cz/


But if you want the full power of bullet, C++ is a better choice.
0
 
khdaniAuthor Commented:
sorry, this is not what i'm looking for
and i think it would be quicker to implement it myself than learning this engine.
0
 
ikeworkCommented:
>> sorry, this is not what i'm looking for

No problem, just trying to help :)

>> and i think it would be quicker to implement it myself than learning this engine.

Not sure about that. Learning this engine is a good idea anyway, its widely used in the industry and then you have a more general solution, not only for this tube setup.

However, can you explain a bit more in detail, what your app is supposed to do?
0
 
ikeworkCommented:
You might find this SIGGRAPH papers useful, loot at the papers in paragraph "Shape Editing and Deformation"
   
  http://kesen.huang.googlepages.com/sig2009.html
0
 
khdaniAuthor Commented:
i've thought of mine implementation for bending a tube,
i'm only a little stuck with rotations, i'll be glad if you help with that.

on fig1 you can see a line created with small lines (don't pay attention to spheres, and axises)
lets say every small line L is from some point a to some point b, in other words L = (a,b).
i want to rotate every small line 90 degrees CCW about point a. (like in fig2)
but i need the coordinates of b after rotation.
what i did with opengl to rotate this is

[code]
glTranslatef(a.x, a.y, a.z)
glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
glTranslatef(-a.x, -a.y, -a.z);
[/code]

if i create my own matrix of translation and rotation and then multiply the point b, i get the rotation about
origin (like in fig3), i don't understand why ?





fig1.png
fig2.png
fig3.png
0
 
khdaniAuthor Commented:
the way i thought to implement tube bending is
create control points and interpolate through them
after that draw a surface around the interpolated points
that way i can bend my tube

i would be more than glad to hear a better idea...
0
 
ikeworkCommented:
>> [code]
>> glTranslatef(a.x, a.y, a.z)
>> glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
>> glTranslatef(-a.x, -a.y, -a.z);
>> [/code]
>> 
>> if i create my own matrix of translation and rotation and then multiply the point b, i get the rotation about
>> origin (like in fig3), i don't understand why ?

Can you show the code, where you create your own matrices and multiply them (the more code the better)
0
 
ikeworkCommented:
Didnt see your last post, when posting mine.

>> the way i thought to implement tube bending is
>> create control points and interpolate through them
>> after that draw a surface around the interpolated points
>> that way i can bend my tube

I dont quite understand, what you mean by "interpolate through them".
Your input will be something like: "bending angle is 30 degrees", there is nothing to interpolate, at least that I can see. An interpolation is to calculate a point between 2 points by a given weight (linear). Here we talking arcs. Maybe you can explain a bit more.

>> i would be more than glad to hear a better idea...

Splines come to my mind
0
 
ikeworkCommented:
Particulary Catmull-Rom Splines, because they will go through all control points, in contrast to Bezier Curves and other Splines:

The 1st link uses directx, but the point is the spline, not the rendering:

http://www.mvps.org/directx/articles/catmull/

http://www.codeproject.com/KB/recipes/Overhauser.aspx

You will find more examples with google.
0
 
khdaniAuthor Commented:
i did create my own matrices, but for testing lets take GL's matrix,
so after (it's java bindings for opengl, pretty much the same as for C)
[code]
gl.glTranslatef(a.x, a.y, a.z);
gl.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
gl.glTranslatef(-a.x, -a.y, -a.z);
[/code]

i do

[code]
float m[] = new float[16];
gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, m, 0);

float[] point = new float[4];
float[] bp = b.getPoints();    //get float array of b values

//multiplication
point[0] = m[0] * bp[0] + m[4] * bp[1] + m[8] * bp[2];
point[1] = m[1] * bp[0] + m[5] * bp[1] + m[9] * bp[2];
point[2] = m[2] * bp[0] + m[6] * bp[1] + m[10] * bp[2];            

gl.glBegin(GL.GL_LINES);
gl.glVertex3fv(a.getPoints(), 0);
gl.glVertex3fv(point, 0);
gl.glEnd();
.
.
[/code]


0
 
khdaniAuthor Commented:
>> Splines come to my mind

I used natural cubic spline, which pretty simple
0
 
ikeworkCommented:
Perfect, then go Catmull-Rom Spline, the 2nd link to codeproject has all you need
0
 
ikeworkCommented:
Wait, I forgot something, the point is to *animate* the control points depending on the degree of bending.
I think about it, gimme a sec..
0
 
ikeworkCommented:
The more I think about it, a spline wont help much .. the control points are not static, the point is to calculate the control points. Sorry, wrong direction ..
0
 
khdaniAuthor Commented:
thanks, i'll check it out
but the real problem is rotation/transformation,
i have posted my code
0
 
khdaniAuthor Commented:
yes the control points are static
but the user can move them, and i will re-interpolate again every time the user
moves control points and this will make it like bending a tube.
0
 
ikeworkCommented:
>> yes the control points are static
>> but the user can move them, and i will re-interpolate again every time the user
>> moves control points and this will make it like bending a tube.

ok

>> but the real problem is rotation/transformation,
>> i have posted my code

You forgot to include the last column of the matrix, where the position is stored m[12] m[13] and m[14]
Try this:

point[0] = m[0] * bp[0] + m[4] * bp[1] + m[8] * bp[2] + m[12];
point[1] = m[1] * bp[0] + m[5] * bp[1] + m[9] * bp[2] + m[13];
point[2] = m[2] * bp[0] + m[6] * bp[1] + m[10] * bp[2] + m[14];
0
 
khdaniAuthor Commented:
yes, you right, forgot about that :)
i also needed to reset my matrix to see the rotation :)
where can I read about the OpenGL's matrix components,
I mean what exactly is position and direction?

Thank You Very Much for Your Help !

i probably will have more questions with that, would be very great if you
help me.



0
 
khdaniAuthor Commented:
Thank You!!!!
0
 
ikeworkCommented:
>> where can I read about the OpenGL's matrix components,

The matrix defines the coord-system. Here are the details:

1st vector, mtx-elements 0 -3  : (R) right vector of the coord-system
2nd vector, mtx-elements 4 -7  : (U) up-vector of the coord-system
3rd vector, mtx-elements 8 -11 : (D) (negated) direction vector of the coord-system
4rd point , mtx-elements 12-15 : (P) position(origin) of the coord-system

You can see it quite well in the identity matrix

R  U  D  P
1  0  0  0
0  1  0  0
0  0  1  0
0  0  0  1


Hope it helps :)

ike

Open in new window

0
 
ikeworkCommented:
A great resource about Math in terms of Geometry is here:

Particluary Matrix:

  http://www.euclideanspace.com/maths/algebra/matrix/index.htm

This site has more very useful information in that matter, it worths studying :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 14
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now