#17069 - DiscoStew - Sun Feb 29, 2004 5:48 pm
I am so frustrated by this problem that I have. I have this function written into a C DLL for use with a VB program (speed reasons), and it does not seem to work correctly. What this function does is takes pixel arrays of my sprite and the output window, and copies the sprite into the output window with scaling and rotation when needed. The result is supposed to be much like on the GBA, with only a specific drawing area unless Double_Flags is on (which is not implemented yet), and any scaling/rotation is always centered in the middle of the drawing area. My problem with the function is that the sprite can't stay centered.
I really don't have much of a problem with equal x-y scaling and rotation, though at every 90 degrees other than 0 I'm loosing a single line of the sprite, but it's when the scaling of the x-y axises are not equal. At 0 degrees, scaling on either axis is ok, but as I rotate, the sprite does not stay centered in the area that is specified. It tends to lean out a bit, and it is very noticable when there is unequal scaling while at a constant rotation value.
Here is the code for this...
...I am using <math.h> for the sin, cos, and atan2 functions, which may be the culprit in the missing pixel line as mentioned earlier. As far as I know, I'm probably missing something that is needed to keep it centered, but I just don't know what. I've stared at this code for hours on end, and tried messing around with it to see if the result will lead up to me getting the problem fixed. Is anyone able to help me resolve this problem? thx for your help.
_________________
DS - It's all about DiscoStew
I really don't have much of a problem with equal x-y scaling and rotation, though at every 90 degrees other than 0 I'm loosing a single line of the sprite, but it's when the scaling of the x-y axises are not equal. At 0 degrees, scaling on either axis is ok, but as I rotate, the sprite does not stay centered in the area that is specified. It tends to lean out a bit, and it is very noticable when there is unequal scaling while at a constant rotation value.
Here is the code for this...
Code: |
----------------------------------------
//Initial values which are meant to come through a function's parameters int Frame_Width = 32, Frame_Height = 32, Output_Width = 240; int Sprite_ScaleX = 128, Sprite_ScaleY = 256, Sprite_RotationVal //Get the midpoint of the sprite int MidPointX = Frame_Width / 2; int MidPointY = Frame_Height / 2; //Get the actual scale values double ActualScaleX = ((double)256 / Sprite_ScaleX); double ActualScaleY = ((double)256 / Sprite_ScaleY); double GrabScaleX = MidPointX / ActualScaleX; double GrabScaleY = MidPointY / ActualScaleY; //Get the distance of the hypotenuse from the center to the upper-left corner of the sprite, and the angle plus add the rotation value of the sprite double AngleDist = sqrt((GrabScaleX * GrabScaleX) + (GrabScaleY * GrabScaleY)); double Angle = Radians(-Sprite_RotationVal) + atan2(-GrabScaleY,-GrabScaleX); //Set where on the Sprite Image to begin grabbing pixels double GrabStartX = (AngleDist * cos(Angle)) + MidPointX; double GrabStartY = (AngleDist * sin(Angle)) + MidPointY; //The X-Increments and Y-Increments associated with Scaling and Rotation double GrabPixel_X = cos(Radians(-Sprite_RotationVal)) / ActualScaleX; double GrabPixel_Y = sin(Radians(-Sprite_RotationVal)) / ActualScaleY; double NextLine_X = cos(Radians(90 - Sprite_RotationVal)) / ActualScaleX; double NextLine_Y = sin(Radians(90 - Sprite_RotationVal)) / ActualScaleY; //Set where on the output array to start placing pixels int StartX = Sprite_PositionX; int StartY = Sprite_PositionY; //Loop through the output for(int PositionY = 0; PositionY < Frame_Height; PositionY++) { //Get the location of the next starting place to grab pixels double CurrentX = GrabStartX + (NextLine_X * PositionY); double CurrentY = GrabStartY + (NextLine_Y * PositionY); for(int PositionX = 0; PositionX < Frame_Width; PositionX++) { //Make sure what is being grabbed is within the sprite image if((CurrentY >= 0) && (CurrentY < Frame_Height) && (CurrentX >= 0) && (CurrentX < Frame_Width)) OutputArray[((StartX + PositionX) + ((StartY + PositionY) * Output_Width))] = SpriteArray[(int)(CurrentX + ((int)CurrentY * Frame_Width))]; else OutputArray[((StartX + PositionX) + ((StartY + PositionY) * Output_Width))] = 0; //Add X_Increments to the locations CurrentX += GrabPixel_X; CurrentY += GrabPixel_Y; } } ------------------------------- double Radians(double Degrees) { double Deg2Rad = Degrees * (PI / 180); return (Deg2Rad); } ------------------------------- |
...I am using <math.h> for the sin, cos, and atan2 functions, which may be the culprit in the missing pixel line as mentioned earlier. As far as I know, I'm probably missing something that is needed to keep it centered, but I just don't know what. I've stared at this code for hours on end, and tried messing around with it to see if the result will lead up to me getting the problem fixed. Is anyone able to help me resolve this problem? thx for your help.
_________________
DS - It's all about DiscoStew