Hi, I am doing a data-viz + animation project and using glRotatef() to animate any number of multi-frame objects. This seems to work well with the code:
// Rotation code
glPushMatrix();
glTranslatef( -imageWidth/2 + x,-imageHeight/2 + y, 0);
glRotatef(angle,0,0,1);
glTranslatef(imageWidth/2 - x,imageHeight/2 - y,0);
(pImage+frameNum)->draw(x,y);
glPopMatrix();
…where pImage is an array of pointers ofImage objects (4-8 frames, current frame is frameNum); x and y are the (x,y) drawing position of the object; imageWidth and imageHeight are instance variables of the width + height of current frame (right now, each frame is the same width & height)
I’m not an experienced graphics programmer and am getting stuck on tracking the location of the true bounding box of the image.
Using the code here to see where the bounding box should be (and realizing that I will have to adjust the bounding box to the translated angle, but that’s a different story), the location of the bounding box is very different than the rotated image (see attached)
ofSetColor(255,0,0);
ofNoFill();
ofRect( x,y,imageWidth,imageHeight);
I’ve been monkeying around with the glTranslatef() calls, since this seems like the culprit, but each time I try to modify or alter these functions, I don’t see the animation at all. This is where I’m butting up against the limits of my graphics programming skills.
Also, if I leave the angle as zero, the bounding box draws fine.
I tried using ofImage::setAnchorPoint and ofImage::setAnchorPercent, but had the same problem where I no longer see the image drawn on the screen
Any help is appreciated and thanks,
Scott