help with rotation issues

Problems with Canvas, OpenGL, etc...

help with rotation issues

Postby ichthus » Mon Nov 07, 2011 10:07 am

hi everyone,

i'm new to this forum. i read several threads hoping for a solution to a problem i'm having, but so far nothing has helped me out.

i have 8 cylinders concentrically placed on the screen. i want to be able to rotate each cylinder independently.
this means i can't rotate the canvas because that would rotate all of them at the same time. (i think)

when i draw the cylinders the first time, they look great and are positioned exactly where i want them.

when i rotate them, they are distorted. like they are not doing a simple rotation around the z-axis but a more complex 3d rotation. bottomline: the rotations ruin the view. the images shrink, then enlarge, then start duplicating themselves. it's ugly.

how do i make a bitmap of an image rotate 6 degrees around the z-axis and retain it's shape geometry?

since i first posted, i experimented with an online example that rotated a simple image. it worked fine. i examined the values in the matrix used and they were a lot different than the values being placed in the matrix in my rotating program. so i tried to build my own matrix with values like the online example...same problem shows up. the online example was not a live wallpaper example though.

is there something about rotating images (bitmaps) on a canvas that is peculiar???


thank you (whoever helps me!!!)

here's the code i'm using:
--------------------------------------------------------------------
// declare the global array of cylinder bitmaps
private Bitmap cylinders[] = new Bitmap[8];

// i load a cylinder into a bitmap
cylinders[0] = BitmapFactory.decodeResource(getResources(), R.drawable.wheel01 );
:
cylinders[7] = BitmapFactory.decodeResource(getResources(), R.drawable.wheel07 );

--------------------------
the next few lines are in a function scheduled to repeatedly execute on time-based periods:
--------------------------

final SurfaceHolder holder = getSurfaceHolder();

Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
setTouchEventsEnabled(true);
drawCylinders(c);
drawTouchPoint(c);
} catch(Exception e) {
// do some stuff
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
}
}

----------------------------------------
the drawCylinders function
---------------------------------------
void drawCylinders(Canvas c) {
// we always save the canvas
c.save();

if ( first_time == true ) {
// do some stuff

} else {
// display the cylinders contained within the coordinates of a matching rectangle
for ( int ix=0; ix<=7; ix++ ) {
c.drawBitmap( cylinders[ix], null, (RectF)cylOrigins[ix], new Paint());
};

// rotate the inner cylinder

float degrees = (float) 6f * arbitrary_number;

int W = cylinders[0].getWidth();
int H = cylinders[0].getHeight();
int nW = cD[0]; // width of original geometric shape
int nH = cD[0]; // height
float scaleWidth = ((float) nW) / W;
float scaleHeight = ((float) nH) / H;

Matrix mSH = new Matrix();
mSH.postScale( scaleWidth, scaleHeight );
mSH.setRotate( (float)degrees, (float)240, (float)420 );

cylinders[0] = Bitmap.createBitmap(cylinders[0],0,0,W,H,mSH,true);

};

c.restore();
}
ichthus
Freshman
Freshman
 
Posts: 3
Joined: Wed Nov 02, 2011 9:07 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests