 |
Author |
Topic: objectX/Y/Z (Read 468 times) |
|
depth

|
objectX/Y/Z
« on: Mar 10th, 2004, 4:20am » |
|
hey...i'm trying to find a way to have objects in 3D space converge on the mouse location. as they are each in their own unique transformation matrices, telling them all to go to a particular point does not necessarily cause them to appear to converge. i thought that objectX/Y/Z() could be used for this, and i did some some searching thru the forums. unfortunately, i couldn't get anything to work... here's a simplified version of my code: Code: Ribbon[] ribbons; int numRibbons; int currRibbonNum; void setup(){ size(800, 600); stroke(255, 0, 0); strokeWeight(2); numRibbons = 100; ribbons = new Ribbon[numRibbons]; } void mousePressed(){ ribbons[currRibbonNum] = new Ribbon(); currRibbonNum++; if (currRibbonNum > numRibbons-1){ currRibbonNum = 0; } } void loop(){ background(120, 180, 230); for (int i=0; i<numRibbons; i++){ if (ribbons[i] != null){ ribbons[i].moveMe(); } } } class Ribbon { int x, y, dX, dY, z, zSpeed; Ribbon(){ dX = x = mouseX; dY = y = mouseY; z = -400; zSpeed = 5; } void moveMe(){ //this method is called every loop for every Ribbon z += zSpeed; //track mouse: //translate mouse coords into 3d space, then move towards that point push(); translate(x-width/2, y-height/2, z); int mX = (int)objectX(mouseX, mouseY, 0); int mY = (int)objectY(mouseX, mouseY, 0); dX += (mX-dX)*.05; dY += (mY-dY)*.05; point(dX, dY, z); pop(); } } |
| click on the screen to make new dots (Ribbon). you can see that the dots converge on (mouseX, mouseY) of their own transformation matrix, but not to the, um, 'absolute' (for lack of a better word) position of the mouse. note: oh yeah, and the translation i chose is relevant to my real code. not just arbitrary. but perhaps part of the problem? i dunno. any suggestions? thanks! -depth
|
« Last Edit: Mar 10th, 2004, 4:21am by depth » |
|
|
|
|
|