Jump to content

  • Log In with Google      Sign In   
  • Create Account

GaMEFRo

Member Since 26 Oct 2006
Offline Last Active Apr 11 2013 01:29 PM

Topics I've Started

Rotating and Scaling a Rectangle around the a point

21 March 2013 - 06:42 PM

Hi all,

 

I'm writing an iPhone application where I'd like the user to be able to push a button and be able to rotate / stretch a rectangle with regards to the red point in the picture below:

 

graphicquestion.png

 

As you can see I'd like to be able to rotate around the red dot (or half way down the y axis) and would also be able to stretch the rectangle with it still being anchored to the red point (doesn't move).

 

I should mention that in iPhone, that anchor point is initially set to the center of the object.

 

I struggle badly with transformations, but was able to figure out the rotation:

 

 

 

    self.rotateView.transform = CGAffineTransformTranslate(self.rotateView.transform,   self.rotateView.bounds.size.width / 2, 0);
    self.rotateView.transform = CGAffineTransformRotate(self.rotateView.transform, M_PI / 180);
    self.rotateView.transform = CGAffineTransformTranslate(self.rotateView.transform, self.rotateView.bounds.size.width  / 2, 0);
 

 

How to scale something is obvious, what I'm having trouble with is correctly translating the object before and after I scale it, and then doing all of this within the context of the rotation so that they both can work out when applied together. 

 

Anyone might be able to point me in the right direction on how to approach this?

 

Thanks,

 

GaMEFRo

 


Rotating an object within a box

03 October 2012 - 06:22 AM

I'm developing a game for the iPhone, and I have a situation where I have a graphic that the user can drag around the screen and there are some buttons the user can push to both rotate it and enlarge it. The graphic is located within a UIView, which is just a rectangular shape that fits tightly around it.

The thing I'm having trouble with is rotating the graphic, and then translating it so it fits within the UIView correctly. When the user pushes the button to rotate, the first thing I'm doing is calculating the correct size the UIView frame needs to be to fit the rotated object. Then I do the following:

- (CGAffineTransform) transform
{  
	CGAffineTransform transform = CGAffineTransformIdentity;
	transform = CGAffineTransformRotate(transform, (M_PI * self.graphicRotationAngle) / 180);
	transform = CGAffineTransformScale(transform, self.graphicSize.width / self.graphic.size.width, self.graphicSize.height / self.graphic.size.height);
	transform = CGAffineTransformTranslate(transform, self.graphicSize.width - self.frame.size.width, self.graphicSize.height - self.frame.size.height);

	return transform;
}


It makes sense to me that in order to translate the object back to the upper left corner (0,0), i have to subtract the new size of the frame width and height value, minus the non rotated images width and height, and that should give me the translation I need. Yet it's not working, do I have the correct order of operations?

Any help would be appreciated.

perlin noise marble equation

01 December 2006 - 12:44 AM

Hi,

does anyone know any equations for generating a nice marble texture? For instance I'm using openGL with perlin.h, I have it set up like this:

#define TexWidth 512
#define TexHeight 512
static GLubyte textureImage[TexHeight][TexWidth][4];
static GLuint texName;
ImprovedNoise noise;

double PlainNoise(int x, int y)
{
double scale = 0.05;
double n;

n = noise.noise(x * scale , y * scale, 11.5);
return n;
}

void CreateTexture()
{
//-- local variables
int i,j, k;
double n, mult;
double min = 0, max = 0;

//-- second iteration to compute texture and scale accordingly
for (i=0 ; i < TexHeight; i++)
for (j=0; j < TexWidth; j++)
{
n = PlainNoise(i,j);
n = ( n - 1) / ( 2 ); //<-- need help here
textureImage[i][j][0] = (GLubyte) (n * 255);
textureImage[i][j][1] = (GLubyte) (n * 255);
textureImage[i][j][2] = (GLubyte) (n * 255);
}
}

Any help would be appreciated thanks.

GaMEFRo

libwave - Wavefront/GL rendering library

01 December 2006 - 12:30 AM

Hi, I'm trying to use libwave, which allows you to read obj files and draw them in your program, but I keep getting a lot of errors when I try to do a build on my project in MS visual studio 2003. I know the problem is with gl.h, that is where all my errors are coming from and specifically a lot are coming from int apientry and WGDAPI. Has anyone who's used libwave had the same problems or would anyone know how to fix this? I appreciate any help you guys can give, thanks. GaMEFRo

perfacenormals calculated by gml

31 October 2006 - 10:01 PM

Hi, I am trying to make it in my program so that I display what it looks like with per face normals without per vertex normals and vice versa. I am not calculating these attributes manually, I am using the GML class by Nate Robbins and his glmFacetNormals(.obj, degrees) and glmVertexNormals(.obj) for the .obj files I am using. Whenever I take away glmFacetNormals() for a particular .obj file, I get a run time error that kills the program it says asstertion fails: facet norms so I am unable to display what it would look like with just per vertx normals. Does anyone know how to fix this? I appreciate your help, thanks FRo

PARTNERS