Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: "John Emmer" Newsgroups: scea.yaroze.programming.2d_graphics Subject: Re: Algorithm to orbit? Date: 3 Aug 1997 21:53:10 GMT Organization: Justice Center Lines: 70 Message-ID: <01bca04f$83feb6a0$8bf135ce@jjustice.iquest.net> References: <01bca03a$5c9d6ee0$8bf135ce@jjustice.iquest.net> <33E4E1EE.7CE0791A@ix.netcom.com> <01bca043$beb64300$8bf135ce@jjustice.iquest.net> Reply-To: "John Emmer" NNTP-Posting-Host: and-003-11.iquest.net X-Newsreader: Microsoft Internet News 4.70.1161 John Emmer wrote in article <01bca043$beb64300$8bf135ce@jjustice.iquest.net>... > > what I need to do is change the center of rotation for the turret sprite > when the tank rotates. That is, when the turret is rotating with the tank, > I rotate it around the center of the tank, and when it rotates on its own, > I use its normal center of rotation. Doh! Here are the routines I'm using for this (there are, of course, equivalent routines for rotation to the right): // some notes: // FULLROTATION = 1470464 (360 degrees of size 4096) // the macros ending in '_OFF' store the offsets for the // center of rotation of their respective objects void RotateTankLeft(Tank * rotate) { short tempMX, tempMY; rotate->tankSprite.rotate -= ONE; if (rotate->tankSprite.rotate < 0) rotate->tankSprite.rotate += FULLROTATION; // store current center of rotation for turret tempMX = rotate->turret.turretSprite.mx; tempMY = rotate->turret.turretSprite.my; // move center of rotation of turret to center of rotation for tank rotate->turret.turretSprite.mx += (rotate->turret.turretSprite.x+TURRET_XROT_OFF - rotate->tankSprite.x+TANK_XROT_OFF); rotate->turret.turretSprite.my += (rotate->turret.turretSprite.y+TURRET_YROT_OFF - rotate->tankSprite.y+TANK_YROT_OFF); // rotate turret around tank center RotateTurretLeft(rotate); // reset turret center of rotation rotate->turret.turretSprite.mx = tempMX; rotate->turret.turretSprite.my = tempMY; } And the turret routine is simply: void RotateTurretLeft(Tank * rotate) { rotate->turret.turretSprite.rotate -= ONE; if (rotate->turret.turretSprite.rotate < 0) rotate->turret.turretSprite.rotate += FULLROTATION; } Now, I thought that what I needed to do was temporarily change the center of rotation for the turret by the current difference between its screen location and that of the center of rotation for the tank. But the turret still swims around as the tank rotates. Where did my thinking - or my programming - go wrong? -- John Emmer Video Game Enthusiast, Philosopher, Fledgling Programmer jjustice@cs.bsu.edu jjustice@iquest.net jpemmer@bsuvc.bsu.edu Vectrex; 7800, Supercharger, Lynx, Jaguar; NES, SNES, Virtual Boy; Turbo Duo & Express; SG, SGCD, 32X, Saturn; 3DO; PlayStation, Yaroze; C64, A600, A1200, P100; Arcade Centipede, Spy Hunter, Neo-Geo; BA, MA, ABD