[Scummvm-cvs-logs] SF.net SVN: scummvm:[42680] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Fri Jul 24 03:54:15 CEST 2009


Revision: 42680
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42680&view=rev
Author:   dkasak13
Date:     2009-07-24 01:54:13 +0000 (Fri, 24 Jul 2009)

Log Message:
-----------
Added support for per-animation scaling (via scaling factors). I have decided to go for a mixed approach (where Animation has a global scaling factor for the whole animation which is separate from Drawable's scaled width and height) so the animation can be scaled more naturally when the scale often changes (like with perspective when the dragon is walking). Previously, one had to alter the sizes of each frame of the dragon's animation whenever the dragon moved which was unclean.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/animation.h
    scummvm/branches/gsoc2009-draci/engines/draci/game.cpp

Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp	2009-07-23 19:50:13 UTC (rev 42679)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.cpp	2009-07-24 01:54:13 UTC (rev 42680)
@@ -33,6 +33,8 @@
 	_z = 0;
 	_relX = 0;
 	_relY = 0;
+	_scaleX = 1.0;
+	_scaleY = 1.0;
 	_playing = false;
 	_looping = false;
 	_tick = _vm->_system->getMillis();
@@ -69,6 +71,10 @@
 
 	// Translate rectangle to compensate for relative coordinates	
 	frameRect.translate(_relX, _relY);
+	
+	// Take animation scaling into account
+	frameRect.setWidth(frameRect.width() * _scaleX);
+	frameRect.setHeight(frameRect.height() * _scaleY);
 
 	// Mark the rectangle dirty on the surface
 	surface->markDirtyRect(frameRect);
@@ -141,12 +147,23 @@
 		frame->setX(newX);
 		frame->setY(newY);
 
+		// Save scaled width and height
+		int scaledWidth = frame->getScaledWidth();
+		int scaledHeight = frame->getScaledHeight();
+
+		// Take into account per-animation scaling and adjust the current frames dimensions	
+		if (_scaleX != 1.0 || _scaleY != 1.0)
+			frame->setScaled(scaledWidth * _scaleX, scaledHeight * _scaleY);
+
 		// Draw frame
 		frame->drawScaled(surface, false);
 
 		// Revert back to old coordinates
 		frame->setX(x);
 		frame->setY(y);
+
+		// Revert back to old dimensions
+		frame->setScaled(scaledWidth, scaledHeight);
 	}
 }
 
@@ -183,6 +200,13 @@
 	_playing = playing;
 }
 
+void Animation::setScaleFactors(double scaleX, double scaleY) {
+	markDirtyRect(_vm->_screen->getSurface());	
+	
+	_scaleX = scaleX;
+	_scaleY = scaleY;
+}
+
 void Animation::addFrame(Drawable *frame) {
 	_frames.push_back(frame);	
 }

Modified: scummvm/branches/gsoc2009-draci/engines/draci/animation.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/animation.h	2009-07-23 19:50:13 UTC (rev 42679)
+++ scummvm/branches/gsoc2009-draci/engines/draci/animation.h	2009-07-24 01:54:13 UTC (rev 42680)
@@ -66,6 +66,8 @@
 	int getRelativeX();
 	int getRelativeY();
 
+	void setScaleFactors(double scaleX, double scaleY);
+
 	void markDirtyRect(Surface *surface);
 
 private:
@@ -79,6 +81,9 @@
 	int _relX;
 	int _relY;
 
+	double _scaleX;
+	double _scaleY;
+
 	uint _tick;
 	bool _playing;
 	bool _looping;

Modified: scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/game.cpp	2009-07-23 19:50:13 UTC (rev 42679)
+++ scummvm/branches/gsoc2009-draci/engines/draci/game.cpp	2009-07-24 01:54:13 UTC (rev 42680)
@@ -193,22 +193,12 @@
 			// We naturally want the dragon to position its feet to the location of the
 			// click but sprites are drawn from their top-left corner so we subtract
 			// the current height of the dragon's sprite
-			// We also need to do this before we change the frames' scaled dimensions
-			// so setRelative() can correctly delete the old frame
 			y -= (int)(scaleY * height);
 			anim->setRelative(x, y);
 
-			// Set the scaled dimensions for all frames
-			for (uint i = 0; i < anim->getFramesNum(); ++i) {
-				frame = anim->getFrame(i);				
+			// Set the per-animation scaling factor
+			anim->setScaleFactors(scaleX, scaleY);
 
-				// Calculate scaled dimensions
-				uint scaledWidth = (uint)(scaleX * frame->getWidth());
-				uint scaledHeight = (uint)(scaleY * frame->getHeight());
-
-				frame->setScaled(scaledWidth, scaledHeight);
-			}
-
 			// Play the animation
 			_vm->_anims->play(animID);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list