Search Results

Search found 1170 results on 47 pages for 'rotation'.

Page 3/47 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • XNA Vector2 Rotation Question

    - by Tom Allen
    I'm messing about with some stuff in XNA and am trying to move an object around asteroids-style in that you press left and right to rotate and up/down to go forwards and backwards in the direction you are pointing. I've got the rotation of the sprite done, but i can't get the object to move in the direction you've pointed it, it always moves up and down on the x = 0 axis. I'm guessing this is straight forward but I just can't figure it out. My "ship" class has the following properties which are note worthy here: Vector2 Position float Rotation The "ship" class has an update method is where the input is handled and so far I've got the following: public void Update(GameTime gameTime) { KeyboardState keyboard = Keyboard.GetState(); GamePadState gamePad = GamePad.GetState(PlayerIndex.One); float x = Position.X; float y = Position.Y; if (keyboard.IsKeyDown(Keys.Left)) Rotation -= 0.1f; if (keyboard.IsKeyDown(Keys.Right)) Rotation += 0.1f; if (keyboard.IsKeyDown(Keys.Up)) y -= ??; if (keyboard.IsKeyDown(Keys.Down)) y += ??; this.Position = new Vector2(x, y); } Any help would be most appreciated!

    Read the article

  • iPhone rotation woes

    - by skooter500
    I have been spending many frustrating hours trying to get rotations working on the iPhone version of Tunepal. Firstly, I have a tab bar controller, with a navigation controller controlling each of the views. I actually only want one of my views to be able to rotate and that is the TuneDisplay. I have a subclassed the UITabBarController and overridden theshouldAutorotateToInterfaceOrientation: (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { if (self.selectedViewController != nil) { return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; } else { return (interfaceOrientation == UIInterfaceOrientationPortrait); } } In each of the view controllers for each of the tabs I have overridden the method and returned YES for each orientation I want to support. All well and good and everything works as it should. If I try and do a rotation on a tab that doesn’t support the rotation, nothing happens. The problem occurs if I move from a tab thats rotated to a tab that isnt supposed to support that rotation. The new tab is displayed rotated too! Screenshots for all this are included here: http://tunepal.wordpress.com/2010/04/20/rotation-woes/ Is there any way I can make it rotate back to portrait on tapping the tab? I have tried the unsupported setOrientation trick, but firstly it doesnt work correctly and secondly I received a warning from Apple for including it in my last build. If (as I suspect) there is no way to limit this behavior: How do I make the microphone image scale when I rotate the device? How do I make the buttons and the progress bar expand to fit the witdh of the toolbar? Also, one of the tabs that rotates ok has a table, with a search bar. The first time I rotate to the right or to the left, I get a black bar to the right of the search bar. If I subsequently rotate back and rotate again, the bar disappears! I have enabled the struts and springs things on the search bar in the interface builder and it looks like it should behave correctly. Any ideas about how to fix this? Ideas, feedback much appreciated Bryan

    Read the article

  • get rotation direction of UIView on touchesMoved

    - by mlecho
    this may sound funny, but i spent hours trying to recreate a knob with a realistic rotation using UIView and some trig. I achieved the goal, but now i can not figure out how to know if the knob is rotating left or right. The most pertinent part of the math is here: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint pt = [touch locationInView:self]; float dx = pt.x - iv.center.x; float dy = pt.y - iv.center.y; float ang = atan2(dy,dx); //do the rotation if (deltaAngle == 0.0) { deltaAngle = ang; initialTransform = iv.transform; }else { float angleDif = deltaAngle - ang; CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif); iv.transform = newTrans; currentValue = [self goodDegrees:radiansToDegrees(angleDif)]; } } ideally, i could leverage a numeric value to tell me if the rotation is positive or negative.

    Read the article

  • Rotation of a single UIViewController in a UITabBarController

    - by burki
    Hi! I have a UITabBarController with four UINavigationControllers. Well, I want to enable the rotation just for one of the four UIViewControllers. According to Apple's doc you shouldn't subclass UITabBarController, so I don't wanna do that. All UIViewControllers should support the same orientations that it works, but that's not what I want. How can the single UIViewController, which should support the rotation, detect that the device has changed its orientation? Because unless all the UIViewControllers added to the UITabBarControllers support the same orientation, the methods of the UIViewController for managing the rotation aren't called. I've been searching now for a while, but I haven't already found a pleasant answer. I guess a lot of developers wonder how to manage that. I already thank you for your answer.

    Read the article

  • OpenCV rotation solution?

    - by sundowatch
    I am using those codes for rotation transforming an image, but it doesn't work. Waht is the problem? IplImage *src = cvLoadImage("image.jpg",1), *dst = cvCloneImage(src); CvMat *rotation_mat = cvCreateMat(2,3,CV_32FC1); CvPoint2D32f center = cvPoint2D32f(src->width/2 ,src->height/2); cvZero(dst); double angle = -50.0, scale = 0.6; cv2DRotationMatrix(center, angle, scale, rotation_mat); cvWarpAffine(src, dst, rotation_mat); cvNamedWindow("rotation"); cvShowImage("rotation",dst); cvWaitKey(0); cvReleaseMat(&rotation_mat); cvReleaseImage(&src); cvReleaseImage(&dst); cvDestroyAllWindows(); return 0;

    Read the article

  • Rotation of ViewController in TabbarController

    - by hanno
    I have a custom UIViewController in a UITabbarController and want to respond to rotation events. When a rotation occurs, the tabbarcontroller and the viewcontroller get rotated. However, the view in the viewcontroller doesn't get redrawn properly: the layout doesn't autoresize and it is black on parts of the screen. The strange thing is that it works when I go to another tab and the back again to my original viewcontroller. What could possibly be wrong? I checked that didRotateFromInterfaceOrientation:fromInterfaceOrientation is being called. However, the view.frame.size values are still the old ones from before the rotation. That's probably not correct.

    Read the article

  • Direct3D Rotation Matrix from Vector and vice-versa

    - by Beta Carotin
    I need to compute a rotation matrix from a direction vector, and a direction vector from a rotation matrix. The up direction should correspond to the z-axis, forward is y and right is x; D3DXMATRIX m; // the rotation matrix D3DXVECTOR3 v; // this is the direction vector wich is given D3DXVECTOR3 r; // resulting direction vector float len = D3DXVec3Length(&v); // length of the initial direction vector // compute matrix D3DXMatrixLookAtLH(&m, &v, &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,0,1)); // use the matrix on a vector { 0, len, 0 } D3DXVec3TransformCoord(&r, &D3DXVECTOR3(0,len,0), &m); Now, the vector r should be equal to v, but it isnt. What exactly do I have to do to get the results I need?

    Read the article

  • Difficulties with rotation of a sprite

    - by Johnny
    I want to program a dolphin that jumps and rotates like a real dolphin. Jumping is not the problem, but I don't know how to make the rotation. At the moment, my dolphin rotates a little weird. But I want that it rotates like a real dolphin does. How can I improve the rotation? public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D image, water; float Gravity = 5.0F; float Acceleration = 20.0F; Vector2 Position = new Vector2(1200,720); Vector2 Velocity; float rotation = 0; SpriteEffects flip; Vector2 Speed = new Vector2(0, 0); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); image = Content.Load<Texture2D>("cartoondolphin"); water = Content.Load<Texture2D>("background"); flip = SpriteEffects.None; } protected override void Update(GameTime gameTime) { float VelocityX = 0f; float VelocityY = 0f; float time = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState kbState = Keyboard.GetState(); if(kbState.IsKeyDown(Keys.Left)) { rotation = 0; flip = SpriteEffects.None; VelocityX += -5f; } if(kbState.IsKeyDown(Keys.Right)) { rotation = 0; flip = SpriteEffects.FlipHorizontally; VelocityX += 5f; } // jump if the dolphin is under water if(Position.Y >= 670) { if (kbState.IsKeyDown(Keys.A)) { if (flip == SpriteEffects.None) { rotation += 0.01f; VelocityY += 40f; } else { rotation -= 0.01f; VelocityY += 40f; } } } else { if (flip == SpriteEffects.None) { rotation -= 0.01f; VelocityY += -10f; } else { rotation += 0.01f; VelocityY += -10f; } } float deltaY = 0; float deltaX = 0; deltaY = Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; deltaX += VelocityX * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; deltaY += -VelocityY * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; Speed = new Vector2(Speed.X + deltaX, Speed.Y + deltaY); Position += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity.X = 0; if (Position.Y + image.Height/2 > graphics.PreferredBackBufferHeight) Position.Y = graphics.PreferredBackBufferHeight - image.Height/2; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(water, new Rectangle(0, graphics.PreferredBackBufferHeight -100, graphics.PreferredBackBufferWidth, 100), Color.White); spriteBatch.Draw(image, Position, null, Color.White, rotation, new Vector2(image.Width / 2, image.Height / 2), 1, flip, 1); spriteBatch.End(); base.Draw(gameTime); } }

    Read the article

  • Implementing touch-based rotation in cocoa touch

    - by ewoo
    I am wondering what is the best way to implement rotation-based dragging movements in my iPhone application. I have a UIView that I wish to rotate around its centre, when the users finger is touch the view and they move it. Think of it like a dial that needs to be adjusted with the finger. The basic question comes down to: 1) Should I remember the initial angle and transform when touchesBegan is called, and then every time touchesMoved is called apply a new transform to the view based on the current position of the finger, e.g., something like: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; //current position of touch if (([touch view] == self) && [Utility getDistance:currentPoint toPoint:self.middle] <= ROTATE_RADIUS //middle is centre of view && [Utility getDistance:currentPoint toPoint:self.middle] >= MOVE_RADIUS) { //will be rotation gesture //remember state of view at beginning of touch CGPoint top = CGPointMake(self.middle.x, 0); self.initialTouch = currentPoint; self.initialAngle = angleBetweenLines(self.middle, top, self.middle, currentPoint); self.initialTransform = self.transform; } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; //current position of touch if (([touch view] == self) && [Utility getDistance:currentPoint toPoint:self.middle] <= ROTATE_RADIUS && [Utility getDistance:currentPoint toPoint:self.middle] >= MOVE_RADIUS) { //a rotation gesture //rotate tile float newAngle = angleBetweenLines(self.middle, CGPointMake(self.middle.x, 0), self.middle, currentPoint); //touch angle float angleDif = newAngle - self.initialAngle; //work out dif between angle at beginning of touch and now. CGAffineTransform newTransform = CGAffineTransformRotate(self.initialTransform, angleDif); //create new transform self.transform = newTransform; //apply transform. } OR 2) Should I simply remember the last known position/angle, and rotate the view based on the difference in angle between that and now, e.g.,: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; //current position of touch if (([touch view] == self) && [Utility getDistance:currentPoint toPoint:self.middle] <= ROTATE_RADIUS && [Utility getDistance:currentPoint toPoint:self.middle] >= MOVE_RADIUS) { //will be rotation gesture //remember state of view at beginning of touch CGPoint top = CGPointMake(self.middle.x, 0); self.lastTouch = currentPoint; self.lastAngle = angleBetweenLines(self.middle, top, self.middle, currentPoint); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; //current position of touch if (([touch view] == self) && [Utility getDistance:currentPoint toPoint:middle] <= ROTATE_RADIUS && [Utility getDistance:currentPoint toPoint:middle] >= MOVE_RADIUS) { //a rotation gesture //rotate tile float newAngle = angleBetweenLines(self.middle, CGPointMake(self.middle.x, 0), self.middle, currentPoint); //touch angle float angleDif = newAngle - self.lastAngle; //work out dif between angle at beginning of touch and now. CGAffineTransform newTransform = CGAffineTransformRotate(self.transform, angleDif); //create new transform self.transform = newTransform; //apply transform. self.lastTouch = currentPoint; self.lastAngle = newAngle; } The second option makes more sense to me, but it is not giving very pleasing results (jaggy updates and non-smooth rotations). Which way is best (if any), in terms of performance? Cheers!

    Read the article

  • Calculating a child object's Position, Rotation and Scale values?

    - by Sergio Plascencia
    I am making my own game editor, but have encountered the following problem: I have two objects, A and B. A's initial values: Position: (3,3,3), Rotation: (45,10,0), Scale(1,2,2.5) B's initial values: Position: (1,1,1), Rotation: (10,34,18), Scale(1.5,2,1) If I now make B a child of A, I need to re-calculate the B's Position, Rotation and Scale relative to A such that it maintains its current position, rotation and scale in world coordinates. So B's position would now be (-2, -2, -2) since now A is its center and (-2, -2, -2) will keep B in the same position. I think I got the Position and scale figured out, but not rotation. So I opened Unity and ran the same example and I noticed that when making a child object, the child object did not move at all. but had its Position, Rotation and Scale values changed relative to the parent. For example: Unity (Parent Object "A"): Position: (0,0,0) Rotation: (45,10,0) Scale: (1,1,1) Unity (Child Object "B"): Position: (0,0,0) Rotation: (0,0,0) Scale: (1,1,1) When B becomes a child of A, it's rotation values become: X: -44.13605 Y: -14.00195 Z: 9.851074 If I plug the same rotation values into the B object in my editor, the object does not move at all. How did Unity arrive at those rotation values for the child? What are the calculations? If you can put all the equations for the Position, Rotation or Scale then I can double check I am doing it correctly but the Rotation is what I really need.

    Read the article

  • Tetris Piece Rotation Algorithm

    - by coppercoder
    What are the best algorithms (and explanations) for representing and rotating the pieces of a tetris game? I always find the piece rotation and representation schemes confusing. Most tetris games seem to use a naive "remake the array of blocks" at each rotation: http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=tetris However, some use pre-built encoded numbers and bit shifting to represent each piece: http://www.codeplex.com/wintris Is there a method to do this using mathematics (not sure that would work on a cell based board)?

    Read the article

  • Axis Rotation Question using sio2 game engine

    - by Leo
    By using left hand rule, I rotate one object left and right using x axis, and rotate up/down using y axis. After first object is rotated to the right, the up/down rotation should be using z axis. However, when I try to rotate using z axis, after the first rotation, it has the same effect when I rotate using y axis. Anyone has any ideas? Thanks

    Read the article

  • Axis Rotation Question

    - by Leo
    By using left hand rule, I rotate one object left and right using y axis, and rotate up/down using x axis. After first object is rotated to the right, the up/down rotation should be using z axis. However, when I try to rotate using z axis, after the first rotation, it has the same effect when I rotate using y axis. Anyone has any ideas? Thanks

    Read the article

  • Euler rotation of direction vector

    - by Tom Savage
    I have defined an object in 3D space with position, rotation and scale values (all defined as 3D vectors). It also has upwards and forwards direction vectors. When I rotate the object, I need these direction vectors to rotate with it. Assuming my up vector is (0, 1, 0) and my forwards vector is (0, 0, 1) at zero rotation, how might I achieve this?

    Read the article

  • How can I implement smooth rotation from one direction to another?

    - by user1759052
    I'm having a problem with animating rotations with 1Matrix.CreateRotationY() with my basic 3D game. Based on where you click the mouse, I want the 3D object to rotate to that direction and then move. I am using this to determine the target direction: float rot = (float)(Math.Atan2(X, Z)); It gives me the correct value, but I am not sure how to handle the rotation animation from current direction to new direction. I've tried a few things, but to no avail. Do you guys know of any good ways of solving this issue?

    Read the article

  • Raphael SVG VML Implement Multi Pivot Points for Rotation

    - by Cody N
    Over the last two days I've effectively figured out how NOT to rotate Raphael Elements. Basically I am trying to implement a multiple pivot points on element to rotate it by mouse. When a user enters rotation mode 5 pivots are created. One for each corner of the bounding box and one in the center of the box. When the mouse is down and moving it is simple enough to rotate around the pivot using Raphael elements.rotate(degrees, x, y) and calculating the degrees based on the mouse positions and atan2 to the pivot point. The problem arises after I've rotated the element, bbox, and the other pivots. There x,y position in the same only there viewport is different. In an SVG enabled browser I can create new pivot points based on matrixTransformation and getCTM. However after creating the first set of new pivots, every rotation after the pivots get further away from the transformed bbox due to rounding errors. The above is not even an option in IE since in is VML based and cannot account for transformation. Is the only effective way to implement element rotation is by using rotate absolute or rotating around the center of the bounding box? Is it possible at all the create multi pivot points for an object and update them after mouseup to remain in the corners and center of the transformed bbox?

    Read the article

  • TableLayout formatting loss after device rotation

    - by roundhill
    I'm seeing a strange issue with a TableLayout after the device is rotated from either orientation. If you load the view in either portrait or landscape mode, the table loads fine. But once you rotate the device, the columns collapse to just fit their width. I would expect that after rotation, the columns would still stretch to fit the width of the screen. Any ideas on what can be done to resolve this? Screenies and layout code below. Before Rotation: After Rotation: Table Layout: <TableLayout android:id="@+id/dataTable" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:layout_below="@id/chart" android:stretchColumns="*" android:shrinkColumns="*" android:padding="6dip" > </TableLayout> Table Row: <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/col1" android:layout_marginRight="2dip" android:textColorLink="#FF21759b" android:text="Column 1" android:padding="4dip" android:textColor="#FF464646"/> <TextView android:id="@+id/col2" android:text="Column 2" android:textColor="#FF464646" android:padding="4dip"/> </TableRow> Thanks!

    Read the article

  • How to convert pitch and yaw to x, y, z rotations?

    - by Aaron Anodide
    I'm a beginner using XNA to try and make a 3D Asteroids game. I'm really close to having my space ship drive around as if it had thrusters for pitch and yaw. The problem is I can't quite figure out how to translate the rotations, for instance, when I pitch forward 45 degrees and then start to turn - in this case there should be rotation being applied to all three directions to get the "diagonal yaw" - right? I thought I had it right with the calculations below, but they cause a partly pitched forward ship to wobble instead of turn.... :( So my quesiton is: how do you calculate the X, Y, and Z rotations for an object in terms of pitch and yaw? Here's current (almost working) calculations for the Rotation acceleration: float accel = .75f; // Thrust +Y / Forward if (currentKeyboardState.IsKeyDown(Keys.I)) { this.ship.AccelerationY += (float)Math.Cos(this.ship.RotationZ) * accel; this.ship.AccelerationX += (float)Math.Sin(this.ship.RotationZ) * -accel; this.ship.AccelerationZ += (float)Math.Sin(this.ship.RotationX) * accel; } // Rotation +Z / Yaw if (currentKeyboardState.IsKeyDown(Keys.J)) { this.ship.RotationAccelerationZ += (float)Math.Cos(this.ship.RotationX) * accel; this.ship.RotationAccelerationY += (float)Math.Sin(this.ship.RotationX) * accel; this.ship.RotationAccelerationX += (float)Math.Sin(this.ship.RotationY) * accel; } // Rotation -Z / Yaw if (currentKeyboardState.IsKeyDown(Keys.K)) { this.ship.RotationAccelerationZ += (float)Math.Cos(this.ship.RotationX) * -accel; this.ship.RotationAccelerationY += (float)Math.Sin(this.ship.RotationX) * -accel; this.ship.RotationAccelerationX += (float)Math.Sin(this.ship.RotationY) * -accel; } // Rotation +X / Pitch if (currentKeyboardState.IsKeyDown(Keys.F)) { this.ship.RotationAccelerationX += accel; } // Rotation -X / Pitch if (currentKeyboardState.IsKeyDown(Keys.D)) { this.ship.RotationAccelerationX -= accel; } I'm combining that with drawing code that does a rotation to the model: public void Draw(Matrix world, Matrix view, Matrix projection, TimeSpan elsapsedTime) { float seconds = (float)elsapsedTime.TotalSeconds; // update velocity based on acceleration this.VelocityX += this.AccelerationX * seconds; this.VelocityY += this.AccelerationY * seconds; this.VelocityZ += this.AccelerationZ * seconds; // update position based on velocity this.PositionX += this.VelocityX * seconds; this.PositionY += this.VelocityY * seconds; this.PositionZ += this.VelocityZ * seconds; // update rotational velocity based on rotational acceleration this.RotationVelocityX += this.RotationAccelerationX * seconds; this.RotationVelocityY += this.RotationAccelerationY * seconds; this.RotationVelocityZ += this.RotationAccelerationZ * seconds; // update rotation based on rotational velocity this.RotationX += this.RotationVelocityX * seconds; this.RotationY += this.RotationVelocityY * seconds; this.RotationZ += this.RotationVelocityZ * seconds; Matrix translation = Matrix.CreateTranslation(PositionX, PositionY, PositionZ); Matrix rotation = Matrix.CreateRotationX(RotationX) * Matrix.CreateRotationY(RotationY) * Matrix.CreateRotationZ(RotationZ); model.Root.Transform = rotation * translation * world; model.CopyAbsoluteBoneTransformsTo(boneTransforms); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = boneTransforms[mesh.ParentBone.Index]; effect.View = view; effect.Projection = projection; effect.EnableDefaultLighting(); } mesh.Draw(); } }

    Read the article

  • How do I apply 2 rotations about different points to a single primitive using OpenGL

    - by Fenoec
    I'm working on a 2D top-down shooter game that has a rotation feature like Realm Of The Mad God such that if you press e the camera rotates around the character in a clockwise direction and q rotates the camera around the character in a counterclockwise direction. I have this working with my floors and walls by translating to the character, doing the screen rotation, and drawing everything with the character as the origin. The problem arises when I shoot projectiles which need to both rotate around the character and rotate around themselves (shooting uses the mouse cursor so I can shoot at any angle). For example, if the screen is not rotated and I'm shooting rectangular projectiles, I want them to face in the direction I'm shooting (rotation around themselves). However if I only do this rotation, when I then rotate the screen the projectiles will always shoot at the same position because my cursor position does not change. Therefore I need to also either rotate the projectiles around the character or rotate the mouse cursor position to get the correct position (which would then totally screw up all of the collision detection). Likewise if I only do the screen rotation on projectiles, the rectangles will always be facing the same way and they would only look correct if I were shooting straight up or straight down. So my question is, how can I perform 2 rotations on a primitive around 2 different points? The only way I can think of is to translate to the character and do the screen rotation, then somehow calculate the translation required to move back to the middle of the projectile (seeing as how my axes are now rotated) and do its rotation. Or am I thinking about this in the wrong way and there is a different solution to accomplishing this effect?

    Read the article

  • Difficulties with rotation of a sprite

    - by Andy
    I want to program a dolphin that jumps and rotates like a real dolphin. Jumping is not the problem, but I don't know how to make the rotation. My dolphin always rests in the same angle while it jumps. But I want that it changes the rotation during the jump, like a real dolphin does. How can I improve the rotation? public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D image, water; float Gravity = 5.0F; float Acceleration = 20.0F; Vector2 Position = new Vector2(1200,720); Vector2 Velocity; float rotation = 0; SpriteEffects flip; Vector2 Speed = new Vector2(0, 0); public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); image = Content.Load<Texture2D>("cartoondolphin"); water = Content.Load<Texture2D>("background"); flip = SpriteEffects.None; } protected override void Update(GameTime gameTime) { float VelocityX = 0f; float VelocityY = 0f; float time = (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState kbState = Keyboard.GetState(); if(kbState.IsKeyDown(Keys.Left)) { rotation = 0; flip = SpriteEffects.None; VelocityX += -5f; } if(kbState.IsKeyDown(Keys.Right)) { rotation = 0; flip = SpriteEffects.FlipHorizontally; VelocityX += 5f; } // jump if the dolphin is under water if(Position.Y >= 670) { if (kbState.IsKeyDown(Keys.A)) { if (flip == SpriteEffects.None) { rotation = 45; VelocityY += 40f; } else { rotation = -45; VelocityY += 40f; } } } else { VelocityY += -10f; } float deltaY = 0; float deltaX = 0; deltaY = Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds; deltaX += VelocityX * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; deltaY += -VelocityY * (float)gameTime.ElapsedGameTime.TotalSeconds * Acceleration; Speed = new Vector2(Speed.X + deltaX, Speed.Y + deltaY); Position += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity.X = 0; if (Position.Y + image.Height/2 > graphics.PreferredBackBufferHeight) Position.Y = graphics.PreferredBackBufferHeight - image.Height/2; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(water, new Rectangle(0, graphics.PreferredBackBufferHeight -100, graphics.PreferredBackBufferWidth, 100), Color.White); spriteBatch.Draw(image, Position, null, Color.White, MathHelper.ToRadians(rotation), new Vector2(image.Width / 2, image.Height / 2), 1, flip, 1); spriteBatch.End(); base.Draw(gameTime); } }

    Read the article

  • how can i get rotation vector from matrix4x4 in xna?

    - by mr.Smyle
    i want to get rotation vector from matrix to realize some parent-children system for models. Matrix bonePos = link.Bone.Transform * World; Matrix m = Matrix.CreateTranslation(link.Offset) * Matrix.CreateScale(link.gameObj.Scale.X, link.gameObj.Scale.Y, link.gameObj.Scale.Z) * Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(link.gameObj.Rotation.Y), MathHelper.ToRadians(link.gameObj.Rotation.X), MathHelper.ToRadians(link.gameObj.Rotation.Z)) //need rotation vector from bone matrix here (now it's global model rotation vector) * Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(Rotation.Y), MathHelper.ToRadians(Rotation.X), MathHelper.ToRadians(Rotation.Z)) * Matrix.CreateTranslation(bonePos.Translation); link.gameObj.World = m; where : link - struct with children model settings, like position, rotation etc. And link.Bone - Parent Bone

    Read the article

  • View controllers inside tab bar controller not auto-resizing on rotation

    - by Padawan
    (Correction: the view controllers are not auto-resizing instead of not auto-rotating.) In an iPad app, I have five regular view controllers (not navigation controllers or anything like that) inside a tab bar controller. The tab bar controller is just a plain UITabBarController declared in the app delegate. All the view controllers return YES in the shouldAutorotateToInterfaceOrientation method. On both the simulator and device, on rotation, the tab bar and the current view controller rotate but the currently selected view controller (call it A) does not resize properly. It keeps its portrait width and height (but it is rotated). If I switch to another view controller B and then back to A (without rotating the device again), A appears correctly resized. This happens with any of the five view controllers Why doesn't the currently selected view controller resize immediately on rotation and how do I fix it? Thanks.

    Read the article

  • tetris rotation

    - by Samuel
    Hey, For university we're supposed to write a game (the language is modula2 little chance you know it). Each tetromino is defined through a central piece and 3 relative pieces, Now when it comes to rotation i just rotate the relative blocks (linear algebra). What i am asking myself is how to handle the rotations a user does when the piece has already "landed" because than the user has a little time left to move his pieve quickly into the desired position but in tetris versions all over the web you can "rotate over" other pieces, but i dont seem to get it with my rotation. Over what piece do i need to rotate? are there guidelines? Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >