Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Apr 2010
Offline Last Active Jul 15 2012 07:03 AM

Topics I've Started

What kind of Inverse Kinematic is used here?

12 July 2012 - 05:21 AM

I'm going to code some 3d creatures like snakes or tentacles.
For inspiration i've looked for some code around on the net and i've found this one:
ok, i like it.

It is a simple structure: a list of nodes, the first node is the main direction, the other nodes follow the first in a fluid and

wiggly way.

the algorithm is quite easy:

1 calculate the position of the head (the direction of the creature)
2 this procedure is used:

[source lang="java"]void move(float headX, float headY, float headZ) { float dx, dy, dz, d; // node 0: position, direction, orbiting handle nodes[0].x = headX; nodes[0].y = headY; nodes[0].z = headZ; // node 1: muscule count += muscleFreq; nodes[1].x = nodes[0].x ; nodes[1].y = nodes[0].y + PApplet.sin(count) ; nodes[1].z = nodes[0].z + PApplet.cos(count) ; // apply kinetic forces down through body nodes for (int i = 2; i < nodes.length; i++) { dx = nodes[i].x - nodes[i - 2].x; dy = nodes[i].y - nodes[i - 2].y; dz = nodes[i].z - nodes[i - 2].z; d = PApplet.sqrt(dx*dx + dy*dy + dx*dx) *ks; float dx_d = + (dx * girth) / d; float dy_d = + (dy * girth) / d; float dz_d = + (dz * girth) / d; nodes[i].x = nodes[i - 1].x +dx_d; nodes[i].y = nodes[i - 1].y +dy_d; nodes[i].z = nodes[i - 1].z +dz_d; } }[/source]

with girth as a random number near between 5 and 15 and muscleFreq between 0.1 and 0.2 i get nice results.

now, i understand that this is not the real inverse kinematics but.. if i check on google about IK i found a lot of maths and a lot of methods like angles, CCD, Jacobs..
my question is:
i just need to make wiggly creatures. what is this algorithm?
or even.. can you advice me some articles or other way to make chain snake-like creatures?

Extend curve to tube surface (part 3)

27 June 2012 - 06:51 AM

hi, i haved resumed some old code.

my problem is in parallel transport approach. i've coded it in java and for some curves it works perfectly, for example trigonometry parametrized curves suach as circle, spirlas, elicodes, toroide, etc..

here is an example:

[source lang="java"]// PQ Knot toroideLineStrip3D vertices = new LineStrip3D();int p = 2;int q = 4;float theta = 0.1f;float dt = ((MathUtils.TWO_PI) / curve_length);for (int i=0; i < = curve_length+1; i++) { float r = MathUtils.cos(q*theta) + 2; float x = r * MathUtils.cos(p * theta) * 50; float y = r * MathUtils.sin(p * theta) * 50; float z = -MathUtils.sin(q*theta) * 50; theta += dt; vertices.add(new Vec3D(x,y,z));}ptf = new ParallelTransportFrame(vertices.getVertices());tube = new Tube(ptf, 6, 10);tube.computeVertexNormals();[/source]

it works nice:
Posted Image

now, i'm trying to do a tube on mouse drawing, and i'm getting weird results:

Posted Image

the tube framing is somewhere stopping and i can't understand why.
somewhere the normals and binormals are always equals to Vec3D(0,0,0).

here is a pics of only tangents (red), normals and binormals (green and blue)

Posted Image

i also noticed that the problem persists also if i try to use a straight line as a curve..
(the tube is not drawn at all)

can someone can give me some ideas?

parallel transport approach code is here:

yet another stupid post on RAY PICKING

22 December 2010 - 05:51 AM

hi guys
i have to ray pick some points on the screen with JOGL.
i want to use gluUnproject cause i think it is better way instead of selection buffer.

i have 3 points in world (3d) space:
x1: eye's coordinate
x2: mouse coordinate on near plane
x0: point to test

i have to get the distance between between line x1-x2 and see the difference between x0, with this formula:


glu.gluPerspective(45.0f, h, 1.0, 20.0); //near plane is at: 1.0

Vector3D x0 = new Vector3D(0.6, 1, 2); // my target point

glu.gluUnProject(width/2, height/2, 0, mvmatrix, 0,projmatrix, 0, viewport, 0, wcoord, 0);

because my eye's coordinate is at the center of the screen at z = 0, right?
glu.gluUnProject( mouseX,  height-mouseY, 1, blabla);

because my mouse is on my near plane at z = 1.0

and then math for distance between point and line

where am i wrong??
the result is not good.. i thought it should be perfectly calculated but i have to add some offset to get distance <0.2 exactly where is the point..
hope some of you can help me despite my bad english

[Edited by - nkint on December 22, 2010 2:07:17 PM]

find all shapes from 2 intersecated rects

23 October 2010 - 04:59 AM

i have two parallel rectangles (so no rotation) and i want to find all shapes formed by intersection.

this is an example:

| |
| 5----9----6
| | | |
3----10----4 |
| |
| |

first rectangle: 1,2,3,4
second: 5,6,7,8
intersection points: 9,10 (getted by brute force intersecting all segment of first rect with each other of second one.. there is a better way?)

desired output:

i hope you understand, sorry for my bad english

what about programming?

07 September 2010 - 11:23 AM

hei guys
at university i'm studing agile programming and extreme methodologies, tdd, etc
is thoose concepts applied to game dev?