|
Author |
Topic: 3D Question (Read 407 times) |
|
Martin
|
3D Question
« on: Mar 11th, 2003, 7:48pm » |
|
hi, how should i approach this? for example i'd want to rotate an element (say, a cube), i could just put it inside loop() together with translate and rotateY for example... now, this would work if i would want to rotate the whole canvas along the y-axis. however, what if i just want to rotate that specific element (the cube), but leaving the other elements (let's say there were some rectangles and ellipses on the canvas) in peace at their original view (y-axis rotation set at original position)? from the top of my head, an algo would be to grab how much the cube rotates, put it in a variable and multiply negative one to that variable then use it to rotate the other elements back to their original position. is there another way, perhaps an easier, more intuitive, way of doing this? for a visual example, consider fry's valence. the spheroid can rotate along the y-axis. however, the text at the lower left of the canvas stays the same.
|
|
|
|
benelek
|
Re: 3D Question
« Reply #1 on: Mar 11th, 2003, 11:07pm » |
|
ive been using {push(), translate, rotate, draw, then pop()} to enclose my seperate elements like this... but it seems to be a slow way of doing it, in terms of processor power. perhaps, as u suggested a while ago, u could use multithreading to do all the transformations alongside each-other... but i'd also appreciate another way to do it -jacob
|
|
|
|
fry
|
Re: 3D Question
« Reply #2 on: Mar 12th, 2003, 3:47am » |
|
it's a combination of the order of operations along with using push() and pop(). for valence, it's something like: push() translate() etc for text draw text pop() push() translate to middle of screen rotateY() based on the mouse dragging scale() to fill screen draw shapes pop() the geometry of the sphere goes from -1 to 1, so the scale multiplies all that up to screen size. this isn't necessary, but that's how it worked in the original (opengl) version. that make sense? are push() and pop() running ridiculously slowly? the problem you describe is the reason they exist, so it'd be a problem if they're so bad that you're coding around them (benelek's 'processor power' comment)
|
|
|
|
_martin Guest
|
Re: 3D Question
« Reply #3 on: Mar 12th, 2003, 6:26am » |
|
thanks fry. push() and pop() did the trick. was interested in understanding it's inner workings and how they actually work ... did a lil example: Code:void setup() { size(200,200); background(80); noStroke(); smooth(); myFont = loadFont("Meta-Bold.vlw.gz"); setFont(myFont); } float a = 0.0; BFont myFont; void loop() { push(); translate(width/2,height/2); rotateY(radians(a)); lights(); fill(255,255,200,80); box(width/3); if(a < 360) { a++; } else { a=0; } pop(); push(); translate(width/2,height/2); rotateX(radians(a)); lights(); fill(200,255,255,80); box(width/3); if(a < 360) { a++; } else { a=0; } pop(); push(); translate(width/2,height/2); rotateX(radians(a)); rotateY(radians(a)); lights(); fill(255,200,200,80); box(width/3); if(a < 360) { a++; } else { a=0; } pop(); fill(255); translate(10,(height)-10); scale(1.2); noLights(); text("push() and pop() test", 0, 0); } |
| notice however that there is a lil bit of jagginess in the movement... caused by push() and pop()? also, push() and pop() are void... can i override them (e.g. make push() to push(int a) )? (this is why i wanted to know their inner workings hehe)... thanks much
|
|
|
|
_martin Guest
|
Re: 3D Question
« Reply #4 on: Mar 12th, 2003, 7:20am » |
|
hmmm... my lil example doesn't make much sense in using push() and pop() i think... it would be nicer if the parameters of translate were different for each case... add'l question: seems that a matrix stack is being used (was going over the forums and found dara's previous query and fry's lengthy but rather amazing reply series ... should have seen that earilier ... hmmm... would a matrix queue have any good
|
|
|
|
fry
|
Re: 3D Question
« Reply #5 on: Mar 12th, 2003, 4:09pm » |
|
the stuff you show is proper use of push() and pop(), and it makes sense. to see if it's push/pop that's causing the hiccups in your app, you might try just taking them out but leaving the rest of the app to run (albeit non-optimally) and see how it behaves. although that wouldn't be conclusive, it'd at least be something to try.
|
|
|
|
Martin
|
Re: 3D Question
« Reply #6 on: Mar 12th, 2003, 5:29pm » |
|
yup. push() and pop() are the culprits. ... even the rotation is faster if i remove push() and pop() ... i played around a little and replaced the box() methods with sphere() methods... terribly slooow. literally crawling... any thoughts?
|
|
|
|
|