• Content count

  • Joined

  • Last visited

Community Reputation

103 Neutral

About nkint

  • Rank
  1. Hi! 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: [url="http://www.openprocessing.org/sketch/8405"]http://www.openproce...org/sketch/8405[/url] 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 [left]wiggly way.[/left] 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?
  2. Extend curve to tube surface (part 3)

    control points was already minimized. i had vound a bug in the code, i was missing an if statement! thanks anyway!!
  3. 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 toroide LineStrip3D 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: [img]http://oi46.tinypic.com/34yvjpf.jpg[/img] now, i'm trying to do a tube on mouse drawing, and i'm getting weird results: [img]http://oi45.tinypic.com/14e9xtg.jpg[/img] : 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) [img]http://oi50.tinypic.com/2v2gw42.jpg[/img] 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: [url="https://github.com/nkint/tubesP5/blob/master/src/ptf/ParallelTransportFrame.java"]https://github.com/n...sportFrame.java[/url]
  4. ok i got it it was stupid : ) picking ray needs to be horizzontal to clipping cube
  5. ok if i put mouse coordinate z (3° input in gluUnproject) as 0.8 instead of 1 everything is ok. why? ho can i calculate the exactly z value with other canvas dimension or different projections matrix?
  6. 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: http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html now.. firstofall: 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 x1: 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? x2: 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]
  7. hi i have two parallel rectangles (so no rotation) and i want to find all shapes formed by intersection. this is an example: 1----------2 | | | 5----9----6 | | | | 3----10----4 | | | | | 7---------8 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: 1,2,9,5,10,3 5,9,10,4 9,6,8,7,10,4 i hope you understand, sorry for my bad english
  8. thanks for answer! Quote:Try to use correct grammar and punctuation in your posts. : ) thanks for advice, i'm learning english! forums is additional helps Quote:Remember, programming is communication. +1 Quote:But game code gets used once, has a single high-cost intensive debugging phase (alpha & beta cycle), and then is largely discarded; TDD does not make sense for it. yeah, but i think TDD is only a design practice, functional tests is only a side-effects, and not totally fill test phase in software lifecycle
  9. hei guys at university i'm studing agile programming and extreme methodologies, tdd, etc is thoose concepts applied to game dev?
  10. i don't think that mat and physics is the best section in which write about grid issues.. mayebe isometric land is better (and also i don't think this is the best forum for actionscript language..) Quote:so, how can i programaticaly find the point of (row x column) the data structure at the base of a grid is a bidimensional array, so you can use a nested for loops to get some points: for(x=0;x<10;x++) { for(y=0;y<10;y++) { // do something with point x-y }} this will iterate trought a 10x10 grid. Quote: how can i draw this Grid programaticaly to locate x and y in Actionscript tou can use a Sprite object to draw, now i don't remember exact syntax but you can fin it here: http://www.adobe.com/devnet/flash/quickstart/drawing_commands_as3/#section1 Quote:how can i find X and Y using ActionScript 3.0 Functions? you have a virtual coordinate system that is your grid. for example you know that there is an actor at coordinate 3-5 (row 3, column 5) in the screen space the real X is 3*pixel_of_each_gridbox the sprte is large 100 pixel, you've got a grid of 10x10 formed by 10pixel box. the real position of actor in sprite coordinates is 30x50 Quote:how can i calculate the distance between x and y ? i think using pitagora formaul is the best way hope responding your question i leave you some links, mayebe could be useful http://www.as3blog.org/?p=50 http://www.yarrcade.com/category/game-development/grids/
  11. Extend curve to tube surface (part 2)

    thanks for replay, good solution! i'll try to implement it. but the things in which i'm interesting more is about switched normals. ohu, my code for now is works perfectly, it's only a question of understanding why.. i don't understand because, in parallel transpot frame approach, i have to take the normal of the last frame BUT switchs it signs after rotation, old_normal = normals[i-1]; old_normal.normalize(); old_normal.rotateAroundAxis(b,theta); old_normal.x = -old_normal.x; old_normal.y = -old_normal.y; old_normal.z = -old_normal.z; well.. if you don't want to follow details no problem, code for now works perfectly, i'm really thank for you help!
  12. hi guys i tried to reply this thread: Extend curve to tube surface (part 1) but seems not working anymore (?) by the way, bit summary: i have a curve (a bezier, but for tests and sketches i'm using a torus knot for semplicity) as a list of points, and i want to make a tubolar surface over it. for that i have to find a frame, that is composed by 3 vectors: tangent, binormal and normal, in each point. for that user jyk and apatriarca advice me to a parallel transform frame, good thecnique. it works! it consists in calculate the first frame in first point and rotate it follow rotation angle of tangents. i've found good reference: Parallel Transport Approach to Curve Framing by Hanson and Ma Game Programming Gems 2, The Parallel Transport Frame in this previous post: http://www.gamedev.net/community/forums/topic.asp?topic_id=577287 BUT: #1 - find the first frame is a problem, i used approximations of frenet frame. #2 - nowhere in reference i found that i need to recalculate cross product to find normal and binormals (!! how this is possible?? by the way thanks apatriarca you show me the way in last post) #3 - in the end.. i found normal and binormal correctly but there was a big problem: normals was switched: one directed inside, one outside. i have to take the normal in previous frame but change it signs. why??? here is my code, in pseudojava, hope this will be usefull for someone in future: Vec3D points[]; // curve point list Vec3D tangents[]; Vec3D binormals[]; Vec3D normals[]; void calculateFrames() { // first frame, needed by parallel transport frame approach // frenet method is used. // __approximations__ of tangents Vec3D p0, p1, b; p0 = points[0]; p1 = points[1]; tangents[0] = getTangentBetweenTwoPoint(p0, p1); p0 = points[1]; p1 = points[2]; tangents[1] = getTangentBetweenTwoPoint(p0, p1); b = tangents[0].cross(tangents[1]); b.normalize(); binormals[0] = b; normals[0] = b.cross(tangents[0]); // all tangents, needed for p.t.f. // again, __approximations__ // #1 for(int i=1; i<100-1; i++) { p0 = points[i]; p1 = points[i+1]; tangents[i] = getTangentBetweenTwoPoint(p0, p1); } // p.t.f approach: Vec3D old_normal; for(int i=1; i<100-2; i++) { p0 = tangents[i]; p1 = tangents[i+1]; // this is what is called A in game programming gems // and B in Hanson and Ma article b = p0.cross(p1); b.normalize(); // normals theta = acos(p0.dot(p1)); old_normal = normals[i-1]; old_normal.normalize(); old_normal.rotateAroundAxis(b,theta); // here switching signs. no reference, no understanding, // empirical method founded for random choice. // #3 old_normal.x = -old_normal.x; old_normal.y = -old_normal.y; old_normal.z = -old_normal.z; // ma questi due ulteriori cross da dove vengono fuori?! // #2 binormals[i] = tangents[i].cross(old_normal); normals[i] = tangents[i].cross(binormals[i]); println("it should be PI/2: "+PI/2); // println(Vec3D.angleBetween(binormals[i], tangents[i])); // println(Vec3D.angleBetween(normals[i], tangents[i])); // println(Vec3D.angleBetween(normals[i], binormals[i])); // assertation tests here } } i hope this helps, strange that there is nowhere tutorials about this, it is a tech quite used for all tubolar-res [Edited by - nkint on September 4, 2010 6:29:04 AM]
  13. hi! thanks for answer my problem is not about push or pop matrix, the object is in the place i want Quote: What happens currently when you drag the mouse? i've tried this code: public void mouseDragged(MouseEvent e) { deltax = e.getX() - (int)mouseDown.x; deltay = e.getY() - (int)mouseDown.y; mouseMoved(e); setRot(new Point3D(deltax, deltay, 0)); } public void setRot(r) { this.r_offset = r; } @Override public void display(GLAutoDrawable drawable) { //blabla glClear, glLoadIdentity, etc.. //gl.glTranslatef( blabla gl.glRotatef(r_offset.x,0,1,0); gl.glRotatef(r_offset.y,1,0,0); render(gl); //do all scene } public void render { (i tried a lots of combinations) i undesrtand that i'm rotating only 2 axis and so there is something that must be wrong, but i've got only 2 points with mouse and in 3d space i have 3 coordinates. please, it requires only two minutes, see the website i've posted, there is an applet with movement i want to simulate. with dragging mouse (only 2 coordinates) they change rotation in space (3 coordinates), but i don't undestand how
  14. hi all yet another stupid post about camera operation, for rotations and pans. first of all, i'm doing jobs with JOGL, i'm on Eclipse ide, and i have zero knowledge on 3d stuffs, hope not be too lame. i want to make some nice effects, like the one linked below, but i didn't managed to. in past with a java framework called prcoessing.org i've used this lib: http://mrfeinberg.com/peasycam/ (with the java applet and rotation effect i want to make) really good one!, but now i'm out of that framework and want to try to do it myself, wihtout ready-to-use libs. i've tried to read the java code but i didn't understand a lot.. i grabbed that they use apache.geometry for rotations, and maybe quaternions. i have a central object in position 0,0,0 and i've tried to rotate it following -the mouse-drag movement like that: gl.glRotatef(rot.x,1,0,0); gl.glRotatef(rot.y,0,1,0); // all scene here // blabla and rot is a vector with the movement of mouse dragged in screen. it is really no nice, i don't understand if it's because i'm appling rotation on object and not on camera or because of quaternion (i'm studing..) and i'm looking for advice or some nice articles that explains some kind of experiments about rotations and pitch. (in some games pitch and roll are linked for same movment or similar) thanks! sorry for confusion
  15. Extend curve to tube surface

    jyk said: "Or, you can compute the derivative from the original Bezier curve (which isn't hard)." no, it's not hard. but i don't have a normal bezier. i have an helix that goes with the trunk of a bezier. the equation of my special curve is: p(t) = r*cos(t*u)*_n_ + r*sin(t*u) *_b_ + k*t*_t_ where r and k are parater of the helix. u is a another angula parameter, and _t_, _n_ and _b_ are tagnet, normal, binormal of the bezier that is the trunk of my special final helix. i want to make tubolar surface of p(t). so i need the frenet frame of p(t). i think it's bit hard get this second derivates. and if it's not hard is no flexible way: if the trunk change with a not more bezier but.. i don't what, simple parabol or others, i have to do too much recalculus. ok, i understan the approximation of the 1° derivates (my points are dense enough), but there is a way for approximate the second der? there is a way? for me it is cleaner approach. i think for now i'll try the parallel transport fram, that is tricky. i re-read the links and they are good, i think i can use this thecnique, even if i would prefer to have method for 1° and 2° deriv. for an arbitrary curves. by the way, what is "Vector3 N = d1.MinAxis;" that use the code of xnt i posted? thanks to all, i never seen a forum with hardmath and lowcoders as this one!