From 1b05afc7bed0e2ac55f61a6b6bfae65856aeee75 Mon Sep 17 00:00:00 2001 From: chsieh Date: Thu, 23 Dec 2010 11:10:02 -0800 Subject: [PATCH] Interim code. Integrating cocos2d. --- Classes/Foundation/Common/GlobalDefines.h | 4 +- .../GraphicsServices/Geometry/BasicPrimitives.h | 27 + .../GraphicsServices/Geometry/BasicPrimitives.mm | 26 + .../Foundation/GraphicsServices/OpenGLServices.h | 4 +- .../Foundation/GraphicsServices/OpenGLServices.mm | 13 +- Classes/Foundation/Math/MathTypes.h | 162 ++-- Classes/Foundation/Math/Matrix.h | 614 +++++----- Classes/Foundation/Math/Quaternion.h | 22 +- Classes/Foundation/Math/Vector.h | 592 +++++----- Classes/cocos2d/CCAction.h | 188 +++ Classes/cocos2d/CCAction.m | 360 ++++++ Classes/cocos2d/CCActionCamera.h | 72 ++ Classes/cocos2d/CCActionCamera.m | 146 +++ Classes/cocos2d/CCActionEase.h | 159 +++ Classes/cocos2d/CCActionEase.m | 534 +++++++++ Classes/cocos2d/CCActionGrid.h | 165 +++ Classes/cocos2d/CCActionGrid.m | 386 +++++++ Classes/cocos2d/CCActionGrid3D.h | 208 ++++ Classes/cocos2d/CCActionGrid3D.m | 659 +++++++++++ Classes/cocos2d/CCActionInstant.h | 197 ++++ Classes/cocos2d/CCActionInstant.m | 472 ++++++++ Classes/cocos2d/CCActionInterval.h | 384 +++++++ Classes/cocos2d/CCActionInterval.m | 1213 ++++++++++++++++++++ Classes/cocos2d/CCActionManager.h | 118 ++ Classes/cocos2d/CCActionManager.m | 356 ++++++ Classes/cocos2d/CCActionPageTurn3D.h | 42 + Classes/cocos2d/CCActionPageTurn3D.m | 86 ++ Classes/cocos2d/CCActionProgressTimer.h | 59 + Classes/cocos2d/CCActionProgressTimer.m | 103 ++ Classes/cocos2d/CCActionTiledGrid.h | 211 ++++ Classes/cocos2d/CCActionTiledGrid.m | 768 +++++++++++++ Classes/cocos2d/CCActionTween.h | 62 + Classes/cocos2d/CCActionTween.m | 72 ++ Classes/cocos2d/CCAnimation.h | 132 +++ Classes/cocos2d/CCAnimation.m | 152 +++ Classes/cocos2d/CCAnimationCache.h | 63 + Classes/cocos2d/CCAnimationCache.m | 100 ++ Classes/cocos2d/CCAtlasNode.h | 86 ++ Classes/cocos2d/CCAtlasNode.m | 205 ++++ Classes/cocos2d/CCBlockSupport.h | 51 + Classes/cocos2d/CCBlockSupport.m | 46 + Classes/cocos2d/CCCamera.h | 94 ++ Classes/cocos2d/CCCamera.m | 130 +++ Classes/cocos2d/CCCompatibility.h | 224 ++++ Classes/cocos2d/CCCompatibility.m | 596 ++++++++++ Classes/cocos2d/CCConfiguration.h | 110 ++ Classes/cocos2d/CCConfiguration.m | 192 +++ Classes/cocos2d/CCDirector.h | 304 +++++ Classes/cocos2d/CCDirector.m | 557 +++++++++ Classes/cocos2d/CCDrawingPrimitives.h | 91 ++ Classes/cocos2d/CCDrawingPrimitives.m | 271 +++++ Classes/cocos2d/CCGrabber.h | 43 + Classes/cocos2d/CCGrabber.m | 95 ++ Classes/cocos2d/CCGrid.h | 121 ++ Classes/cocos2d/CCGrid.m | 571 +++++++++ Classes/cocos2d/CCLabelAtlas.h | 61 + Classes/cocos2d/CCLabelAtlas.m | 189 +++ Classes/cocos2d/CCLabelBMFont.h | 189 +++ Classes/cocos2d/CCLabelBMFont.m | 669 +++++++++++ Classes/cocos2d/CCLabelTTF.h | 62 + Classes/cocos2d/CCLabelTTF.m | 125 ++ Classes/cocos2d/CCLayer.h | 261 +++++ Classes/cocos2d/CCLayer.m | 562 +++++++++ Classes/cocos2d/CCMenu.h | 89 ++ Classes/cocos2d/CCMenu.m | 516 +++++++++ Classes/cocos2d/CCMenuItem.h | 341 ++++++ Classes/cocos2d/CCMenuItem.m | 752 ++++++++++++ Classes/cocos2d/CCMotionStreak.h | 67 ++ Classes/cocos2d/CCMotionStreak.m | 104 ++ Classes/cocos2d/CCNode.h | 510 ++++++++ Classes/cocos2d/CCNode.m | 883 ++++++++++++++ Classes/cocos2d/CCParallaxNode.h | 49 + Classes/cocos2d/CCParallaxNode.m | 160 +++ Classes/cocos2d/CCParticleExamples.h | 110 ++ Classes/cocos2d/CCParticleExamples.m | 925 +++++++++++++++ Classes/cocos2d/CCParticleSystem.h | 444 +++++++ Classes/cocos2d/CCParticleSystem.m | 795 +++++++++++++ Classes/cocos2d/CCParticleSystemPoint.h | 64 + Classes/cocos2d/CCParticleSystemPoint.m | 207 ++++ Classes/cocos2d/CCParticleSystemQuad.h | 74 ++ Classes/cocos2d/CCParticleSystemQuad.m | 314 +++++ Classes/cocos2d/CCProgressTimer.h | 83 ++ Classes/cocos2d/CCProgressTimer.m | 494 ++++++++ Classes/cocos2d/CCProtocols.h | 124 ++ Classes/cocos2d/CCRenderTexture.h | 108 ++ Classes/cocos2d/CCRenderTexture.m | 308 +++++ Classes/cocos2d/CCRibbon.h | 117 ++ Classes/cocos2d/CCRibbon.m | 381 ++++++ Classes/cocos2d/CCScene.h | 42 + Classes/cocos2d/CCScene.m | 44 + Classes/cocos2d/CCScheduler.h | 212 ++++ Classes/cocos2d/CCScheduler.m | 597 ++++++++++ Classes/cocos2d/CCSprite.h | 367 ++++++ Classes/cocos2d/CCSprite.m | 1004 ++++++++++++++++ Classes/cocos2d/CCSpriteBatchNode.h | 143 +++ Classes/cocos2d/CCSpriteBatchNode.m | 499 ++++++++ Classes/cocos2d/CCSpriteFrame.h | 89 ++ Classes/cocos2d/CCSpriteFrame.m | 87 ++ Classes/cocos2d/CCSpriteFrameCache.h | 133 +++ Classes/cocos2d/CCSpriteFrameCache.m | 344 ++++++ Classes/cocos2d/CCSpriteSheet.h | 61 + Classes/cocos2d/CCSpriteSheet.m | 37 + Classes/cocos2d/CCTMXLayer.h | 153 +++ Classes/cocos2d/CCTMXLayer.m | 668 +++++++++++ Classes/cocos2d/CCTMXObjectGroup.h | 65 ++ Classes/cocos2d/CCTMXObjectGroup.m | 83 ++ Classes/cocos2d/CCTMXTiledMap.h | 144 +++ Classes/cocos2d/CCTMXTiledMap.m | 202 ++++ Classes/cocos2d/CCTMXXMLParser.h | 200 ++++ Classes/cocos2d/CCTMXXMLParser.m | 444 +++++++ Classes/cocos2d/CCTexture2D.h | 308 +++++ Classes/cocos2d/CCTexture2D.m | 754 ++++++++++++ Classes/cocos2d/CCTextureAtlas.h | 138 +++ Classes/cocos2d/CCTextureAtlas.m | 343 ++++++ Classes/cocos2d/CCTextureCache.h | 139 +++ Classes/cocos2d/CCTextureCache.m | 466 ++++++++ Classes/cocos2d/CCTexturePVR.h | 118 ++ Classes/cocos2d/CCTexturePVR.m | 407 +++++++ Classes/cocos2d/CCTileMapAtlas.h | 82 ++ Classes/cocos2d/CCTileMapAtlas.m | 233 ++++ Classes/cocos2d/CCTransition.h | 295 +++++ Classes/cocos2d/CCTransition.m | 1057 +++++++++++++++++ Classes/cocos2d/CCTransitionPageTurn.h | 60 + Classes/cocos2d/CCTransitionPageTurn.m | 117 ++ Classes/cocos2d/CCTransitionRadial.h | 40 + Classes/cocos2d/CCTransitionRadial.m | 115 ++ Classes/cocos2d/Platforms/CCGL.h | 82 ++ Classes/cocos2d/Platforms/CCNS.h | 62 + Classes/cocos2d/Platforms/Mac/CCDirectorMac.h | 99 ++ Classes/cocos2d/Platforms/Mac/CCDirectorMac.m | 471 ++++++++ Classes/cocos2d/Platforms/Mac/CCEventDispatcher.h | 233 ++++ Classes/cocos2d/Platforms/Mac/CCEventDispatcher.m | 578 ++++++++++ Classes/cocos2d/Platforms/Mac/MacGLView.h | 88 ++ Classes/cocos2d/Platforms/Mac/MacGLView.m | 241 ++++ Classes/cocos2d/Platforms/iOS/CCDirectorIOS.h | 342 ++++++ Classes/cocos2d/Platforms/iOS/CCDirectorIOS.m | 897 +++++++++++++++ .../Platforms/iOS/CCTouchDelegateProtocol.h | 75 ++ Classes/cocos2d/Platforms/iOS/CCTouchDispatcher.h | 122 ++ Classes/cocos2d/Platforms/iOS/CCTouchDispatcher.m | 326 ++++++ Classes/cocos2d/Platforms/iOS/CCTouchHandler.h | 93 ++ Classes/cocos2d/Platforms/iOS/CCTouchHandler.m | 135 +++ Classes/cocos2d/Platforms/iOS/EAGLView.h | 155 +++ Classes/cocos2d/Platforms/iOS/EAGLView.m | 342 ++++++ Classes/cocos2d/Platforms/iOS/ES1Renderer.h | 71 ++ Classes/cocos2d/Platforms/iOS/ES1Renderer.m | 252 ++++ Classes/cocos2d/Platforms/iOS/ESRenderer.h | 53 + Classes/cocos2d/Platforms/iOS/glu.c | 113 ++ Classes/cocos2d/Platforms/iOS/glu.h | 29 + Classes/cocos2d/Support/CCArray.h | 92 ++ Classes/cocos2d/Support/CCArray.m | 245 ++++ Classes/cocos2d/Support/CCFileUtils.h | 61 + Classes/cocos2d/Support/CCFileUtils.m | 168 +++ Classes/cocos2d/Support/CCProfiling.h | 53 + Classes/cocos2d/Support/CCProfiling.m | 117 ++ Classes/cocos2d/Support/CGPointExtension.h | 321 ++++++ Classes/cocos2d/Support/CGPointExtension.m | 167 +++ Classes/cocos2d/Support/OpenGL_Internal.h | 80 ++ Classes/cocos2d/Support/TGAlib.h | 55 + Classes/cocos2d/Support/TGAlib.m | 272 +++++ Classes/cocos2d/Support/TransformUtils.h | 37 + Classes/cocos2d/Support/TransformUtils.m | 46 + Classes/cocos2d/Support/ZipUtils.h | 78 ++ Classes/cocos2d/Support/ZipUtils.m | 246 ++++ Classes/cocos2d/Support/base64.c | 89 ++ Classes/cocos2d/Support/base64.h | 33 + Classes/cocos2d/Support/ccCArray.h | 406 +++++++ Classes/cocos2d/Support/ccUtils.c | 20 + Classes/cocos2d/Support/ccUtils.h | 29 + Classes/cocos2d/Support/uthash.h | 956 +++++++++++++++ Classes/cocos2d/Support/utlist.h | 493 ++++++++ Classes/cocos2d/ccConfig.h | 291 +++++ Classes/cocos2d/ccMacros.h | 227 ++++ Classes/cocos2d/ccTypes.h | 262 +++++ Classes/cocos2d/cocos2d.h | 165 +++ Classes/cocos2d/cocos2d.m | 33 + Littlest.xcodeproj/project.pbxproj | 14 + 176 files changed, 42357 insertions(+), 703 deletions(-) create mode 100644 Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h create mode 100644 Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm create mode 100644 Classes/cocos2d/CCAction.h create mode 100644 Classes/cocos2d/CCAction.m create mode 100644 Classes/cocos2d/CCActionCamera.h create mode 100644 Classes/cocos2d/CCActionCamera.m create mode 100644 Classes/cocos2d/CCActionEase.h create mode 100644 Classes/cocos2d/CCActionEase.m create mode 100644 Classes/cocos2d/CCActionGrid.h create mode 100644 Classes/cocos2d/CCActionGrid.m create mode 100644 Classes/cocos2d/CCActionGrid3D.h create mode 100644 Classes/cocos2d/CCActionGrid3D.m create mode 100644 Classes/cocos2d/CCActionInstant.h create mode 100644 Classes/cocos2d/CCActionInstant.m create mode 100644 Classes/cocos2d/CCActionInterval.h create mode 100644 Classes/cocos2d/CCActionInterval.m create mode 100644 Classes/cocos2d/CCActionManager.h create mode 100644 Classes/cocos2d/CCActionManager.m create mode 100644 Classes/cocos2d/CCActionPageTurn3D.h create mode 100644 Classes/cocos2d/CCActionPageTurn3D.m create mode 100644 Classes/cocos2d/CCActionProgressTimer.h create mode 100644 Classes/cocos2d/CCActionProgressTimer.m create mode 100644 Classes/cocos2d/CCActionTiledGrid.h create mode 100644 Classes/cocos2d/CCActionTiledGrid.m create mode 100644 Classes/cocos2d/CCActionTween.h create mode 100644 Classes/cocos2d/CCActionTween.m create mode 100644 Classes/cocos2d/CCAnimation.h create mode 100644 Classes/cocos2d/CCAnimation.m create mode 100644 Classes/cocos2d/CCAnimationCache.h create mode 100644 Classes/cocos2d/CCAnimationCache.m create mode 100644 Classes/cocos2d/CCAtlasNode.h create mode 100644 Classes/cocos2d/CCAtlasNode.m create mode 100644 Classes/cocos2d/CCBlockSupport.h create mode 100644 Classes/cocos2d/CCBlockSupport.m create mode 100644 Classes/cocos2d/CCCamera.h create mode 100644 Classes/cocos2d/CCCamera.m create mode 100644 Classes/cocos2d/CCCompatibility.h create mode 100644 Classes/cocos2d/CCCompatibility.m create mode 100644 Classes/cocos2d/CCConfiguration.h create mode 100644 Classes/cocos2d/CCConfiguration.m create mode 100644 Classes/cocos2d/CCDirector.h create mode 100644 Classes/cocos2d/CCDirector.m create mode 100644 Classes/cocos2d/CCDrawingPrimitives.h create mode 100644 Classes/cocos2d/CCDrawingPrimitives.m create mode 100644 Classes/cocos2d/CCGrabber.h create mode 100644 Classes/cocos2d/CCGrabber.m create mode 100644 Classes/cocos2d/CCGrid.h create mode 100644 Classes/cocos2d/CCGrid.m create mode 100644 Classes/cocos2d/CCLabelAtlas.h create mode 100644 Classes/cocos2d/CCLabelAtlas.m create mode 100644 Classes/cocos2d/CCLabelBMFont.h create mode 100644 Classes/cocos2d/CCLabelBMFont.m create mode 100644 Classes/cocos2d/CCLabelTTF.h create mode 100644 Classes/cocos2d/CCLabelTTF.m create mode 100644 Classes/cocos2d/CCLayer.h create mode 100644 Classes/cocos2d/CCLayer.m create mode 100644 Classes/cocos2d/CCMenu.h create mode 100644 Classes/cocos2d/CCMenu.m create mode 100644 Classes/cocos2d/CCMenuItem.h create mode 100644 Classes/cocos2d/CCMenuItem.m create mode 100644 Classes/cocos2d/CCMotionStreak.h create mode 100644 Classes/cocos2d/CCMotionStreak.m create mode 100644 Classes/cocos2d/CCNode.h create mode 100644 Classes/cocos2d/CCNode.m create mode 100644 Classes/cocos2d/CCParallaxNode.h create mode 100644 Classes/cocos2d/CCParallaxNode.m create mode 100644 Classes/cocos2d/CCParticleExamples.h create mode 100644 Classes/cocos2d/CCParticleExamples.m create mode 100644 Classes/cocos2d/CCParticleSystem.h create mode 100644 Classes/cocos2d/CCParticleSystem.m create mode 100644 Classes/cocos2d/CCParticleSystemPoint.h create mode 100644 Classes/cocos2d/CCParticleSystemPoint.m create mode 100644 Classes/cocos2d/CCParticleSystemQuad.h create mode 100644 Classes/cocos2d/CCParticleSystemQuad.m create mode 100644 Classes/cocos2d/CCProgressTimer.h create mode 100644 Classes/cocos2d/CCProgressTimer.m create mode 100644 Classes/cocos2d/CCProtocols.h create mode 100755 Classes/cocos2d/CCRenderTexture.h create mode 100755 Classes/cocos2d/CCRenderTexture.m create mode 100644 Classes/cocos2d/CCRibbon.h create mode 100644 Classes/cocos2d/CCRibbon.m create mode 100644 Classes/cocos2d/CCScene.h create mode 100644 Classes/cocos2d/CCScene.m create mode 100644 Classes/cocos2d/CCScheduler.h create mode 100644 Classes/cocos2d/CCScheduler.m create mode 100644 Classes/cocos2d/CCSprite.h create mode 100644 Classes/cocos2d/CCSprite.m create mode 100644 Classes/cocos2d/CCSpriteBatchNode.h create mode 100644 Classes/cocos2d/CCSpriteBatchNode.m create mode 100644 Classes/cocos2d/CCSpriteFrame.h create mode 100644 Classes/cocos2d/CCSpriteFrame.m create mode 100644 Classes/cocos2d/CCSpriteFrameCache.h create mode 100644 Classes/cocos2d/CCSpriteFrameCache.m create mode 100644 Classes/cocos2d/CCSpriteSheet.h create mode 100644 Classes/cocos2d/CCSpriteSheet.m create mode 100644 Classes/cocos2d/CCTMXLayer.h create mode 100644 Classes/cocos2d/CCTMXLayer.m create mode 100644 Classes/cocos2d/CCTMXObjectGroup.h create mode 100644 Classes/cocos2d/CCTMXObjectGroup.m create mode 100644 Classes/cocos2d/CCTMXTiledMap.h create mode 100644 Classes/cocos2d/CCTMXTiledMap.m create mode 100644 Classes/cocos2d/CCTMXXMLParser.h create mode 100644 Classes/cocos2d/CCTMXXMLParser.m create mode 100644 Classes/cocos2d/CCTexture2D.h create mode 100644 Classes/cocos2d/CCTexture2D.m create mode 100644 Classes/cocos2d/CCTextureAtlas.h create mode 100644 Classes/cocos2d/CCTextureAtlas.m create mode 100644 Classes/cocos2d/CCTextureCache.h create mode 100644 Classes/cocos2d/CCTextureCache.m create mode 100644 Classes/cocos2d/CCTexturePVR.h create mode 100644 Classes/cocos2d/CCTexturePVR.m create mode 100644 Classes/cocos2d/CCTileMapAtlas.h create mode 100644 Classes/cocos2d/CCTileMapAtlas.m create mode 100644 Classes/cocos2d/CCTransition.h create mode 100644 Classes/cocos2d/CCTransition.m create mode 100644 Classes/cocos2d/CCTransitionPageTurn.h create mode 100644 Classes/cocos2d/CCTransitionPageTurn.m create mode 100644 Classes/cocos2d/CCTransitionRadial.h create mode 100644 Classes/cocos2d/CCTransitionRadial.m create mode 100644 Classes/cocos2d/Platforms/CCGL.h create mode 100644 Classes/cocos2d/Platforms/CCNS.h create mode 100644 Classes/cocos2d/Platforms/Mac/CCDirectorMac.h create mode 100644 Classes/cocos2d/Platforms/Mac/CCDirectorMac.m create mode 100644 Classes/cocos2d/Platforms/Mac/CCEventDispatcher.h create mode 100644 Classes/cocos2d/Platforms/Mac/CCEventDispatcher.m create mode 100644 Classes/cocos2d/Platforms/Mac/MacGLView.h create mode 100644 Classes/cocos2d/Platforms/Mac/MacGLView.m create mode 100755 Classes/cocos2d/Platforms/iOS/CCDirectorIOS.h create mode 100755 Classes/cocos2d/Platforms/iOS/CCDirectorIOS.m create mode 100644 Classes/cocos2d/Platforms/iOS/CCTouchDelegateProtocol.h create mode 100644 Classes/cocos2d/Platforms/iOS/CCTouchDispatcher.h create mode 100644 Classes/cocos2d/Platforms/iOS/CCTouchDispatcher.m create mode 100644 Classes/cocos2d/Platforms/iOS/CCTouchHandler.h create mode 100644 Classes/cocos2d/Platforms/iOS/CCTouchHandler.m create mode 100755 Classes/cocos2d/Platforms/iOS/EAGLView.h create mode 100755 Classes/cocos2d/Platforms/iOS/EAGLView.m create mode 100755 Classes/cocos2d/Platforms/iOS/ES1Renderer.h create mode 100755 Classes/cocos2d/Platforms/iOS/ES1Renderer.m create mode 100755 Classes/cocos2d/Platforms/iOS/ESRenderer.h create mode 100755 Classes/cocos2d/Platforms/iOS/glu.c create mode 100644 Classes/cocos2d/Platforms/iOS/glu.h create mode 100644 Classes/cocos2d/Support/CCArray.h create mode 100644 Classes/cocos2d/Support/CCArray.m create mode 100644 Classes/cocos2d/Support/CCFileUtils.h create mode 100644 Classes/cocos2d/Support/CCFileUtils.m create mode 100644 Classes/cocos2d/Support/CCProfiling.h create mode 100644 Classes/cocos2d/Support/CCProfiling.m create mode 100644 Classes/cocos2d/Support/CGPointExtension.h create mode 100644 Classes/cocos2d/Support/CGPointExtension.m create mode 100644 Classes/cocos2d/Support/OpenGL_Internal.h create mode 100644 Classes/cocos2d/Support/TGAlib.h create mode 100644 Classes/cocos2d/Support/TGAlib.m create mode 100644 Classes/cocos2d/Support/TransformUtils.h create mode 100644 Classes/cocos2d/Support/TransformUtils.m create mode 100644 Classes/cocos2d/Support/ZipUtils.h create mode 100644 Classes/cocos2d/Support/ZipUtils.m create mode 100644 Classes/cocos2d/Support/base64.c create mode 100644 Classes/cocos2d/Support/base64.h create mode 100644 Classes/cocos2d/Support/ccCArray.h create mode 100644 Classes/cocos2d/Support/ccUtils.c create mode 100644 Classes/cocos2d/Support/ccUtils.h create mode 100644 Classes/cocos2d/Support/uthash.h create mode 100644 Classes/cocos2d/Support/utlist.h create mode 100644 Classes/cocos2d/ccConfig.h create mode 100644 Classes/cocos2d/ccMacros.h create mode 100644 Classes/cocos2d/ccTypes.h create mode 100644 Classes/cocos2d/cocos2d.h create mode 100644 Classes/cocos2d/cocos2d.m diff --git a/Classes/Foundation/Common/GlobalDefines.h b/Classes/Foundation/Common/GlobalDefines.h index 7dde617..14712b2 100755 --- a/Classes/Foundation/Common/GlobalDefines.h +++ b/Classes/Foundation/Common/GlobalDefines.h @@ -70,9 +70,9 @@ //---------------------------------------------------------------------------------------- // alignment macros #if defined(__WINDOWS__) -#define ALIGN(N) __declspec(align(N)) +#define MEM_ALIGN(N) __declspec(align(N)) #elif defined(__iOS__) -#define ALIGN(N) __attribute__((aligned (N))) +#define MEM_ALIGN(N) __attribute__((aligned (N))) #endif #define IS_POWER_OF_TWO(x) ( ((x) & -(x)) == (x) ) diff --git a/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h new file mode 100644 index 0000000..ba50ba9 --- /dev/null +++ b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h @@ -0,0 +1,27 @@ +#pragma once + +#include "Foundation/Common/GlobalInclude.h" +#include "Foundation/Math/MathInclude.h" + +//#include +#include + +//---------------------------------------------------------------------------------------- +struct Basic2DPrimitive +{ +protected: + Basic2DPrimitive(); // Only the children classes can call this. + ~Basic2DPrimitive(); + + GLuint mVertexBuffer; + uint16_t mX, mY; +}; + +//---------------------------------------------------------------------------------------- +struct Rectangle : public Basic2DPrimitive +{ +public: + GLuint mWidth, mHeight; + + Rectangle( uint16_t width, uint16_t height, uint16_t anchorX, uint16_t anchorY ); +}; diff --git a/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm new file mode 100644 index 0000000..4cc9da1 --- /dev/null +++ b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm @@ -0,0 +1,26 @@ +#include "BasicPrimitives.h" + +//---------------------------------------------------------------------------------------- +Basic2DPrimitive::Basic2DPrimitive() : mVertexBuffer(0), mX(0), mY(0) +{ + glGenBuffers( 1, &mVertexBuffer ); +} + +//---------------------------------------------------------------------------------------- +Basic2DPrimitive::~Basic2DPrimitive() +{ + glDeleteBuffers( 1, &mVertexBuffer ); +} + +//---------------------------------------------------------------------------------------- +Rectangle::Rectangle( uint16_t width, uint16_t height, uint16_t anchorX, uint16_t anchorY ) : Basic2DPrimitive() +{ + Assert( mVertexBuffer ); + glBindBuffer( GL_ARRAY_BUFFER, mVertexBuffer ); + + mWidth = width; + mHeight = height; + + uint16_t values[4 * 2] = {-anchorX, height + anchorY, -anchorX, }; + glBufferData( GL_ARRAY_BUFFER, 4 * 2 * sizeof(uint16_t), values, GL_STATIC_DRAW ); +} diff --git a/Classes/Foundation/GraphicsServices/OpenGLServices.h b/Classes/Foundation/GraphicsServices/OpenGLServices.h index 819ba12..deadd57 100644 --- a/Classes/Foundation/GraphicsServices/OpenGLServices.h +++ b/Classes/Foundation/GraphicsServices/OpenGLServices.h @@ -10,8 +10,8 @@ * we should never need to set context other than during startup or shutdown. *****************************************************************************************/ -#include -#include +//#include +//#include #include #include diff --git a/Classes/Foundation/GraphicsServices/OpenGLServices.mm b/Classes/Foundation/GraphicsServices/OpenGLServices.mm index 236059e..9c1f7a2 100644 --- a/Classes/Foundation/GraphicsServices/OpenGLServices.mm +++ b/Classes/Foundation/GraphicsServices/OpenGLServices.mm @@ -22,16 +22,21 @@ bool OpenGLServices::init( EAGLContext* mainContext ) initScratchMem(); - // Enable some common states. + // Enable some common states and set their parameters. glEnable( GL_TEXTURE_2D ); - glEnable( GL_BLEND ); - // We will premultiply alpha into the color channels of all textures (so no alpha animation). // This is basically the A over B alpha scheme. glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); - glEnable( GL_DEPTH_TEST ); + glDepthFunc( GL_LEQUAL ); + glFrontFace( GL_CCW ); + glCullFace( GL_BACK ); + + // Disable unused stuff. + glDisable( GL_STENCIL_TEST ); + glDisable( GL_SCISSOR_TEST ); + glDisable( GL_DITHER ); return true; } diff --git a/Classes/Foundation/Math/MathTypes.h b/Classes/Foundation/Math/MathTypes.h index c16a44e..379bf16 100755 --- a/Classes/Foundation/Math/MathTypes.h +++ b/Classes/Foundation/Math/MathTypes.h @@ -4,16 +4,16 @@ #include "Foundation/Math/MathOperations.h" //---------------------------------------------------------------------------------------- -struct Vector2 +struct Vec2 { float x; float y; - slInline explicit Vector2() {} - slInline explicit Vector2(const float xy) {x = xy; y = xy;} - slInline explicit Vector2(const float ix, const float iy) {x = ix; y = iy;} + slInline explicit Vec2() {} + slInline explicit Vec2(const float xy) {x = xy; y = xy;} + slInline explicit Vec2(const float ix, const float iy) {x = ix; y = iy;} - slInline Vector2(const Vector2& v) {x = v.x; y = v.y;} // copy constructor + slInline Vec2(const Vec2& v) {x = v.x; y = v.y;} // copy constructor slInline float* AsFloatArray() {return &x;} slInline const float* AsFloatArray() const {return &x;} @@ -23,21 +23,21 @@ struct Vector2 //---------------------------------------------------------------------------------------- -struct Vector3 +struct Vec3 { float x; float y; float z; - slInline explicit Vector3() {} - slInline explicit Vector3(const float xyz) {x = xyz; y = xyz; z = xyz;} - slInline explicit Vector3(const float ix, const float iy, const float iz) {x = ix; y = iy; z = iz;} + slInline explicit Vec3() {} + slInline explicit Vec3(const float xyz) {x = xyz; y = xyz; z = xyz;} + slInline explicit Vec3(const float ix, const float iy, const float iz) {x = ix; y = iy; z = iz;} - slInline explicit Vector3(const Vector2& v, const float iz) {x = v.x; y = v.y; z = iz;} + slInline explicit Vec3(const Vec2& v, const float iz) {x = v.x; y = v.y; z = iz;} - slInline Vector3(const Vector3& v) {x = v.x; y = v.y; z = v.z;} // copy constructor + slInline Vec3(const Vec3& v) {x = v.x; y = v.y; z = v.z;} // copy constructor - slInline Vector2 AsVector2() const {return Vector2(x, y);} + slInline Vec2 AsVec2() const {return Vec2(x, y);} slInline float* AsFloatArray() {return &x;} slInline const float* AsFloatArray() const {return &x;} @@ -47,27 +47,27 @@ struct Vector3 //---------------------------------------------------------------------------------------- -struct Vector4 +struct Vec4 { float x; float y; float z; float w; - slInline explicit Vector4() {} - slInline explicit Vector4(const float xyzw) {x = xyzw; y = xyzw; z = xyzw; w = xyzw;} - slInline explicit Vector4(const float xyz, const float iw) {x = xyz; y = xyz; z = xyz; w = iw;} - slInline explicit Vector4(const float ix, const float iy, const float iz, const float iw) {x = ix; y = iy; z = iz; w = iw;} + slInline explicit Vec4() {} + slInline explicit Vec4(const float xyzw) {x = xyzw; y = xyzw; z = xyzw; w = xyzw;} + slInline explicit Vec4(const float xyz, const float iw) {x = xyz; y = xyz; z = xyz; w = iw;} + slInline explicit Vec4(const float ix, const float iy, const float iz, const float iw) {x = ix; y = iy; z = iz; w = iw;} - slInline explicit Vector4(const Vector2& u, const Vector2& v) {x = u.x; y = u.y; z = v.x; w = v.y;} - slInline explicit Vector4(const Vector2& v, const float iz, const float iw) {x = v.x; y = v.y; z = iz; w = iw;} + slInline explicit Vec4(const Vec2& u, const Vec2& v) {x = u.x; y = u.y; z = v.x; w = v.y;} + slInline explicit Vec4(const Vec2& v, const float iz, const float iw) {x = v.x; y = v.y; z = iz; w = iw;} - slInline explicit Vector4(const Vector3& v, const float iw) {x = v.x; y = v.y; z = v.z; w = iw;} + slInline explicit Vec4(const Vec3& v, const float iw) {x = v.x; y = v.y; z = v.z; w = iw;} - slInline Vector4(const Vector4& v) {x = v.x; y = v.y; z = v.z; w = v.w;} // copy constructor + slInline Vec4(const Vec4& v) {x = v.x; y = v.y; z = v.z; w = v.w;} // copy constructor - slInline Vector2 AsVector2() const {return Vector2(x, y);} - slInline Vector3 AsVector3() const {return Vector3(x, y, z);} + slInline Vec2 AsVec2() const {return Vec2(x, y);} + slInline Vec3 AsVec3() const {return Vec3(x, y, z);} slInline float* AsFloatArray() {return &x;} slInline const float* AsFloatArray() const {return &x;} @@ -85,43 +85,43 @@ struct Quaternion float s; slInline explicit Quaternion() {} - explicit Quaternion(const float angle, const Vector3& normalized_axis); + explicit Quaternion(const float angle, const Vec3& normalized_axis); explicit Quaternion(const float angle, const float x, const float y, const float z); slInline Quaternion(const Quaternion& q) {i = q.i; j = q.j; k = q.k; s = q.s;} - Vector4 AsVector4(); + Vec4 AsVec4(); slInline float* AsFloatArray() {return &i;} - Vector3 GetImaginary(); + Vec3 GetImaginary(); slInline float GetReal() {return s;} }; -slInline Quaternion::Quaternion(const float angle, const Vector3& normalized_axis) +slInline Quaternion::Quaternion(const float angle, const Vec3& normalized_axis) { - Assert( EpsilonEquals(LengthVector3(normalized_axis), 1.0f, kEpsilon) ); + Assert( EpsilonEquals(normalized_axis.x * normalized_axis.x + normalized_axis.y * normalized_axis.y + normalized_axis.z * normalized_axis.z, 1.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); i = normalized_axis.x * sin_half_angle; j = normalized_axis.y * sin_half_angle; k = normalized_axis.z * sin_half_angle; - s = Cosf(half_angle); + s = (float)Cosf(half_angle); } slInline Quaternion::Quaternion(const float angle, const float x, const float y, const float z) { Assert( EpsilonEquals(x * x + y * y + z * z, 1.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); i = x * sin_half_angle; j = y * sin_half_angle; k = z * sin_half_angle; - s = Cosf(half_angle); + s = (float)Cosf(half_angle); } -Vector4 Quaternion::AsVector4() +Vec4 Quaternion::AsVec4() { - Vector4 r; + Vec4 r; r.x = i; r.y = j; r.z = k; @@ -129,9 +129,9 @@ Vector4 Quaternion::AsVector4() return r; } -Vector3 Quaternion::GetImaginary() +Vec3 Quaternion::GetImaginary() { - Vector3 r; + Vec3 r; r.x = i; r.y = j; r.z = k; @@ -140,35 +140,35 @@ Vector3 Quaternion::GetImaginary() //---------------------------------------------------------------------------------------- -struct Matrix3 +struct Mat3 { - Vector3 v[3]; + Vec3 v[3]; - slInline explicit Matrix3() {} - explicit Matrix3(const Vector3& v0, const Vector3& v1, const Vector3& v2); - explicit Matrix3(const float v00, const float v01, const float v02, - const float v10, const float v11, const float v12, - const float v20, const float v21, const float v22); - Matrix3(Matrix3& m); // copy constructor + slInline explicit Mat3() {} + explicit Mat3(const Vec3& v0, const Vec3& v1, const Vec3& v2); + explicit Mat3(const float v00, const float v01, const float v02, + const float v10, const float v11, const float v12, + const float v20, const float v21, const float v22); + Mat3(const Mat3& m); // copy constructor float* AsFloatArray() {return &v[0].x;} }; -slInline Matrix3::Matrix3(const Vector3& v0, const Vector3& v1, const Vector3& v2) +slInline Mat3::Mat3(const Vec3& v0, const Vec3& v1, const Vec3& v2) { v[0] = v0; v[1] = v1; v[2] = v2; } -slInline Matrix3::Matrix3(const float v00, const float v01, const float v02, const float v10, const float v11, const float v12, const float v20, const float v21, const float v22) +slInline Mat3::Mat3(const float v00, const float v01, const float v02, const float v10, const float v11, const float v12, const float v20, const float v21, const float v22) { v[0].x = v00; v[0].y = v01; v[0].z = v02; v[1].x = v10; v[1].y = v11; v[1].z = v12; v[2].x = v20; v[2].y = v21; v[2].z = v22; } -slInline Matrix3::Matrix3(Matrix3& m) +slInline Mat3::Mat3(const Mat3& m) { v[0] = m.v[0]; v[1] = m.v[1]; @@ -177,23 +177,23 @@ slInline Matrix3::Matrix3(Matrix3& m) //---------------------------------------------------------------------------------------- -struct Matrix4 +struct Mat4 { - Vector4 v[4]; + Vec4 v[4]; - slInline explicit Matrix4() {} - explicit Matrix4(const Vector4& v0, const Vector4& v1, const Vector4& v2, const Vector4& v3); - explicit Matrix4(const float v00, const float v01, const float v02, const float v03, - const float v10, const float v11, const float v12, const float v13, - const float v20, const float v21, const float v22, const float v23, - const float v30, const float v31, const float v32, const float v33); - explicit Matrix4(const Matrix3& m); - Matrix4(const Matrix4& m); // copy constructor + slInline explicit Mat4() {} + explicit Mat4(const Vec4& v0, const Vec4& v1, const Vec4& v2, const Vec4& v3); + explicit Mat4(const float v00, const float v01, const float v02, const float v03, + const float v10, const float v11, const float v12, const float v13, + const float v20, const float v21, const float v22, const float v23, + const float v30, const float v31, const float v32, const float v33); + explicit Mat4(const Mat3& m); + Mat4(const Mat4& m); // copy constructor float* AsFloatArray() {return &v[0].x;} }; -slInline Matrix4::Matrix4(const Vector4& v0, const Vector4& v1, const Vector4& v2, const Vector4& v3) +slInline Mat4::Mat4(const Vec4& v0, const Vec4& v1, const Vec4& v2, const Vec4& v3) { v[0] = v0; v[1] = v1; @@ -201,7 +201,7 @@ slInline Matrix4::Matrix4(const Vector4& v0, const Vector4& v1, const Vector4& v v[3] = v3; } -slInline Matrix4::Matrix4(const float v00, const float v01, const float v02, const float v03, const float v10, const float v11, const float v12, const float v13, const float v20, const float v21, const float v22, const float v23, const float v30, const float v31, const float v32, const float v33) +slInline Mat4::Mat4(const float v00, const float v01, const float v02, const float v03, const float v10, const float v11, const float v12, const float v13, const float v20, const float v21, const float v22, const float v23, const float v30, const float v31, const float v32, const float v33) { v[0].x = v00; v[0].y = v01; v[0].z = v02; v[0].w = v03; v[1].x = v10; v[1].y = v11; v[1].z = v12; v[1].w = v13; @@ -209,7 +209,7 @@ slInline Matrix4::Matrix4(const float v00, const float v01, const float v02, con v[3].x = v30; v[3].y = v31; v[3].z = v32; v[3].w = v33; } -slInline Matrix4::Matrix4(const Matrix3& m) +slInline Mat4::Mat4(const Mat3& m) { v[0].x = m.v[0].x; v[0].y = m.v[0].y; v[0].z = m.v[0].z; v[0].w = 0.0f; v[1].x = m.v[1].x; v[1].y = m.v[1].y; v[1].z = m.v[1].z; v[1].w = 0.0f; @@ -217,7 +217,7 @@ slInline Matrix4::Matrix4(const Matrix3& m) v[3].x = 0.0f; v[3].y = 0.0f; v[3].z = 0.0f; v[3].w = 1.0f; } -slInline Matrix4::Matrix4(const Matrix4& m) +slInline Mat4::Mat4(const Mat4& m) { v[0] = m.v[0]; v[1] = m.v[1]; @@ -227,18 +227,18 @@ slInline Matrix4::Matrix4(const Matrix4& m) //---------------------------------------------------------------------------------------- -typedef ALIGN(8) Vector2 AlignedVector2; -typedef ALIGN(16) Vector3 AlignedVector3; -typedef ALIGN(16) Vector4 AlignedVector4; +typedef MEM_ALIGN(8) Vec2 AlignedVec2; +typedef MEM_ALIGN(16) Vec3 AlignedVec3; +typedef MEM_ALIGN(16) Vec4 AlignedVec4; -typedef ALIGN(64) Matrix3 AlignedMatrix3; -typedef ALIGN(64) Matrix4 AlignedMatrix4; +typedef MEM_ALIGN(64) Mat3 AlignedMat3; +typedef MEM_ALIGN(64) Mat4 AlignedMat4; //---------------------------------------------------------------------------------------- // SIMD Structures //---------------------------------------------------------------------------------------- -struct Vector2SOA +struct Vec2SOA { uint32_t m_Count; uint32_t m_MaxCount; @@ -246,13 +246,13 @@ struct Vector2SOA float* m_X; float* m_Y; - slInline explicit Vector2SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL;} - bool InitVector2SOA(float* buffer, uint32_t buffer_size); + slInline explicit Vec2SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL;} + bool InitVec2SOA(float* buffer, uint32_t buffer_size); - void GetVector2AtIndex(Vector2& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index];} + void GetVec2AtIndex(Vec2& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index];} }; -slInline bool Vector2SOA::InitVector2SOA(float* buffer, uint32_t max_count) +slInline bool Vec2SOA::InitVec2SOA(float* buffer, uint32_t max_count) { m_Count = 0; @@ -280,17 +280,17 @@ slInline bool Vector2SOA::InitVector2SOA(float* buffer, uint32_t max_count) //---------------------------------------------------------------------------------------- -struct Vector3SOA : public Vector2SOA +struct Vec3SOA : public Vec2SOA { float* m_Z; - slInline explicit Vector3SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL;} - bool InitVector3SOA(float* buffer, uint32_t buffer_size); + slInline explicit Vec3SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL;} + bool InitVec3SOA(float* buffer, uint32_t buffer_size); - void GetVector3AtIndex(Vector3& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index];} + void GetVec3AtIndex(Vec3& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index];} }; -slInline bool Vector3SOA::InitVector3SOA(float* buffer, uint32_t max_count) +slInline bool Vec3SOA::InitVec3SOA(float* buffer, uint32_t max_count) { m_Count = 0; @@ -321,17 +321,17 @@ slInline bool Vector3SOA::InitVector3SOA(float* buffer, uint32_t max_count) //---------------------------------------------------------------------------------------- -struct Vector4SOA : public Vector3SOA +struct Vec4SOA : public Vec3SOA { float* m_W; - slInline explicit Vector4SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL; m_W = NULL;} - bool InitVector4SOA(float* buffer, uint32_t buffer_size); + slInline explicit Vec4SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL; m_W = NULL;} + bool InitVec4SOA(float* buffer, uint32_t buffer_size); - void GetVector4AtIndex(Vector4& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index]; v.w = m_W[index];} + void GetVec4AtIndex(Vec4& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index]; v.w = m_W[index];} }; -slInline bool Vector4SOA::InitVector4SOA(float* buffer, uint32_t max_count) +slInline bool Vec4SOA::InitVec4SOA(float* buffer, uint32_t max_count) { m_Count = 0; diff --git a/Classes/Foundation/Math/Matrix.h b/Classes/Foundation/Math/Matrix.h index 37e5362..40e2a70 100755 --- a/Classes/Foundation/Math/Matrix.h +++ b/Classes/Foundation/Math/Matrix.h @@ -21,36 +21,36 @@ //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- -// Matrix3 +// Mat3 //---------------------------------------------------------------------------------------- -void SetMatrix3(Matrix3& r, const Matrix3& a); -void SetMatrix3(Matrix3& r, const Vector3& v0, const Vector3& v1, const Vector3& v2); +void SetMat3(Mat3& r, const Mat3& a); +void SetMat3(Mat3& r, const Vec3& v0, const Vec3& v1, const Vec3& v2); -void ScaleMatrix3(Matrix3& r, const float s, const Matrix3& a); -Matrix3 ScaleMatrix3(const float s, const Matrix3& a); +void ScaleMat3(Mat3& r, const float s, const Mat3& a); +Mat3 ScaleMat3(const float s, const Mat3& a); -float DeterminantOfMatrix3(const Matrix3& a); +float DeterminantOfMat3(const Mat3& a); -void TransposeMatrix3(Matrix3& r, const Matrix3& a); -Matrix3 TransposeMatrix3(const Matrix3& a); +void TransposeMat3(Mat3& r, const Mat3& a); +Mat3 TransposeMat3(const Mat3& a); -void InvertAffineMatrix3(Matrix3& r, const Matrix3& a); -Matrix3 InvertAffineMatrix3(const Matrix3& a); +void InvertAffineMat3(Mat3& r, const Mat3& a); +Mat3 InvertAffineMat3(const Mat3& a); -void InvertGeneralMatrix3(Matrix3& r, const Matrix3& a); -Matrix3 InvertGeneralMatrix3(const Matrix3& a); +void InvertGeneralMat3(Mat3& r, const Mat3& a); +Mat3 InvertGeneralMat3(const Mat3& a); -void MulMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b); -Matrix3 MulMatrix3(const Matrix3& a, const Matrix3& b); +void MulMat3(Mat3& r, const Mat3& a, const Mat3& b); +Mat3 MulMat3(const Mat3& a, const Mat3& b); -void MulMatrix3ByTransposedMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b); -Matrix3 MulMatrix3ByTransposedMatrix3(const Matrix3& a, const Matrix3& b); +void MulMat3ByTransposedMat3(Mat3& r, const Mat3& a, const Mat3& b); +Mat3 MulMat3ByTransposedMat3(const Mat3& a, const Mat3& b); -void MulVector3ByMatrix3(Vector3& r, const Vector3& v, const Matrix3& a); -Vector3 MulVector3ByMatrix3(const Vector3& v, const Matrix3& a); +void MulVec3ByMat3(Vec3& r, const Vec3& v, const Mat3& a); +Vec3 MulVec3ByMat3(const Vec3& v, const Mat3& a); //---------------------------------------------------------------------------------------- -slInline void SetMatrix3(Matrix3& r, const Matrix3& a) +slInline void SetMat3(Mat3& r, const Mat3& a) { r.v[0] = a.v[0]; r.v[1] = a.v[1]; @@ -58,7 +58,7 @@ slInline void SetMatrix3(Matrix3& r, const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline void SetMatrix3(Matrix3& r, const Vector3& v0, const Vector3& v1, const Vector3& v2) +slInline void SetMat3(Mat3& r, const Vec3& v0, const Vec3& v1, const Vec3& v2) { r.v[0] = v0; r.v[1] = v1; @@ -66,25 +66,25 @@ slInline void SetMatrix3(Matrix3& r, const Vector3& v0, const Vector3& v1, const } //---------------------------------------------------------------------------------------- -slInline void ScaleMatrix3(Matrix3& r, const float s, const Matrix3& a) +slInline void ScaleMat3(Mat3& r, const float s, const Mat3& a) { - ScaleVector3(r.v[0], s, a.v[0]); - ScaleVector3(r.v[1], s, a.v[1]); - ScaleVector3(r.v[2], s, a.v[2]); + ScaleVec3(r.v[0], s, a.v[0]); + ScaleVec3(r.v[1], s, a.v[1]); + ScaleVec3(r.v[2], s, a.v[2]); } //---------------------------------------------------------------------------------------- -slInline Matrix3 ScaleMatrix3(const float s, const Matrix3& a) +slInline Mat3 ScaleMat3(const float s, const Mat3& a) { - Matrix3 r; - ScaleVector3(r.v[0], s, a.v[0]); - ScaleVector3(r.v[1], s, a.v[1]); - ScaleVector3(r.v[2], s, a.v[2]); + Mat3 r; + ScaleVec3(r.v[0], s, a.v[0]); + ScaleVec3(r.v[1], s, a.v[1]); + ScaleVec3(r.v[2], s, a.v[2]); return r; } //---------------------------------------------------------------------------------------- -slInline float DeterminantOfMatrix3(const Matrix3& a) +slInline float DeterminantOfMat3(const Mat3& a) { return a.v[0].x * (a.v[1].y * a.v[2].z - a.v[1].z * a.v[2].y) + a.v[0].y * (a.v[1].z * a.v[2].x - a.v[1].x * a.v[2].z) @@ -92,7 +92,7 @@ slInline float DeterminantOfMatrix3(const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline void TransposeMatrix3(Matrix3& r, const Matrix3& a) +slInline void TransposeMat3(Mat3& r, const Mat3& a) { // a might be the same as r r.v[0].x = a.v[0].x; @@ -114,9 +114,9 @@ slInline void TransposeMatrix3(Matrix3& r, const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline Matrix3 TransposeMatrix3(const Matrix3& a) +slInline Mat3 TransposeMat3(const Mat3& a) { - Matrix3 r; + Mat3 r; r.v[0].x = a.v[0].x; r.v[0].y = a.v[1].x; r.v[0].z = a.v[2].x; r.v[1].x = a.v[0].y; r.v[1].y = a.v[1].y; r.v[1].z = a.v[2].y; r.v[2].x = a.v[0].z; r.v[2].y = a.v[1].z; r.v[2].z = a.v[2].z; @@ -124,139 +124,139 @@ slInline Matrix3 TransposeMatrix3(const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline void InvertAffineMatrix3(Matrix3& r, const Matrix3& a) +slInline void InvertAffineMat3(Mat3& r, const Mat3& a) { - TransposeMatrix3(r, a); + TransposeMat3(r, a); } //---------------------------------------------------------------------------------------- -slInline Matrix3 InvertAffineMatrix3(const Matrix3& a) +slInline Mat3 InvertAffineMat3(const Mat3& a) { - return TransposeMatrix3(a); + return TransposeMat3(a); } //---------------------------------------------------------------------------------------- -slInline void InvertGeneralMatrix3(Matrix3& r, const Matrix3& a) +slInline void InvertGeneralMat3(Mat3& r, const Mat3& a) { - float inv_determinant = 1.0f / DeterminantOfMatrix3(a); + float inv_determinant = 1.0f / DeterminantOfMat3(a); - Matrix3 a_T; - TransposeMatrix3(a_T, a); - CrossVector3(r.v[0], a_T.v[1], a_T.v[2]); - CrossVector3(r.v[1], a_T.v[2], a_T.v[0]); - CrossVector3(r.v[2], a_T.v[0], a_T.v[1]); + Mat3 a_T; + TransposeMat3(a_T, a); + CrossVec3(r.v[0], a_T.v[1], a_T.v[2]); + CrossVec3(r.v[1], a_T.v[2], a_T.v[0]); + CrossVec3(r.v[2], a_T.v[0], a_T.v[1]); - ScaleMatrix3(r, inv_determinant, r); + ScaleMat3(r, inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline Matrix3 InvertGeneralMatrix3(const Matrix3& a) +slInline Mat3 InvertGeneralMat3(const Mat3& a) { - float inv_determinant = 1.0f / DeterminantOfMatrix3(a); + float inv_determinant = 1.0f / DeterminantOfMat3(a); - Matrix3 r; - Matrix3 a_T = TransposeMatrix3(a); - CrossVector3(r.v[0], a_T.v[1], a_T.v[2]); - CrossVector3(r.v[1], a_T.v[2], a_T.v[0]); - CrossVector3(r.v[2], a_T.v[0], a_T.v[1]); + Mat3 r; + Mat3 a_T = TransposeMat3(a); + CrossVec3(r.v[0], a_T.v[1], a_T.v[2]); + CrossVec3(r.v[1], a_T.v[2], a_T.v[0]); + CrossVec3(r.v[2], a_T.v[0], a_T.v[1]); - return ScaleMatrix3(inv_determinant, r); + return ScaleMat3(inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline void MulMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b) +slInline void MulMat3(Mat3& r, const Mat3& a, const Mat3& b) { - Matrix3 temp; + Mat3 temp; - temp.v[0].x = DotVector3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); - temp.v[0].y = DotVector3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); - temp.v[0].z = DotVector3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); + temp.v[0].x = DotVec3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); + temp.v[0].y = DotVec3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); + temp.v[0].z = DotVec3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); - temp.v[1].x = DotVector3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); - temp.v[1].y = DotVector3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); - temp.v[1].z = DotVector3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); + temp.v[1].x = DotVec3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); + temp.v[1].y = DotVec3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); + temp.v[1].z = DotVec3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); - temp.v[2].x = DotVector3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); - temp.v[2].y = DotVector3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); - temp.v[2].z = DotVector3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); + temp.v[2].x = DotVec3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); + temp.v[2].y = DotVec3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); + temp.v[2].z = DotVec3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); - SetMatrix3(r, temp); + SetMat3(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix3 MulMatrix3(const Matrix3& a, const Matrix3& b) +slInline Mat3 MulMat3(const Mat3& a, const Mat3& b) { - Matrix3 r; + Mat3 r; - r.v[0].x = DotVector3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); - r.v[0].y = DotVector3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); - r.v[0].z = DotVector3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); + r.v[0].x = DotVec3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); + r.v[0].y = DotVec3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); + r.v[0].z = DotVec3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); - r.v[1].x = DotVector3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); - r.v[1].y = DotVector3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); - r.v[1].z = DotVector3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); + r.v[1].x = DotVec3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); + r.v[1].y = DotVec3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); + r.v[1].z = DotVec3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); - r.v[2].x = DotVector3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); - r.v[2].y = DotVector3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); - r.v[2].z = DotVector3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); + r.v[2].x = DotVec3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); + r.v[2].y = DotVec3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); + r.v[2].z = DotVec3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); return r; } //---------------------------------------------------------------------------------------- -slInline void MulMatrix3ByTransposedMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b) +slInline void MulMat3ByTransposedMat3(Mat3& r, const Mat3& a, const Mat3& b) { - Matrix3 temp; + Mat3 temp; - temp.v[0].x = DotVector3(a.v[0], b.v[0]); - temp.v[0].y = DotVector3(a.v[0], b.v[1]); - temp.v[0].z = DotVector3(a.v[0], b.v[2]); + temp.v[0].x = DotVec3(a.v[0], b.v[0]); + temp.v[0].y = DotVec3(a.v[0], b.v[1]); + temp.v[0].z = DotVec3(a.v[0], b.v[2]); - temp.v[1].x = DotVector3(a.v[1], b.v[0]); - temp.v[1].y = DotVector3(a.v[1], b.v[1]); - temp.v[1].z = DotVector3(a.v[1], b.v[2]); + temp.v[1].x = DotVec3(a.v[1], b.v[0]); + temp.v[1].y = DotVec3(a.v[1], b.v[1]); + temp.v[1].z = DotVec3(a.v[1], b.v[2]); - temp.v[2].x = DotVector3(a.v[2], b.v[0]); - temp.v[2].y = DotVector3(a.v[2], b.v[1]); - temp.v[2].z = DotVector3(a.v[2], b.v[2]); + temp.v[2].x = DotVec3(a.v[2], b.v[0]); + temp.v[2].y = DotVec3(a.v[2], b.v[1]); + temp.v[2].z = DotVec3(a.v[2], b.v[2]); - SetMatrix3(r, temp); + SetMat3(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix3 MulMatrix3ByTransposedMatrix3(const Matrix3& a, const Matrix3& b) +slInline Mat3 MulMat3ByTransposedMat3(const Mat3& a, const Mat3& b) { - Matrix3 r; + Mat3 r; - r.v[0].x = DotVector3(a.v[0], b.v[0]); - r.v[0].y = DotVector3(a.v[0], b.v[1]); - r.v[0].z = DotVector3(a.v[0], b.v[2]); + r.v[0].x = DotVec3(a.v[0], b.v[0]); + r.v[0].y = DotVec3(a.v[0], b.v[1]); + r.v[0].z = DotVec3(a.v[0], b.v[2]); - r.v[1].x = DotVector3(a.v[1], b.v[0]); - r.v[1].y = DotVector3(a.v[1], b.v[1]); - r.v[1].z = DotVector3(a.v[1], b.v[2]); + r.v[1].x = DotVec3(a.v[1], b.v[0]); + r.v[1].y = DotVec3(a.v[1], b.v[1]); + r.v[1].z = DotVec3(a.v[1], b.v[2]); - r.v[2].x = DotVector3(a.v[2], b.v[0]); - r.v[2].y = DotVector3(a.v[2], b.v[1]); - r.v[2].z = DotVector3(a.v[2], b.v[2]); + r.v[2].x = DotVec3(a.v[2], b.v[0]); + r.v[2].y = DotVec3(a.v[2], b.v[1]); + r.v[2].z = DotVec3(a.v[2], b.v[2]); return r; } //---------------------------------------------------------------------------------------- // do NOT pass in components of a as the r vector -slInline void MulVector3ByMatrix3(Vector3& r, const Vector3& v, const Matrix3& a) +slInline void MulVec3ByMat3(Vec3& r, const Vec3& v, const Mat3& a) { float x = v.x * a.v[0].x + v.y * a.v[1].x + v.z * a.v[2].x; float y = v.x * a.v[0].y + v.y * a.v[1].y + v.z * a.v[2].y; float z = v.x * a.v[0].z + v.y * a.v[1].z + v.z * a.v[2].z; - SetVector3(r, x, y, z); + SetVec3(r, x, y, z); } //---------------------------------------------------------------------------------------- -slInline Vector3 MulVector3ByMatrix3(const Vector3& v, const Matrix3& a) +slInline Vec3 MulVec3ByMat3(const Vec3& v, const Mat3& a) { - Vector3 r; + Vec3 r; r.x = v.x * a.v[0].x + v.y * a.v[1].x + v.z * a.v[2].x; r.y = v.x * a.v[0].y + v.y * a.v[1].y + v.z * a.v[2].y; r.z = v.x * a.v[0].z + v.y * a.v[1].z + v.z * a.v[2].z; @@ -266,46 +266,46 @@ slInline Vector3 MulVector3ByMatrix3(const Vector3& v, const Matrix3& a) //---------------------------------------------------------------------------------------- -// Matrix4 +// Mat4 //---------------------------------------------------------------------------------------- -void SetMatrix4(Matrix4& r, const Matrix4& a); -void SetMatrix4(Matrix4& r, const Matrix3& a); -void SetMatrix4(Matrix4& r, const Matrix3& a, const Vector3& position); +void SetMat4(Mat4& r, const Mat4& a); +void SetMat4(Mat4& r, const Mat3& a); +void SetMat4(Mat4& r, const Mat3& a, const Vec3& position); -void ScaleMatrix4(Matrix4& r, const float s, const Matrix4& a); -Matrix4 ScaleMatrix4(const float s, const Matrix4& a); +void ScaleMat4(Mat4& r, const float s, const Mat4& a); +Mat4 ScaleMat4(const float s, const Mat4& a); -float DeterminantOfMatrix4(const Matrix4& a); +float DeterminantOfMat4(const Mat4& a); -void TransposeMatrix4(Matrix4& r, const Matrix4& a); -Matrix4 TransposeMatrix4(const Matrix4& a); +void TransposeMat4(Mat4& r, const Mat4& a); +Mat4 TransposeMat4(const Mat4& a); -void InvertAffineMatrix4(Matrix4& r, const Matrix4& a); -Matrix4 InvertAffineMatrix4(const Matrix4& a); +void InvertAffineMat4(Mat4& r, const Mat4& a); +Mat4 InvertAffineMat4(const Mat4& a); -void InvertGeneralMatrix4(Matrix4& r, const Matrix4& a); -Matrix4 InvertGeneralMatrix4(const Matrix4& a); +void InvertGeneralMat4(Mat4& r, const Mat4& a); +Mat4 InvertGeneralMat4(const Mat4& a); -void MulMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& b); -Matrix4 MulMatrix4(const Matrix4& a, const Matrix4& b); +void MulMat4(Mat4& r, const Mat4& a, const Mat4& b); +Mat4 MulMat4(const Mat4& a, const Mat4& b); -void MulMatrix4ByTransposedMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& t); -Matrix4 MulMatrix4ByTransposedMatrix4(const Matrix4& a, Matrix4& t); +void MulMat4ByTransposedMat4(Mat4& r, const Mat4& a, const Mat4& t); +Mat4 MulMat4ByTransposedMat4(const Mat4& a, Mat4& t); -void MulVector4ByMatrix4(Vector4& r, const Vector4& v, const Matrix4& a); -Vector4 MulVector4ByMatrix4(const Vector4& v, const Matrix4& a); +void MulVec4ByMat4(Vec4& r, const Vec4& v, const Mat4& a); +Vec4 MulVec4ByMat4(const Vec4& v, const Mat4& a); -void MulVector3ByMatrix4(Vector4& r, const Vector3& v, const float w, const Matrix4& a); -Vector4 MulVector3ByMatrix4(const Vector3& v, const float w, const Matrix4& a); +void MulVec3ByMat4(Vec4& r, const Vec3& v, const float w, const Mat4& a); +Vec4 MulVec3ByMat4(const Vec3& v, const float w, const Mat4& a); -void MulVector4ByTransposedMatrix4(Vector4& r, const Vector4& v, const Matrix4& t); -Vector4 MulVector4ByTransposedMatrix4(const Vector4& v, const Matrix4& t); +void MulVec4ByTransposedMat4(Vec4& r, const Vec4& v, const Mat4& t); +Vec4 MulVec4ByTransposedMat4(const Vec4& v, const Mat4& t); -void MulVector3ByTransposedMatrix4(Vector4& r, const Vector3& v, const float w, const Matrix4& t); -Vector4 MulVector3ByTransposedMatrix4(const Vector3& v, const float w, const Matrix4& t); +void MulVec3ByTransposedMat4(Vec4& r, const Vec3& v, const float w, const Mat4& t); +Vec4 MulVec3ByTransposedMat4(const Vec3& v, const float w, const Mat4& t); //---------------------------------------------------------------------------------------- -slInline void SetMatrix4(Matrix4& r, const Matrix4& a) +slInline void SetMat4(Mat4& r, const Mat4& a) { r.v[0] = a.v[0]; r.v[1] = a.v[1]; @@ -314,54 +314,54 @@ slInline void SetMatrix4(Matrix4& r, const Matrix4& a) } //---------------------------------------------------------------------------------------- -slInline void SetMatrix4(Matrix4& r, const Matrix3& a) +slInline void SetMat4(Mat4& r, const Mat3& a) { - SetVector4(r.v[0], a.v[0], 0.0f); - SetVector4(r.v[1], a.v[1], 0.0f); - SetVector4(r.v[2], a.v[2], 0.0f); - SetVector4(r.v[3], 0.0f, 0.0f, 0.0f, 1.0f); + SetVec4(r.v[0], a.v[0], 0.0f); + SetVec4(r.v[1], a.v[1], 0.0f); + SetVec4(r.v[2], a.v[2], 0.0f); + SetVec4(r.v[3], 0.0f, 0.0f, 0.0f, 1.0f); } //---------------------------------------------------------------------------------------- -slInline void SetMatrix4(Matrix4& r, const Matrix3& a, const Vector3& position) +slInline void SetMat4(Mat4& r, const Mat3& a, const Vec3& position) { - SetVector4(r.v[0], a.v[0], 0.0f); - SetVector4(r.v[1], a.v[1], 0.0f); - SetVector4(r.v[2], a.v[2], 0.0f); - SetVector4(r.v[3], position, 1.0f); + SetVec4(r.v[0], a.v[0], 0.0f); + SetVec4(r.v[1], a.v[1], 0.0f); + SetVec4(r.v[2], a.v[2], 0.0f); + SetVec4(r.v[3], position, 1.0f); } //---------------------------------------------------------------------------------------- -slInline void ScaleMatrix4(Matrix4& r, const float s, const Matrix4& a) +slInline void ScaleMat4(Mat4& r, const float s, const Mat4& a) { - ScaleVector4(r.v[0], s, a.v[0]); - ScaleVector4(r.v[1], s, a.v[1]); - ScaleVector4(r.v[2], s, a.v[2]); - ScaleVector4(r.v[3], s, a.v[3]); + ScaleVec4(r.v[0], s, a.v[0]); + ScaleVec4(r.v[1], s, a.v[1]); + ScaleVec4(r.v[2], s, a.v[2]); + ScaleVec4(r.v[3], s, a.v[3]); } //---------------------------------------------------------------------------------------- -slInline Matrix4 ScaleMatrix4(const float s, const Matrix4& a) +slInline Mat4 ScaleMat4(const float s, const Mat4& a) { - Matrix4 r; - ScaleVector4(r.v[0], s, a.v[0]); - ScaleVector4(r.v[1], s, a.v[1]); - ScaleVector4(r.v[2], s, a.v[2]); - ScaleVector4(r.v[3], s, a.v[3]); + Mat4 r; + ScaleVec4(r.v[0], s, a.v[0]); + ScaleVec4(r.v[1], s, a.v[1]); + ScaleVec4(r.v[2], s, a.v[2]); + ScaleVec4(r.v[3], s, a.v[3]); return r; } //---------------------------------------------------------------------------------------- -slInline float DeterminantOfMatrix4(const Matrix4& a) +slInline float DeterminantOfMat4(const Mat4& a) { // is this correct? - Vector4 cross_product; - CrossVector4(cross_product, a.v[1], a.v[2], a.v[3]); - return DotVector4(a.v[0], cross_product); + Vec4 cross_product; + CrossVec4(cross_product, a.v[1], a.v[2], a.v[3]); + return DotVec4(a.v[0], cross_product); } //---------------------------------------------------------------------------------------- -slInline void TransposeMatrix4(Matrix4& r, const Matrix4& a) +slInline void TransposeMat4(Mat4& r, const Mat4& a) { // a might be the same as r r.v[0].x = a.v[0].x; @@ -396,9 +396,9 @@ slInline void TransposeMatrix4(Matrix4& r, const Matrix4& a) } //---------------------------------------------------------------------------------------- -slInline Matrix4 TransposeMatrix4(const Matrix4& a) +slInline Mat4 TransposeMat4(const Mat4& a) { - Matrix4 r; + Mat4 r; r.v[0].x = a.v[0].x; r.v[0].y = a.v[1].x; r.v[0].z = a.v[2].x; r.v[0].w = a.v[3].x; r.v[1].x = a.v[0].y; r.v[1].y = a.v[1].y; r.v[1].z = a.v[2].y; r.v[1].w = a.v[3].y; r.v[2].x = a.v[0].z; r.v[2].y = a.v[1].z; r.v[2].z = a.v[2].z; r.v[2].w = a.v[3].z; @@ -407,254 +407,254 @@ slInline Matrix4 TransposeMatrix4(const Matrix4& a) } //---------------------------------------------------------------------------------------- -slInline void InvertAffineMatrix4(Matrix4& r, const Matrix4& a) +slInline void InvertAffineMat4(Mat4& r, const Mat4& a) { // this may not be correct... - Matrix3 a3_T(a.v[0].AsVector3(), a.v[1].AsVector3(), a.v[2].AsVector3()); - InvertAffineMatrix3(a3_T, a3_T); + Mat3 a3_T(a.v[0].AsVec3(), a.v[1].AsVec3(), a.v[2].AsVec3()); + InvertAffineMat3(a3_T, a3_T); - Vector3 transpose; - MulVector3ByMatrix3(transpose, a.v[3].AsVector3(), a3_T); + Vec3 transpose; + MulVec3ByMat3(transpose, a.v[3].AsVec3(), a3_T); - SetMatrix4(r, a3_T, transpose); + SetMat4(r, a3_T, transpose); } //---------------------------------------------------------------------------------------- -slInline Matrix4 InvertAffineMatrix4(const Matrix4& a) +slInline Mat4 InvertAffineMat4(const Mat4& a) { - Matrix4 r; + Mat4 r; // this may not be correct... - Matrix3 a3_T(a.v[0].AsVector3(), a.v[1].AsVector3(), a.v[2].AsVector3()); - InvertAffineMatrix3(a3_T, a3_T); + Mat3 a3_T(a.v[0].AsVec3(), a.v[1].AsVec3(), a.v[2].AsVec3()); + InvertAffineMat3(a3_T, a3_T); - Vector3 transpose; - MulVector3ByMatrix3(transpose, a.v[3].AsVector3(), a3_T); + Vec3 transpose; + MulVec3ByMat3(transpose, a.v[3].AsVec3(), a3_T); - SetMatrix4(r, a3_T, transpose); + SetMat4(r, a3_T, transpose); return r; } //---------------------------------------------------------------------------------------- -slInline void InvertGeneralMatrix4(Matrix4& r, const Matrix4& a) +slInline void InvertGeneralMat4(Mat4& r, const Mat4& a) { // does this work? - float inv_determinant = 1.0f / DeterminantOfMatrix4(a); + float inv_determinant = 1.0f / DeterminantOfMat4(a); - Matrix4 a_T; - TransposeMatrix4(a_T, a); - CrossVector4(r.v[0], a_T.v[1], a_T.v[2], a_T.v[3]); - CrossVector4(r.v[1], a_T.v[2], a_T.v[3], a_T.v[0]); - CrossVector4(r.v[2], a_T.v[3], a_T.v[0], a_T.v[1]); - CrossVector4(r.v[3], a_T.v[0], a_T.v[1], a_T.v[2]); + Mat4 a_T; + TransposeMat4(a_T, a); + CrossVec4(r.v[0], a_T.v[1], a_T.v[2], a_T.v[3]); + CrossVec4(r.v[1], a_T.v[2], a_T.v[3], a_T.v[0]); + CrossVec4(r.v[2], a_T.v[3], a_T.v[0], a_T.v[1]); + CrossVec4(r.v[3], a_T.v[0], a_T.v[1], a_T.v[2]); - ScaleMatrix4(r, inv_determinant, r); + ScaleMat4(r, inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline Matrix4 InvertGeneralMatrix4(const Matrix4& a) +slInline Mat4 InvertGeneralMat4(const Mat4& a) { // does this work? - Matrix4 r; - float inv_determinant = 1.0f / DeterminantOfMatrix4(a); + Mat4 r; + float inv_determinant = 1.0f / DeterminantOfMat4(a); - Matrix4 a_T; - TransposeMatrix4(a_T, a); - r.v[0] = CrossVector4(a_T.v[1], a_T.v[2], a_T.v[3]); - r.v[1] = CrossVector4(a_T.v[2], a_T.v[3], a_T.v[0]); - r.v[2] = CrossVector4(a_T.v[3], a_T.v[0], a_T.v[1]); - r.v[3] = CrossVector4(a_T.v[0], a_T.v[1], a_T.v[2]); + Mat4 a_T; + TransposeMat4(a_T, a); + r.v[0] = CrossVec4(a_T.v[1], a_T.v[2], a_T.v[3]); + r.v[1] = CrossVec4(a_T.v[2], a_T.v[3], a_T.v[0]); + r.v[2] = CrossVec4(a_T.v[3], a_T.v[0], a_T.v[1]); + r.v[3] = CrossVec4(a_T.v[0], a_T.v[1], a_T.v[2]); - return ScaleMatrix4(inv_determinant, r); + return ScaleMat4(inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline void MulMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& b) +slInline void MulMat4(Mat4& r, const Mat4& a, const Mat4& b) { - Matrix4 temp; + Mat4 temp; - temp.v[0].x = DotVector4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[0].y = DotVector4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[0].z = DotVector4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[0].w = DotVector4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[0].x = DotVec4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[0].y = DotVec4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[0].z = DotVec4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[0].w = DotVec4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - temp.v[1].x = DotVector4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[1].y = DotVector4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[1].z = DotVector4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[1].w = DotVector4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[1].x = DotVec4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[1].y = DotVec4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[1].z = DotVec4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[1].w = DotVec4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - temp.v[2].x = DotVector4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[2].y = DotVector4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[2].z = DotVector4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[2].w = DotVector4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[2].x = DotVec4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[2].y = DotVec4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[2].z = DotVec4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[2].w = DotVec4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - temp.v[3].x = DotVector4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[3].y = DotVector4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[3].z = DotVector4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[3].w = DotVector4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[3].x = DotVec4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[3].y = DotVec4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[3].z = DotVec4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[3].w = DotVec4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - SetMatrix4(r, temp); + SetMat4(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix4 MulMatrix4(const Matrix4& a, const Matrix4& b) +slInline Mat4 MulMat4(const Mat4& a, const Mat4& b) { - Matrix4 r; + Mat4 r; - r.v[0].x = DotVector4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[0].y = DotVector4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[0].z = DotVector4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[0].w = DotVector4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[0].x = DotVec4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[0].y = DotVec4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[0].z = DotVec4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[0].w = DotVec4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - r.v[1].x = DotVector4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[1].y = DotVector4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[1].z = DotVector4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[1].w = DotVector4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[1].x = DotVec4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[1].y = DotVec4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[1].z = DotVec4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[1].w = DotVec4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - r.v[2].x = DotVector4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[2].y = DotVector4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[2].z = DotVector4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[2].w = DotVector4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[2].x = DotVec4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[2].y = DotVec4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[2].z = DotVec4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[2].w = DotVec4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - r.v[3].x = DotVector4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[3].y = DotVector4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[3].z = DotVector4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[3].w = DotVector4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[3].x = DotVec4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[3].y = DotVec4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[3].z = DotVec4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[3].w = DotVec4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); return r; } //---------------------------------------------------------------------------------------- -slInline void MulMatrix4ByTransposedMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& t) +slInline void MulMat4ByTransposedMat4(Mat4& r, const Mat4& a, const Mat4& t) { - Matrix4 temp; + Mat4 temp; - temp.v[0].x = DotVector4(a.v[0], b.v[0]); - temp.v[0].y = DotVector4(a.v[0], b.v[1]); - temp.v[0].z = DotVector4(a.v[0], b.v[2]); - temp.v[0].w = DotVector4(a.v[0], b.v[3]); + temp.v[0].x = DotVec4(a.v[0], t.v[0]); + temp.v[0].y = DotVec4(a.v[0], t.v[1]); + temp.v[0].z = DotVec4(a.v[0], t.v[2]); + temp.v[0].w = DotVec4(a.v[0], t.v[3]); - temp.v[1].x = DotVector4(a.v[1], b.v[0]); - temp.v[1].y = DotVector4(a.v[1], b.v[1]); - temp.v[1].z = DotVector4(a.v[1], b.v[2]); - temp.v[1].w = DotVector4(a.v[1], b.v[3]); + temp.v[1].x = DotVec4(a.v[1], t.v[0]); + temp.v[1].y = DotVec4(a.v[1], t.v[1]); + temp.v[1].z = DotVec4(a.v[1], t.v[2]); + temp.v[1].w = DotVec4(a.v[1], t.v[3]); - temp.v[2].x = DotVector4(a.v[2], b.v[0]); - temp.v[2].y = DotVector4(a.v[2], b.v[1]); - temp.v[2].z = DotVector4(a.v[2], b.v[2]); - temp.v[2].w = DotVector4(a.v[2], b.v[3]); + temp.v[2].x = DotVec4(a.v[2], t.v[0]); + temp.v[2].y = DotVec4(a.v[2], t.v[1]); + temp.v[2].z = DotVec4(a.v[2], t.v[2]); + temp.v[2].w = DotVec4(a.v[2], t.v[3]); - temp.v[3].x = DotVector4(a.v[3], b.v[0]); - temp.v[3].y = DotVector4(a.v[3], b.v[1]); - temp.v[3].z = DotVector4(a.v[3], b.v[2]); - temp.v[3].w = DotVector4(a.v[3], b.v[3]); + temp.v[3].x = DotVec4(a.v[3], t.v[0]); + temp.v[3].y = DotVec4(a.v[3], t.v[1]); + temp.v[3].z = DotVec4(a.v[3], t.v[2]); + temp.v[3].w = DotVec4(a.v[3], t.v[3]); - SetMatrix4(r, temp); + SetMat4(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix4 MulMatrix4ByTransposedMatrix4(const Matrix4& a, const Matrix4& t) +slInline Mat4 MulMat4ByTransposedMat4(const Mat4& a, const Mat4& t) { - Matrix4 r; + Mat4 r; - r.v[0].x = DotVector4(a.v[0], b.v[0]); - r.v[0].y = DotVector4(a.v[0], b.v[1]); - r.v[0].z = DotVector4(a.v[0], b.v[2]); - r.v[0].w = DotVector4(a.v[0], b.v[3]); + r.v[0].x = DotVec4(a.v[0], t.v[0]); + r.v[0].y = DotVec4(a.v[0], t.v[1]); + r.v[0].z = DotVec4(a.v[0], t.v[2]); + r.v[0].w = DotVec4(a.v[0], t.v[3]); - r.v[1].x = DotVector4(a.v[1], b.v[0]); - r.v[1].y = DotVector4(a.v[1], b.v[1]); - r.v[1].z = DotVector4(a.v[1], b.v[2]); - r.v[1].w = DotVector4(a.v[1], b.v[3]); + r.v[1].x = DotVec4(a.v[1], t.v[0]); + r.v[1].y = DotVec4(a.v[1], t.v[1]); + r.v[1].z = DotVec4(a.v[1], t.v[2]); + r.v[1].w = DotVec4(a.v[1], t.v[3]); - r.v[2].x = DotVector4(a.v[2], b.v[0]); - r.v[2].y = DotVector4(a.v[2], b.v[1]); - r.v[2].z = DotVector4(a.v[2], b.v[2]); - r.v[2].w = DotVector4(a.v[2], b.v[3]); + r.v[2].x = DotVec4(a.v[2], t.v[0]); + r.v[2].y = DotVec4(a.v[2], t.v[1]); + r.v[2].z = DotVec4(a.v[2], t.v[2]); + r.v[2].w = DotVec4(a.v[2], t.v[3]); - r.v[3].x = DotVector4(a.v[3], b.v[0]); - r.v[3].y = DotVector4(a.v[3], b.v[1]); - r.v[3].z = DotVector4(a.v[3], b.v[2]); - r.v[3].w = DotVector4(a.v[3], b.v[3]); + r.v[3].x = DotVec4(a.v[3], t.v[0]); + r.v[3].y = DotVec4(a.v[3], t.v[1]); + r.v[3].z = DotVec4(a.v[3], t.v[2]); + r.v[3].w = DotVec4(a.v[3], t.v[3]); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector4ByMatrix4(Vector4& r, const Vector4& v, const Matrix4& a) +slInline void MulVec4ByMat4(Vec4& r, const Vec4& v, const Mat4& a) { - Vector4 result; - ScaleVector4(result, v.x, a.v[0]); - ScaleAddVector4(result, v.y, a.v[1], result); - ScaleAddVector4(result, v.z, a.v[2], result); - ScaleAddVector4(result, v.w, a.v[3], result); - SetVector4(r, result); + Vec4 result; + ScaleVec4(result, v.x, a.v[0]); + ScaleAddVec4(result, v.y, a.v[1], result); + ScaleAddVec4(result, v.z, a.v[2], result); + ScaleAddVec4(result, v.w, a.v[3], result); + SetVec4(r, result); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector4ByMatrix4(const Vector4& v, const Matrix4& a) +slInline Vec4 MulVec4ByMat4(const Vec4& v, const Mat4& a) { - Vector4 r; - ScaleVector4(r, v.x, a.v[0]); - ScaleAddVector4(r, v.y, a.v[1], r); - ScaleAddVector4(r, v.z, a.v[2], r); - ScaleAddVector4(r, v.w, a.v[3], r); + Vec4 r; + ScaleVec4(r, v.x, a.v[0]); + ScaleAddVec4(r, v.y, a.v[1], r); + ScaleAddVec4(r, v.z, a.v[2], r); + ScaleAddVec4(r, v.w, a.v[3], r); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector3ByMatrix4(Vector4& r, const Vector3& v, const float iw, const Matrix4& a) +slInline void MulVec3ByMat4(Vec4& r, const Vec3& v, const float iw, const Mat4& a) { - Vector4 result; - ScaleVector4(result, v.x, a.v[0]); - ScaleAddVector4(result, v.y, a.v[1], result); - ScaleAddVector4(result, v.z, a.v[2], result); - ScaleAddVector4(result, iw, a.v[3], result); - SetVector4(r, result); + Vec4 result; + ScaleVec4(result, v.x, a.v[0]); + ScaleAddVec4(result, v.y, a.v[1], result); + ScaleAddVec4(result, v.z, a.v[2], result); + ScaleAddVec4(result, iw, a.v[3], result); + SetVec4(r, result); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector3ByMatrix4(const Vector3& v, const float iw, const Matrix4& a) +slInline Vec4 MulVec3ByMat4(const Vec3& v, const float iw, const Mat4& a) { - Vector4 r; - ScaleVector4(r, v.x, a.v[0]); - ScaleAddVector4(r, v.y, a.v[1], r); - ScaleAddVector4(r, v.z, a.v[2], r); - ScaleAddVector4(r, iw, a.v[3], r); + Vec4 r; + ScaleVec4(r, v.x, a.v[0]); + ScaleAddVec4(r, v.y, a.v[1], r); + ScaleAddVec4(r, v.z, a.v[2], r); + ScaleAddVec4(r, iw, a.v[3], r); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector4ByTransposedMatrix4(Vector4& r, const Vector4& v, const Matrix4& t) +slInline void MulVec4ByTransposedMat4(Vec4& r, const Vec4& v, const Mat4& t) { - float x = DotVector4(v, t.v[0]); - float y = DotVector4(v, t.v[1]); - float z = DotVector4(v, t.v[2]); - float w = DotVector4(v, t.v[3]); - SetVector4(r, x, y, z, w); + float x = DotVec4(v, t.v[0]); + float y = DotVec4(v, t.v[1]); + float z = DotVec4(v, t.v[2]); + float w = DotVec4(v, t.v[3]); + SetVec4(r, x, y, z, w); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector4ByTransposedMatrix4(const Vector4& v, const Matrix4& t) +slInline Vec4 MulVec4ByTransposedMat4(const Vec4& v, const Mat4& t) { - Vector4 r; - r.x = DotVector4(v, t.v[0]); - r.y = DotVector4(v, t.v[1]); - r.z = DotVector4(v, t.v[2]); - r.w = DotVector4(v, t.v[3]); + Vec4 r; + r.x = DotVec4(v, t.v[0]); + r.y = DotVec4(v, t.v[1]); + r.z = DotVec4(v, t.v[2]); + r.w = DotVec4(v, t.v[3]); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector3ByTransposedMatrix4(Vector4& r, const Vector3& v, const float w, const Matrix4& t) +slInline void MulVec3ByTransposedMat4(Vec4& r, const Vec3& v, const float w, const Mat4& t) { - Vector4 v_new(v, w); - MulVector4ByTransposedMatrix4(r, v_new, a); + Vec4 v_new(v, w); + MulVec4ByTransposedMat4(r, v_new, t); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector3ByTransposedMatrix4(const Vector3& v, const float w, const Matrix4& t) +slInline Vec4 MulVec3ByTransposedMat4(const Vec3& v, const float w, const Mat4& t) { - Vector4 v_as_v4(v, w); - return MulVector4ByTransposedMatrix4(v_as_v4, t); + Vec4 v_as_v4(v, w); + return MulVec4ByTransposedMat4(v_as_v4, t); } diff --git a/Classes/Foundation/Math/Quaternion.h b/Classes/Foundation/Math/Quaternion.h index 8a303db..d9cce5d 100755 --- a/Classes/Foundation/Math/Quaternion.h +++ b/Classes/Foundation/Math/Quaternion.h @@ -1,14 +1,14 @@ #pragma once #include "Foundation/Common/GlobalInclude.h" -#include "Foundation/Common/MathTypes.h" +#include "Foundation/Math/MathTypes.h" #include "Foundation/Math/Vector.h" //---------------------------------------------------------------------------------------- // Quaternion //---------------------------------------------------------------------------------------- void SetQuaternion(Quaternion& r, const float angle, const float x, const float y, const float z); -void SetQuaternion(Quaternion& r, const float angle, const Vector3& rotation_axis); +void SetQuaternion(Quaternion& r, const float angle, const Vec3& rotation_axis); void ScaleQuaternion(Quaternion& r, const float s, const Quaternion& q); void MulQuaternion(Quaternion& r, const Quaternion& p, const Quaternion& q); void ConjugateOfQuaternion(Quaternion& r, const Quaternion& q); @@ -20,29 +20,29 @@ void InverseQuaterion(Quaternion& r, const Quaternion& q); //---------------------------------------------------------------------------------------- void SetQuaternion(Quaternion& r, const float angle, const float x, const float y, const float z) { - Assert( EpsilonEquals(LengthVector3(rotation_axis), 0.0f, kEpsilon) ); + Assert( EpsilonEquals(x*x + y*y + z*z, 0.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); r.i = x * sin_half_angle; r.j = y * sin_half_angle; r.k = z * sin_half_angle; - r.s = Cosf(half_angle); + r.s = (float)Cosf(half_angle); } //---------------------------------------------------------------------------------------- -void SetQuaternion(Quaternion& r, const float angle, const Vector3& rotation_axis) +void SetQuaternion(Quaternion& r, const float angle, const Vec3& rotation_axis) { - Assert( EpsilonEquals(LengthVector3(rotation_axis), 0.0f, kEpsilon) ); + Assert( EpsilonEquals(rotation_axis.x * rotation_axis.x + rotation_axis.y * rotation_axis.y + rotation_axis.z * rotation_axis.z, 0.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); r.i = rotation_axis.x * sin_half_angle; r.j = rotation_axis.y * sin_half_angle; r.k = rotation_axis.z * sin_half_angle; - r.s = Cosf(half_angle); + r.s = (float)Cosf(half_angle); } //---------------------------------------------------------------------------------------- @@ -75,7 +75,7 @@ void ConjugateOfQuaternion(Quaternion& r, const Quaternion& q) //---------------------------------------------------------------------------------------- float NormOfQuaternion(const Quaternion& q) { - return Sqrtf( q.i * q.i + q.j * q.j + q.k * q.k + q.s * q.s); + return (float)Sqrtf( q.i * q.i + q.j * q.j + q.k * q.k + q.s * q.s); } //---------------------------------------------------------------------------------------- @@ -87,7 +87,7 @@ float NormSquaredOfQuaternion(const Quaternion& q) //---------------------------------------------------------------------------------------- void NormalizeQuaternion(Quaternion& r, Quaternion& q) { - float norm_scale = 1.0f / NormQuaternion( q ); + float norm_scale = 1.0f / NormOfQuaternion( q ); ScaleQuaternion( r, norm_scale, q ); } diff --git a/Classes/Foundation/Math/Vector.h b/Classes/Foundation/Math/Vector.h index 3e5e524..91cc817 100755 --- a/Classes/Foundation/Math/Vector.h +++ b/Classes/Foundation/Math/Vector.h @@ -5,407 +5,407 @@ #include "Foundation/Math/MathOperations.h" //---------------------------------------------------------------------------------------- -// Vector2 +// Vec2 //---------------------------------------------------------------------------------------- -void SetVector2(Vector2& r, const Vector2& v); -void SetVector2(Vector2& r, const float x, const float y); -void SetVector2(Vector2& r, const float xy); -void AbsVector2(Vector2& r, const Vector2& v); -float MinComponentVector2(const Vector2& v); -float MaxComponentVector2(const Vector2& v); -uint32_t MinIndexVector2(const Vector2& v); -uint32_t MaxIndexVector2(const Vector2& v); -float DotVector2(const Vector2& a, const Vector2& b); -float DotVector2(const Vector2& a, const float x, const float y); +void SetVec2(Vec2& r, const Vec2& v); +void SetVec2(Vec2& r, const float x, const float y); +void SetVec2(Vec2& r, const float xy); +void AbsVec2(Vec2& r, const Vec2& v); +float MinComponentVec2(const Vec2& v); +float MaxComponentVec2(const Vec2& v); +uint32_t MinIndexVec2(const Vec2& v); +uint32_t MaxIndexVec2(const Vec2& v); +float DotVec2(const Vec2& a, const Vec2& b); +float DotVec2(const Vec2& a, const float x, const float y); -void PerpendicularVector2(Vector2& r, const Vector2& v); -Vector2 PerpendicularVector2(const Vector2& v); +void PerpendicularVec2(Vec2& r, const Vec2& v); +Vec2 PerpendicularVec2(const Vec2& v); -void AddVector2ByScalar(Vector2& r, const float s, const Vector2& v); -Vector2 AddVector2ByScalar(const float s, const Vector2& v); +void AddVec2ByScalar(Vec2& r, const float s, const Vec2& v); +Vec2 AddVec2ByScalar(const float s, const Vec2& v); -void AddVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 AddVector2(const Vector2& a, const Vector2& b); +void AddVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 AddVec2(const Vec2& a, const Vec2& b); -void AddVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 AddVector2(const Vector2& a, const float x, const float y); +void AddVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 AddVec2(const Vec2& a, const float x, const float y); -void SubVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 SubVector2(const Vector2& a, const Vector2& b); +void SubVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 SubVec2(const Vec2& a, const Vec2& b); -void SubVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 SubVector2(const Vector2& a, const float x, const float y); +void SubVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 SubVec2(const Vec2& a, const float x, const float y); -void ScaleVector2(Vector2& r, const float s, const Vector2& v); -Vector2 ScaleVector2(const float s, const Vector2& v); +void ScaleVec2(Vec2& r, const float s, const Vec2& v); +Vec2 ScaleVec2(const float s, const Vec2& v); -void MulVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 MulVector2(const Vector2& a, const Vector2& b); +void MulVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 MulVec2(const Vec2& a, const Vec2& b); -void MulVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 MulVector2(const Vector2& a, const float x, const float y); +void MulVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 MulVec2(const Vec2& a, const float x, const float y); -void DivVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 DivVector2(const Vector2& a, const Vector2& b); +void DivVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 DivVec2(const Vec2& a, const Vec2& b); -void DivVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 DivVector2(const Vector2& a, const float x, const float y); +void DivVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 DivVec2(const Vec2& a, const float x, const float y); -void ScaleAddVector2(Vector2& r, const float s, const Vector2& v_scale, const Vector2& v_add); -Vector2 ScaleAddVector2(const float s, const Vector2& v_scale, const Vector2& v_add); +void ScaleAddVec2(Vec2& r, const float s, const Vec2& v_scale, const Vec2& v_add); +Vec2 ScaleAddVec2(const float s, const Vec2& v_scale, const Vec2& v_add); -void NormalizeVector2(Vector2& r, const Vector2& a); -Vector2 NormalizeVector2(const Vector2& a); +void NormalizeVec2(Vec2& r, const Vec2& a); +Vec2 NormalizeVec2(const Vec2& a); -float LengthOfVector2(const Vector2& a); -float LengthSquaredOfVector2(const Vector2& a); +float LengthOfVec2(const Vec2& a); +float LengthSquaredOfVec2(const Vec2& a); //---------------------------------------------------------------------------------------- -slInline void SetVector2(Vector2& r, const Vector2& v) +slInline void SetVec2(Vec2& r, const Vec2& v) { r.x = v.x; r.y = v.y; } //---------------------------------------------------------------------------------------- -slInline void SetVector2(Vector2& r, const float x, const float y) +slInline void SetVec2(Vec2& r, const float x, const float y) { r.x = x; r.y = y; } //---------------------------------------------------------------------------------------- -slInline void SetVector2(Vector2& r, const float xy) +slInline void SetVec2(Vec2& r, const float xy) { r.x = xy; r.y = xy; } //---------------------------------------------------------------------------------------- -void AbsVector2(Vector2& r, const Vector2& v) +void AbsVec2(Vec2& r, const Vec2& v) { r.x = Absf(v.x); r.y = Absf(v.y); } //---------------------------------------------------------------------------------------- -float MinComponentVector2(const Vector2& v) +float MinComponentVec2(const Vec2& v) { return v.x <= v.y ? v.x : v.y; } //---------------------------------------------------------------------------------------- -float MaxComponentVector2(const Vector2& v) +float MaxComponentVec2(const Vec2& v) { return v.x >= v.y ? v.x : v.y; } //---------------------------------------------------------------------------------------- -uint32_t MinIndexVector2(const Vector2& v) +uint32_t MinIndexVec2(const Vec2& v) { return v.x <= v.y ? 0 : 1; } //---------------------------------------------------------------------------------------- -uint32_t MaxIndexVector2(const Vector2& v) +uint32_t MaxIndexVec2(const Vec2& v) { return v.x >= v.y ? 0 : 1; } //---------------------------------------------------------------------------------------- -slInline float DotVector2(const Vector2& a, const Vector2& b) +slInline float DotVec2(const Vec2& a, const Vec2& b) { return a.x * b.x + a.y * b.y; } //---------------------------------------------------------------------------------------- -slInline float DotVector2(const Vector2& a, const float x, const float y) +slInline float DotVec2(const Vec2& a, const float x, const float y) { return a.x * x + a.y * y; } //---------------------------------------------------------------------------------------- -slInline void PerpendicularVector2(Vector2& r, const Vector2& v) +slInline void PerpendicularVec2(Vec2& r, const Vec2& v) { r.x = -v.y; r.y = v.x; } //---------------------------------------------------------------------------------------- -slInline Vector2 PerpendicularVector2(const Vector2& v) +slInline Vec2 PerpendicularVec2(const Vec2& v) { - Vector2 r; + Vec2 r; r.x = -v.y; r.y = v.x; return r; } //---------------------------------------------------------------------------------------- -slInline void AddVector2ByScalar(Vector2& r, const float s, Vector2& v) +slInline void AddVec2ByScalar(Vec2& r, const float s, Vec2& v) { r.x = s + v.x; r.y = s + v.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 AddVector2ByScalar(const float s, const Vector2& v) +slInline Vec2 AddVec2ByScalar(const float s, const Vec2& v) { - Vector2 r; + Vec2 r; r.x = s + v.x; r.y = s + v.y; return r; } //---------------------------------------------------------------------------------------- -slInline void AddVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void AddVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x + b.x; r.y = a.y + b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 AddVector2(const Vector2& a, const Vector2& b) +slInline Vec2 AddVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x + b.x; r.y = a.y + b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void AddVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void AddVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x + x; r.y = a.y + y; } //---------------------------------------------------------------------------------------- -slInline Vector2 AddVector2(const Vector2& a, const float x, const float y) +slInline Vec2 AddVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x + x; r.y = a.y + y; return r; } //---------------------------------------------------------------------------------------- -slInline void SubVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void SubVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x - b.x; r.y = a.y - b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 SubVector2(const Vector2& a, const Vector2& b) +slInline Vec2 SubVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x - b.x; r.y = a.y - b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void SubVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void SubVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x - x; r.y = a.y - y; } //---------------------------------------------------------------------------------------- -slInline Vector2 SubVector2(const Vector2& a, const float x, const float y) +slInline Vec2 SubVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x - x; r.y = a.y - y; return r; } //---------------------------------------------------------------------------------------- -slInline void ScaleVector2(Vector2& r, const float s, const Vector2& v) +slInline void ScaleVec2(Vec2& r, const float s, const Vec2& v) { r.x = s * v.x; r.y = s * v.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 ScaleVector2(const float s, const Vector2& v) +slInline Vec2 ScaleVec2(const float s, const Vec2& v) { - Vector2 r; + Vec2 r; r.x = s * v.x; r.y = s * v.y; return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void MulVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x * b.x; r.y = a.y * b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 MulVector2(const Vector2& a, const Vector2& b) +slInline Vec2 MulVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x * b.x; r.y = a.y * b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void MulVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x * x; r.y = a.y * y; } //---------------------------------------------------------------------------------------- -slInline Vector2 MulVector2(const Vector2& a, const float x, const float y) +slInline Vec2 MulVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x * x; r.y = a.y * y; return r; } //---------------------------------------------------------------------------------------- -slInline void DivVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void DivVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x / b.x; r.y = a.y / b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 DivVector2(const Vector2& a, const Vector2& b) +slInline Vec2 DivVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x / b.x; r.y = a.y / b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void DivVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void DivVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x / x; r.y = a.y / y; } //---------------------------------------------------------------------------------------- -slInline Vector2 DivVector2(const Vector2& a, const float x, const float y) +slInline Vec2 DivVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x / x; r.y = a.y / y; return r; } //---------------------------------------------------------------------------------------- -slInline void ScaleAddVector2(Vector2& r, const float s, const Vector2& v_scale, const Vector2& v_add) +slInline void ScaleAddVec2(Vec2& r, const float s, const Vec2& v_scale, const Vec2& v_add) { r.x = v_scale.x * s + v_add.x; r.y = v_scale.y * s + v_add.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 ScaleAddVector2(const float s, const Vector2& v_scale, const Vector2& v_add) +slInline Vec2 ScaleAddVec2(const float s, const Vec2& v_scale, const Vec2& v_add) { - Vector2 r; + Vec2 r; r.x = v_scale.x * s + v_add.x; r.y = v_scale.y * s + v_add.y; return r; } //---------------------------------------------------------------------------------------- -slInline void NormalizeVector2(Vector2& r, const Vector2& a) +slInline void NormalizeVec2(Vec2& r, const Vec2& a) { - float scale = 1.0f / LengthOfVector2(a); - ScaleVector2( r, scale, a ); + float scale = 1.0f / LengthOfVec2(a); + ScaleVec2( r, scale, a ); } //---------------------------------------------------------------------------------------- -slInline Vector2 NormalizeVector2(const Vector2& a) +slInline Vec2 NormalizeVec2(const Vec2& a) { - float scale = 1.0f / LengthOfVector2(a); - return ScaleVector2( scale, a ); + float scale = 1.0f / LengthOfVec2(a); + return ScaleVec2( scale, a ); } //---------------------------------------------------------------------------------------- -slInline float LengthOfVector2(const Vector2& a) +slInline float LengthOfVec2(const Vec2& a) { - return Sqrtf( DotVector2(a, a) ); + return (float)Sqrtf( DotVec2(a, a) ); } //---------------------------------------------------------------------------------------- -slInline float LengthSquaredOfVector2(const Vector2& a) +slInline float LengthSquaredOfVec2(const Vec2& a) { - return DotVector2(a, a); + return DotVec2(a, a); } //---------------------------------------------------------------------------------------- -// Vector3 +// Vec3 //---------------------------------------------------------------------------------------- -void SetVector3(Vector3& r, const Vector3& v); -void SetVector3(Vector3& r, const Vector2& v, const float z); -void SetVector3(Vector3& r, const float xyz); -void SetVector3(Vector3& r, const float x, const float y, const float z); +void SetVec3(Vec3& r, const Vec3& v); +void SetVec3(Vec3& r, const Vec2& v, const float z); +void SetVec3(Vec3& r, const float xyz); +void SetVec3(Vec3& r, const float x, const float y, const float z); -void AbsVector3(Vector3& r, const Vector3& v); -Vector3 AbsVector3(const Vector3& v); +void AbsVec3(Vec3& r, const Vec3& v); +Vec3 AbsVec3(const Vec3& v); -float MinComponentVector3(const Vector3& v); -float MaxComponentVector3(const Vector3& v); -uint32_t MinIndexVector3(const Vector3& v); -uint32_t MaxIndexVector3(const Vector3& v); -float DotVector3(const Vector3& a, const Vector3& b); -float DotVector3(const Vector3& a, const float x, const float y, const float z); +float MinComponentVec3(const Vec3& v); +float MaxComponentVec3(const Vec3& v); +uint32_t MinIndexVec3(const Vec3& v); +uint32_t MaxIndexVec3(const Vec3& v); +float DotVec3(const Vec3& a, const Vec3& b); +float DotVec3(const Vec3& a, const float x, const float y, const float z); -void CrossVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 CrossVector3(const Vector3& a, const Vector3& b); +void CrossVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 CrossVec3(const Vec3& a, const Vec3& b); -void AddVector3ByScalar(Vector3& r, const float s, Vector3& v); -Vector3 AddVector3ByScalar(const float s, Vector3& v); +void AddVec3ByScalar(Vec3& r, const float s, Vec3& v); +Vec3 AddVec3ByScalar(const float s, Vec3& v); -void AddVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 AddVector3(const Vector3& a, const Vector3& b); +void AddVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 AddVec3(const Vec3& a, const Vec3& b); -void AddVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 AddVector3(const Vector3& a, const float x, const float y, const float z); +void AddVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 AddVec3(const Vec3& a, const float x, const float y, const float z); -void SubVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 SubVector3(const Vector3& a, const Vector3& b); +void SubVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 SubVec3(const Vec3& a, const Vec3& b); -void SubVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 SubVector3(const Vector3& a, const float x, const float y, const float z); +void SubVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 SubVec3(const Vec3& a, const float x, const float y, const float z); -void ScaleVector3(Vector3& r, const float s, const Vector3& v); -Vector3 ScaleVector3(const float s, const Vector3& v); +void ScaleVec3(Vec3& r, const float s, const Vec3& v); +Vec3 ScaleVec3(const float s, const Vec3& v); -void MulVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 MulVector3(const Vector3& a, const Vector3& b); +void MulVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 MulVec3(const Vec3& a, const Vec3& b); -void MulVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 MulVector3(const Vector3& a, const float x, const float y, const float z); +void MulVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 MulVec3(const Vec3& a, const float x, const float y, const float z); -void DivVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 DivVector3(const Vector3& a, const Vector3& b); +void DivVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 DivVec3(const Vec3& a, const Vec3& b); -void DivVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 DivVector3(const Vector3& a, const float x, const float y, const float z); +void DivVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 DivVec3(const Vec3& a, const float x, const float y, const float z); -void ScaleAddVector3(Vector3& r, const float s, const Vector3& v_scale, const Vector3& v_add); -Vector3 ScaleAddVector3(const float s, const Vector3& v_scale, const Vector3& v_add); +void ScaleAddVec3(Vec3& r, const float s, const Vec3& v_scale, const Vec3& v_add); +Vec3 ScaleAddVec3(const float s, const Vec3& v_scale, const Vec3& v_add); -void NormalizeVector3(Vector3& r, const Vector3& a); -Vector3 NormalizeVector3(const Vector3& a); +void NormalizeVec3(Vec3& r, const Vec3& a); +Vec3 NormalizeVec3(const Vec3& a); -float LengthVector3(const Vector3& a); -float LengthSquaredVector3(const Vector3& a); +float LengthOfVec3(const Vec3& a); +float LengthSquaredVec3(const Vec3& a); //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const Vector3& v) +slInline void SetVec3(Vec3& r, const Vec3& v) { r.x = v.x; r.y = v.y; @@ -413,7 +413,7 @@ slInline void SetVector3(Vector3& r, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const Vector2& v, const float z) +slInline void SetVec3(Vec3& r, const Vec2& v, const float z) { r.x = v.x; r.y = v.y; @@ -421,7 +421,7 @@ slInline void SetVector3(Vector3& r, const Vector2& v, const float z) } //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const float xyz) +slInline void SetVec3(Vec3& r, const float xyz) { r.x = xyz; r.y = xyz; @@ -429,7 +429,7 @@ slInline void SetVector3(Vector3& r, const float xyz) } //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const float x, const float y, const float z) +slInline void SetVec3(Vec3& r, const float x, const float y, const float z) { r.x = x; r.y = y; @@ -437,7 +437,7 @@ slInline void SetVector3(Vector3& r, const float x, const float y, const float z } //---------------------------------------------------------------------------------------- -slInline void AbsVector3(Vector3& r, const Vector3& v) +slInline void AbsVec3(Vec3& r, const Vec3& v) { r.x = Absf(v.x); r.y = Absf(v.y); @@ -445,9 +445,9 @@ slInline void AbsVector3(Vector3& r, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline Vector3 AbsVector3(const Vector3& v) +slInline Vec3 AbsVec3(const Vec3& v) { - Vector3 r; + Vec3 r; r.x = Absf(v.x); r.y = Absf(v.y); r.z = Absf(v.z); @@ -455,21 +455,21 @@ slInline Vector3 AbsVector3(const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline float MinComponentVector3(const Vector3& v) +slInline float MinComponentVec3(const Vec3& v) { float xy = v.x <= v.y ? v.x : v.y; return xy <= v.z ? xy : v.z; } //---------------------------------------------------------------------------------------- -slInline float MaxComponentVector3(const Vector3& v) +slInline float MaxComponentVec3(const Vec3& v) { float xy = v.x >= v.y ? v.x : v.y; return xy >= v.z ? xy : v.z; } //---------------------------------------------------------------------------------------- -slInline uint32_t MinIndexVector3(const Vector3& v) +slInline uint32_t MinIndexVec3(const Vec3& v) { const float* v_array = &v.x; uint32_t xy = v.x <= v.y ? 0 : 1; @@ -477,7 +477,7 @@ slInline uint32_t MinIndexVector3(const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline uint32_t MaxIndexVector3(const Vector3& v) +slInline uint32_t MaxIndexVec3(const Vec3& v) { const float* v_array = &v.x; uint32_t xy = v.x >= v.y ? 0 : 1; @@ -485,19 +485,19 @@ slInline uint32_t MaxIndexVector3(const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline float DotVector3(const Vector3& a, const Vector3& b) +slInline float DotVec3(const Vec3& a, const Vec3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; } //---------------------------------------------------------------------------------------- -slInline float DotVector3(const Vector3& a, const float x, const float y, const float z) +slInline float DotVec3(const Vec3& a, const float x, const float y, const float z) { return a.x * x + a.y * y + a.z * z; } //---------------------------------------------------------------------------------------- -slInline void CrossVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void CrossVec3(Vec3& r, const Vec3& a, const Vec3& b) { float x = a.y * b.z - b.y * a.z; float y = a.z * b.x - b.z * a.x; @@ -508,9 +508,9 @@ slInline void CrossVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 CrossVector3(const Vector3& a, const Vector3& b) +slInline Vec3 CrossVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.y * b.z - b.y * a.z; r.y = a.z * b.x - b.z * a.x; r.z = a.x * b.y - b.x * a.y; @@ -518,7 +518,7 @@ slInline Vector3 CrossVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void AddVector3ByScalar(Vector3& r, const float s, Vector3& v) +slInline void AddVec3ByScalar(Vec3& r, const float s, Vec3& v) { r.x = s + v.x; r.y = s + v.y; @@ -526,9 +526,9 @@ slInline void AddVector3ByScalar(Vector3& r, const float s, Vector3& v) } //---------------------------------------------------------------------------------------- -slInline Vector3 AddVector3ByScalar(const float s, Vector3& v) +slInline Vec3 AddVec3ByScalar(const float s, Vec3& v) { - Vector3 r; + Vec3 r; r.x = s + v.x; r.y = s + v.y; r.z = s + v.z; @@ -536,7 +536,7 @@ slInline Vector3 AddVector3ByScalar(const float s, Vector3& v) } //---------------------------------------------------------------------------------------- -slInline void AddVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void AddVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x + b.x; r.y = a.y + b.y; @@ -544,9 +544,9 @@ slInline void AddVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 AddVector3(const Vector3& a, const Vector3& b) +slInline Vec3 AddVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x + b.x; r.y = a.y + b.y; r.z = a.z + b.z; @@ -554,7 +554,7 @@ slInline Vector3 AddVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void AddVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z) +slInline void AddVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z) { r.x = a.x + x; r.y = a.y + y; @@ -562,9 +562,9 @@ slInline void AddVector3(Vector3& r, const Vector3& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector3 AddVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 AddVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x + x; r.y = a.y + y; r.z = a.z + z; @@ -572,7 +572,7 @@ slInline Vector3 AddVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void SubVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void SubVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x - b.x; r.y = a.y - b.y; @@ -580,9 +580,9 @@ slInline void SubVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 SubVector3(const Vector3& a, const Vector3& b) +slInline Vec3 SubVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x - b.x; r.y = a.y - b.y; r.z = a.z - b.z; @@ -590,9 +590,9 @@ slInline Vector3 SubVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 SubVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 SubVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x - x; r.y = a.y - y; r.z = a.z - z; @@ -600,7 +600,7 @@ slInline Vector3 SubVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void ScaleVector3(Vector3& r, const float s, const Vector3& v) +slInline void ScaleVec3(Vec3& r, const float s, const Vec3& v) { r.x = s * v.x; r.y = s * v.y; @@ -608,9 +608,9 @@ slInline void ScaleVector3(Vector3& r, const float s, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline Vector3 ScaleVector3(const float s, const Vector3& v) +slInline Vec3 ScaleVec3(const float s, const Vec3& v) { - Vector3 r; + Vec3 r; r.x = s * v.x; r.y = s * v.y; r.z = s * v.z; @@ -618,7 +618,7 @@ slInline Vector3 ScaleVector3(const float s, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline void MulVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void MulVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x * b.x; r.y = a.y * b.y; @@ -626,9 +626,9 @@ slInline void MulVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 MulVector3(const Vector3& a, const Vector3& b) +slInline Vec3 MulVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x * b.x; r.y = a.y * b.y; r.z = a.z * b.z; @@ -636,7 +636,7 @@ slInline Vector3 MulVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void MulVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z) +slInline void MulVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z) { r.x = a.x * x; r.y = a.y * y; @@ -644,9 +644,9 @@ slInline void MulVector3(Vector3& r, const Vector3& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector3 MulVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 MulVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x * x; r.y = a.y * y; r.z = a.z * z; @@ -654,7 +654,7 @@ slInline Vector3 MulVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void DivVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void DivVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x / b.x; r.y = a.y / b.y; @@ -662,9 +662,9 @@ slInline void DivVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 DivVector3(const Vector3& a, const Vector3& b) +slInline Vec3 DivVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x / b.x; r.y = a.y / b.y; r.z = a.z / b.z; @@ -672,7 +672,7 @@ slInline Vector3 DivVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void DivVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z) +slInline void DivVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z) { r.x = a.x / x; r.y = a.y / y; @@ -680,9 +680,9 @@ slInline void DivVector3(Vector3& r, const Vector3& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector3 DivVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 DivVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x / x; r.y = a.y / y; r.z = a.z / z; @@ -690,7 +690,7 @@ slInline Vector3 DivVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void ScaleAddVector3(Vector3& r, const float s, const Vector3& v_scale, const Vector3& v_add) +slInline void ScaleAddVec3(Vec3& r, const float s, const Vec3& v_scale, const Vec3& v_add) { r.x = s * v_scale.x + v_add.x; r.y = s * v_scale.y + v_add.y; @@ -698,9 +698,9 @@ slInline void ScaleAddVector3(Vector3& r, const float s, const Vector3& v_scale, } //---------------------------------------------------------------------------------------- -slInline Vector3 ScaleAddVector3(const float s, const Vector3& v_scale, const Vector3& v_add) +slInline Vec3 ScaleAddVec3(const float s, const Vec3& v_scale, const Vec3& v_add) { - Vector3 r; + Vec3 r; r.x = s * v_scale.x + v_add.x; r.y = s * v_scale.y + v_add.y; r.z = s * v_scale.z + v_add.z; @@ -708,96 +708,96 @@ slInline Vector3 ScaleAddVector3(const float s, const Vector3& v_scale, const Ve } //---------------------------------------------------------------------------------------- -slInline void NormalizeVector3(Vector3& r, const Vector3& a) +slInline void NormalizeVec3(Vec3& r, const Vec3& a) { - float scale = 1.0f / LengthOfVector3( a ); - ScaleVector3( r, scale, a ); + float scale = 1.0f / LengthOfVec3( a ); + ScaleVec3( r, scale, a ); } //---------------------------------------------------------------------------------------- -slInline Vector3 NormalizeVector3(const Vector3& a) +slInline Vec3 NormalizeVec3(const Vec3& a) { - float scale = 1.0f / LengthOfVector3( a ); - return ScaleVector3( scale, a ); + float scale = 1.0f / LengthOfVec3( a ); + return ScaleVec3( scale, a ); } //---------------------------------------------------------------------------------------- -slInline float LengthOfVector3(const Vector3& a) +slInline float LengthOfVec3(const Vec3& a) { - return Sqrtf( DotVector3(a, a) ); + return (float)Sqrtf( DotVec3(a, a) ); } //---------------------------------------------------------------------------------------- -slInline float LengthSquaredOfVector3(const Vector3& a) +slInline float LengthSquaredOfVec3(const Vec3& a) { - return DotVector3( a, a ); + return DotVec3( a, a ); } //---------------------------------------------------------------------------------------- -// Vector4 +// Vec4 //---------------------------------------------------------------------------------------- -void SetVector4(Vector4& r, const Vector4& v); -void SetVector4(Vector4& r, const Vector2& a, const Vector2& b); -void SetVector4(Vector4& r, const Vector3& v, const float w); -void SetVector4(Vector4& r, const float xyzw); -void SetVector4(Vector4& r, const float x, const float y, const float z, const float w); +void SetVec4(Vec4& r, const Vec4& v); +void SetVec4(Vec4& r, const Vec2& a, const Vec2& b); +void SetVec4(Vec4& r, const Vec3& v, const float w); +void SetVec4(Vec4& r, const float xyzw); +void SetVec4(Vec4& r, const float x, const float y, const float z, const float w); -void AbsVector4(Vector4& r, const Vector4& v); -Vector4 AbsVector4(const Vector4& v); +void AbsVec4(Vec4& r, const Vec4& v); +Vec4 AbsVec4(const Vec4& v); -float MinComponentVector4(const Vector4& v); -float MaxComponentVector4(const Vector4& v); -uint32_t MinIndexVector4(const Vector4& v); -uint32_t MaxIndexVector4(const Vector4& v); -float DotVector4(const Vector4& a, const Vector4& b); -float DotVector4(const Vector4& a, const float x, const float y, const float z, const float w); +float MinComponentVec4(const Vec4& v); +float MaxComponentVec4(const Vec4& v); +uint32_t MinIndexVec4(const Vec4& v); +uint32_t MaxIndexVec4(const Vec4& v); +float DotVec4(const Vec4& a, const Vec4& b); +float DotVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void CrossVector4(Vector4& r, const Vector4& a, const Vector4& b, const Vector4& c); -Vector4 CrossVector4(const Vector4& a, const Vector4& b, const Vector4& c); +void CrossVec4(Vec4& r, const Vec4& a, const Vec4& b, const Vec4& c); +Vec4 CrossVec4(const Vec4& a, const Vec4& b, const Vec4& c); -void AddVector4ByScalar(Vector4& r, const float s, Vector4& v); -Vector4 AddVector4ByScalar(const float s, Vector4& v); +void AddVec4ByScalar(Vec4& r, const float s, Vec4& v); +Vec4 AddVec4ByScalar(const float s, Vec4& v); -void AddVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 AddVector4(const Vector4& a, const Vector4& b); +void AddVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 AddVec4(const Vec4& a, const Vec4& b); -void AddVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 AddVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void AddVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 AddVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void SubVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 SubVector4(const Vector4& a, const Vector4& b); +void SubVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 SubVec4(const Vec4& a, const Vec4& b); -void SubVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 SubVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void SubVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 SubVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void ScaleVector4(Vector4& r, const float s, const Vector4& v); -Vector4 ScaleVector4(const float s, const Vector4& v); +void ScaleVec4(Vec4& r, const float s, const Vec4& v); +Vec4 ScaleVec4(const float s, const Vec4& v); -void MulVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 MulVector4(const Vector4& a, const Vector4& b); +void MulVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 MulVec4(const Vec4& a, const Vec4& b); -void MulVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 MulVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void MulVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 MulVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void DivVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 DivVector4(const Vector4& a, const Vector4& b); +void DivVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 DivVec4(const Vec4& a, const Vec4& b); -void DivVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 DivVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void DivVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 DivVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void ScaleAddVector4(Vector4& r, const float s, const Vector4& v_scale, const Vector4& v_add); -Vector4 ScaleAddVector4(const float s, const Vector4& v_scale, const Vector4& v_add); +void ScaleAddVec4(Vec4& r, const float s, const Vec4& v_scale, const Vec4& v_add); +Vec4 ScaleAddVec4(const float s, const Vec4& v_scale, const Vec4& v_add); -void NormalizeVector4(Vector4& r, const Vector4& a); -Vector4 NormalizeVector4(const Vector4& a); +void NormalizeVec4(Vec4& r, const Vec4& a); +Vec4 NormalizeVec4(const Vec4& a); -float LengthVector4(const Vector4& a); -float LengthSquaredVector4(const Vector4& a); +float LengthOfVec4(const Vec4& a); +float LengthSquaredVec4(const Vec4& a); //---------------------------------------------------------------------------------------- -slInline void SetVector4(Vector4& r, const Vector4& v) +slInline void SetVec4(Vec4& r, const Vec4& v) { r.x = v.x; r.y = v.y; @@ -806,7 +806,7 @@ slInline void SetVector4(Vector4& r, const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline void SetVector4(Vector4& r, const Vector2& a, const Vector2& b) +slInline void SetVec4(Vec4& r, const Vec2& a, const Vec2& b) { r.x = a.x; r.y = a.y; @@ -815,7 +815,7 @@ slInline void SetVector4(Vector4& r, const Vector2& a, const Vector2& b) } //---------------------------------------------------------------------------------------- -slInline void SetVector4(Vector4& r, const Vector3& v, const float w) +slInline void SetVec4(Vec4& r, const Vec3& v, const float w) { r.x = v.x; r.y = v.y; @@ -824,7 +824,7 @@ slInline void SetVector4(Vector4& r, const Vector3& v, const float w) } //---------------------------------------------------------------------------------------- -slInline void SetVector4(Vector4& r, const float xyzw) +slInline void SetVec4(Vec4& r, const float xyzw) { r.x = xyzw; r.y = xyzw; @@ -833,7 +833,7 @@ slInline void SetVector4(Vector4& r, const float xyzw) } //---------------------------------------------------------------------------------------- -slInline void SetVector4(Vector4& r, const float x, const float y, const float z, const float w) +slInline void SetVec4(Vec4& r, const float x, const float y, const float z, const float w) { r.x = x; r.y = y; @@ -842,7 +842,7 @@ slInline void SetVector4(Vector4& r, const float x, const float y, const float z } //---------------------------------------------------------------------------------------- -slInline void AbsVector4(Vector4& r, const Vector4& v) +slInline void AbsVec4(Vec4& r, const Vec4& v) { r.x = Absf(v.x); r.y = Absf(v.y); @@ -851,9 +851,9 @@ slInline void AbsVector4(Vector4& r, const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline Vector4 AbsVector4(const Vector4& v) +slInline Vec4 AbsVec4(const Vec4& v) { - Vector4 r; + Vec4 r; r.x = Absf(v.x); r.y = Absf(v.y); r.z = Absf(v.z); @@ -862,7 +862,7 @@ slInline Vector4 AbsVector4(const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline float MinComponentVector4(const Vector4& v) +slInline float MinComponentVec4(const Vec4& v) { float xy = v.x <= v.y ? v.x : v.y; float zw = v.z <= v.w ? v.z : v.w; @@ -870,7 +870,7 @@ slInline float MinComponentVector4(const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline float MaxComponentVector4(const Vector4& v) +slInline float MaxComponentVec4(const Vec4& v) { float xy = v.x >= v.y ? v.x : v.y; float zw = v.z >= v.w ? v.z : v.w; @@ -878,7 +878,7 @@ slInline float MaxComponentVector4(const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline uint32_t MinIndexVector4(const Vector4& v) +slInline uint32_t MinIndexVec4(const Vec4& v) { const float* v_array = &v.x; uint32_t xy = v.x <= v.y ? 0 : 1; @@ -887,7 +887,7 @@ slInline uint32_t MinIndexVector4(const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline uint32_t MaxIndexVector4(const Vector4& v) +slInline uint32_t MaxIndexVec4(const Vec4& v) { const float* v_array = &v.x; uint32_t xy = v.x >= v.y ? 0 : 1; @@ -896,19 +896,19 @@ slInline uint32_t MaxIndexVector4(const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline float DotVector4(const Vector4& a, const Vector4& b) +slInline float DotVec4(const Vec4& a, const Vec4& b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } //---------------------------------------------------------------------------------------- -slInline float DotVector4(const Vector4& a, const float x, const float y, const float z, const float w) +slInline float DotVec4(const Vec4& a, const float x, const float y, const float z, const float w) { return a.x * x + a.y * y + a.z * z + a.w * w; } //---------------------------------------------------------------------------------------- -slInline void CrossVector4(Vector4& r, const Vector4& a, const Vector4& b, const Vector4& c) +slInline void CrossVec4(Vec4& r, const Vec4& a, const Vec4& b, const Vec4& c) { // is this right? r.x = a.y * (b.z * c.w - b.w * c.z) - a.z * (b.y * c.w - c.y * b.w) + a.w * (b.y * c.z - b.z * c.y); @@ -918,9 +918,9 @@ slInline void CrossVector4(Vector4& r, const Vector4& a, const Vector4& b, const } //---------------------------------------------------------------------------------------- -slInline Vector4 CrossVector4(const Vector4& a, const Vector4& b, const Vector4& c) +slInline Vec4 CrossVec4(const Vec4& a, const Vec4& b, const Vec4& c) { - Vector4 r; + Vec4 r; // is this right? r.x = a.y * (b.z * c.w - b.w * c.z) - a.z * (b.y * c.w - c.y * b.w) + a.w * (b.y * c.z - b.z * c.y); r.y = -a.x * (b.z * c.w - b.w * c.z) + a.z * (b.x * c.w - c.x * b.w) - a.w * (b.x * c.z - b.z * c.x); @@ -930,7 +930,7 @@ slInline Vector4 CrossVector4(const Vector4& a, const Vector4& b, const Vector4& } //---------------------------------------------------------------------------------------- -slInline void AddVector4ByScalar(Vector4& r, const float s, Vector4& v) +slInline void AddVec4ByScalar(Vec4& r, const float s, Vec4& v) { r.x = s * v.x; r.y = s * v.y; @@ -939,9 +939,9 @@ slInline void AddVector4ByScalar(Vector4& r, const float s, Vector4& v) } //---------------------------------------------------------------------------------------- -slInline Vector4 AddVector4ByScalar(const float s, Vector4& v) +slInline Vec4 AddVec4ByScalar(const float s, Vec4& v) { - Vector4 r; + Vec4 r; r.x = s * v.x; r.y = s * v.y; r.z = s * v.z; @@ -950,7 +950,7 @@ slInline Vector4 AddVector4ByScalar(const float s, Vector4& v) } //---------------------------------------------------------------------------------------- -slInline void AddVector4(Vector4& r, const Vector4& a, const Vector4& b) +slInline void AddVec4(Vec4& r, const Vec4& a, const Vec4& b) { r.x = a.x + b.x; r.y = a.y + b.y; @@ -959,9 +959,9 @@ slInline void AddVector4(Vector4& r, const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline Vector4 AddVector4(const Vector4& a, const Vector4& b) +slInline Vec4 AddVec4(const Vec4& a, const Vec4& b) { - Vector4 r; + Vec4 r; r.x = a.x + b.x; r.y = a.y + b.y; r.z = a.z + b.z; @@ -970,7 +970,7 @@ slInline Vector4 AddVector4(const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline void AddVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w) +slInline void AddVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w) { r.x = a.x + x; r.y = a.y + y; @@ -979,9 +979,9 @@ slInline void AddVector4(Vector4& r, const Vector4& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector4 AddVector4(const Vector4& a, const float x, const float y, const float z, const float w) +slInline Vec4 AddVec4(const Vec4& a, const float x, const float y, const float z, const float w) { - Vector4 r; + Vec4 r; r.x = a.x + x; r.y = a.y + y; r.z = a.z + z; @@ -990,7 +990,7 @@ slInline Vector4 AddVector4(const Vector4& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void SubVector4(Vector4& r, const Vector4& a, const Vector4& b) +slInline void SubVec4(Vec4& r, const Vec4& a, const Vec4& b) { r.x = a.x - b.x; r.y = a.y - b.y; @@ -999,9 +999,9 @@ slInline void SubVector4(Vector4& r, const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline Vector4 SubVector4(const Vector4& a, const Vector4& b) +slInline Vec4 SubVec4(const Vec4& a, const Vec4& b) { - Vector4 r; + Vec4 r; r.x = a.x - b.x; r.y = a.y - b.y; r.z = a.z - b.z; @@ -1010,7 +1010,7 @@ slInline Vector4 SubVector4(const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline void SubVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w) +slInline void SubVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w) { r.x = a.x - x; r.y = a.y - y; @@ -1019,9 +1019,9 @@ slInline void SubVector4(Vector4& r, const Vector4& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector4 SubVector4(const Vector4& a, const float x, const float y, const float z, const float w) +slInline Vec4 SubVec4(const Vec4& a, const float x, const float y, const float z, const float w) { - Vector4 r; + Vec4 r; r.x = a.x - x; r.y = a.y - y; r.z = a.z - z; @@ -1030,7 +1030,7 @@ slInline Vector4 SubVector4(const Vector4& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void ScaleVector4(Vector4& r, const float s, const Vector4& v) +slInline void ScaleVec4(Vec4& r, const float s, const Vec4& v) { r.x = s * v.x; r.y = s * v.y; @@ -1039,9 +1039,9 @@ slInline void ScaleVector4(Vector4& r, const float s, const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline Vector4 ScaleVector4(const float s, const Vector4& v) +slInline Vec4 ScaleVec4(const float s, const Vec4& v) { - Vector4 r; + Vec4 r; r.x = s * v.x; r.y = s * v.y; r.z = s * v.z; @@ -1050,7 +1050,7 @@ slInline Vector4 ScaleVector4(const float s, const Vector4& v) } //---------------------------------------------------------------------------------------- -slInline void MulVector4(Vector4& r, const Vector4& a, const Vector4& b) +slInline void MulVec4(Vec4& r, const Vec4& a, const Vec4& b) { r.x = a.x * b.x; r.y = a.y * b.y; @@ -1059,9 +1059,9 @@ slInline void MulVector4(Vector4& r, const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector4(const Vector4& a, const Vector4& b) +slInline Vec4 MulVec4(const Vec4& a, const Vec4& b) { - Vector4 r; + Vec4 r; r.x = a.x * b.x; r.y = a.y * b.y; r.z = a.z * b.z; @@ -1070,7 +1070,7 @@ slInline Vector4 MulVector4(const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline void MulVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w) +slInline void MulVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w) { r.x = a.x * x; r.y = a.y * y; @@ -1079,9 +1079,9 @@ slInline void MulVector4(Vector4& r, const Vector4& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector4(const Vector4& a, const float x, const float y, const float z, const float w) +slInline Vec4 MulVec4(const Vec4& a, const float x, const float y, const float z, const float w) { - Vector4 r; + Vec4 r; r.x = a.x * x; r.y = a.y * y; r.z = a.z * z; @@ -1090,7 +1090,7 @@ slInline Vector4 MulVector4(const Vector4& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void DivVector4(Vector4& r, const Vector4& a, const Vector4& b) +slInline void DivVec4(Vec4& r, const Vec4& a, const Vec4& b) { r.x = a.x / b.x; r.y = a.y / b.y; @@ -1099,9 +1099,9 @@ slInline void DivVector4(Vector4& r, const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline Vector4 DivVector4(const Vector4& a, const Vector4& b) +slInline Vec4 DivVec4(const Vec4& a, const Vec4& b) { - Vector4 r; + Vec4 r; r.x = a.x / b.x; r.y = a.y / b.y; r.z = a.z / b.z; @@ -1110,7 +1110,7 @@ slInline Vector4 DivVector4(const Vector4& a, const Vector4& b) } //---------------------------------------------------------------------------------------- -slInline void DivVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w) +slInline void DivVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w) { r.x = a.x / x; r.y = a.y / y; @@ -1119,9 +1119,9 @@ slInline void DivVector4(Vector4& r, const Vector4& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector4 DivVector4(const Vector4& a, const float x, const float y, const float z, const float w) +slInline Vec4 DivVec4(const Vec4& a, const float x, const float y, const float z, const float w) { - Vector4 r; + Vec4 r; r.x = a.x / x; r.y = a.y / y; r.z = a.z / z; @@ -1130,7 +1130,7 @@ slInline Vector4 DivVector4(const Vector4& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void ScaleAddVector4(Vector4& r, const float s, const Vector4& v_scale, const Vector4& v_add) +slInline void ScaleAddVec4(Vec4& r, const float s, const Vec4& v_scale, const Vec4& v_add) { r.x = s * v_scale.x + v_add.x; r.y = s * v_scale.y + v_add.y; @@ -1139,9 +1139,9 @@ slInline void ScaleAddVector4(Vector4& r, const float s, const Vector4& v_scale, } //---------------------------------------------------------------------------------------- -slInline Vector4 ScaleAddVector4(const float s, const Vector4& v_scale, const Vector4& v_add) +slInline Vec4 ScaleAddVec4(const float s, const Vec4& v_scale, const Vec4& v_add) { - Vector4 r; + Vec4 r; r.x = s * v_scale.x + v_add.x; r.y = s * v_scale.y + v_add.y; r.z = s * v_scale.z + v_add.z; @@ -1150,27 +1150,27 @@ slInline Vector4 ScaleAddVector4(const float s, const Vector4& v_scale, const Ve } //---------------------------------------------------------------------------------------- -slInline void NormalizeVector4(Vector4& r, const Vector4& a) +slInline void NormalizeVec4(Vec4& r, const Vec4& a) { - float scale = 1.0f / LengthOfVector4( a ); - ScaleVector4( r, scale, a ); + float scale = 1.0f / LengthOfVec4( a ); + ScaleVec4( r, scale, a ); } //---------------------------------------------------------------------------------------- -slInline Vector4 NormalizeVector4(const Vector4& a) +slInline Vec4 NormalizeVec4(const Vec4& a) { - float scale = 1.0f / LengthOfVector4( a ); - return ScaleVector4( scale, a ); + float scale = 1.0f / LengthOfVec4( a ); + return ScaleVec4( scale, a ); } //---------------------------------------------------------------------------------------- -slInline float LengthOfVector4(const Vector4& a) +slInline float LengthOfVec4(const Vec4& a) { - return Sqrtf( DotVector4(a, a) ); + return (float)Sqrtf( DotVec4(a, a) ); } //---------------------------------------------------------------------------------------- -slInline float LengthSquaredOfVector4(const Vector4& a) +slInline float LengthSquaredOfVec4(const Vec4& a) { - return DotVector4( a, a ); + return DotVec4( a, a ); } diff --git a/Classes/cocos2d/CCAction.h b/Classes/cocos2d/CCAction.h new file mode 100644 index 0000000..327a251 --- /dev/null +++ b/Classes/cocos2d/CCAction.h @@ -0,0 +1,188 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#include +#import + +#import "ccTypes.h" + +enum { + //! Default tag + kCCActionTagInvalid = -1, +}; + +/** Base class for CCAction objects. + */ +@interface CCAction : NSObject +{ + id originalTarget_; + id target_; + NSInteger tag_; +} + +/** The "target". The action will modify the target properties. + The target will be set with the 'startWithTarget' method. + When the 'stop' method is called, target will be set to nil. + The target is 'assigned', it is not 'retained'. + */ +@property (nonatomic,readonly,assign) id target; + +/** The original target, since target can be nil. + Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you should NOT call this method. + @since v0.8.2 +*/ +@property (nonatomic,readonly,assign) id originalTarget; + + +/** The action tag. An identifier of the action */ +@property (nonatomic,readwrite,assign) NSInteger tag; + +/** Allocates and initializes the action */ ++(id) action; + +/** Initializes the action */ +-(id) init; + +-(id) copyWithZone: (NSZone*) zone; + +//! return YES if the action has finished +-(BOOL) isDone; +//! called before the action start. It will also set the target. +-(void) startWithTarget:(id)target; +//! called after the action has finished. It will set the 'target' to nil. +//! IMPORTANT: You should never call "[action stop]" manually. Instead, use: "[target stopAction:action];" +-(void) stop; +//! called every frame with it's delta time. DON'T override unless you know what you are doing. +-(void) step: (ccTime) dt; +//! called once per frame. time a value between 0 and 1 +//! For example: +//! * 0 means that the action just started +//! * 0.5 means that the action is in the middle +//! * 1 means that the action is over +-(void) update: (ccTime) time; + +@end + +/** Base class actions that do have a finite time duration. + Possible actions: + - An action with a duration of 0 seconds + - An action with a duration of 35.5 seconds + Infitite time actions are valid + */ +@interface CCFiniteTimeAction : CCAction +{ + //! duration in seconds + ccTime duration_; +} +//! duration in seconds of the action +@property (nonatomic,readwrite) ccTime duration; + +/** returns a reversed action */ +- (CCFiniteTimeAction*) reverse; +@end + + +@class CCActionInterval; +/** Repeats an action for ever. + To repeat the an action for a limited number of times use the Repeat action. + @warning This action can't be Sequenceable because it is not an IntervalAction + */ +@interface CCRepeatForever : CCAction +{ + CCActionInterval *other; +} +/** creates the action */ ++(id) actionWithAction: (CCActionInterval*) action; +/** initializes the action */ +-(id) initWithAction: (CCActionInterval*) action; +@end + +/** Changes the speed of an action, making it take longer (speed>1) + or less (speed<1) time. + Useful to simulate 'slow motion' or 'fast forward' effect. + @warning This action can't be Sequenceable because it is not an IntervalAction + */ +@interface CCSpeed : CCAction +{ + CCActionInterval *other; + float speed; +} +/** alter the speed of the inner function in runtime */ +@property (nonatomic,readwrite) float speed; +/** creates the action */ ++(id) actionWithAction: (CCActionInterval*) action speed:(float)rate; +/** initializes the action */ +-(id) initWithAction: (CCActionInterval*) action speed:(float)rate; +@end + +@class CCNode; +/** CCFollow is an action that "follows" a node. + + Eg: + [layer runAction: [CCFollow actionWithTarget:hero]]; + + Instead of using CCCamera as a "follower", use this action instead. + @since v0.99.2 + */ +@interface CCFollow : CCAction +{ + /* node to follow */ + CCNode *followedNode_; + + /* whether camera should be limited to certain area */ + BOOL boundarySet; + + /* if screensize is bigger than the boundary - update not needed */ + BOOL boundaryFullyCovered; + + /* fast access to the screen dimensions */ + CGPoint halfScreenSize; + CGPoint fullScreenSize; + + /* world boundaries */ + float leftBoundary; + float rightBoundary; + float topBoundary; + float bottomBoundary; +} + +/** alter behavior - turn on/off boundary */ +@property (nonatomic,readwrite) BOOL boundarySet; + +/** creates the action with no boundary set */ ++(id) actionWithTarget:(CCNode *)followedNode; + +/** creates the action with a set boundary */ ++(id) actionWithTarget:(CCNode *)followedNode worldBoundary:(CGRect)rect; + +/** initializes the action */ +-(id) initWithTarget:(CCNode *)followedNode; + +/** initializes the action with a set boundary */ +-(id) initWithTarget:(CCNode *)followedNode worldBoundary:(CGRect)rect; + +@end + diff --git a/Classes/cocos2d/CCAction.m b/Classes/cocos2d/CCAction.m new file mode 100644 index 0000000..8fc3b4c --- /dev/null +++ b/Classes/cocos2d/CCAction.m @@ -0,0 +1,360 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + + +#import +#import "CCDirector.h" +#import "ccMacros.h" +#import "CCAction.h" +#import "CCActionInterval.h" +#import "Support/CGPointExtension.h" + +// +// Action Base Class +// +#pragma mark - +#pragma mark Action +@implementation CCAction + +@synthesize tag = tag_, target = target_, originalTarget = originalTarget_; + ++(id) action +{ + return [[[self alloc] init] autorelease]; +} + +-(id) init +{ + if( (self=[super init]) ) { + originalTarget_ = target_ = nil; + tag_ = kCCActionTagInvalid; + } + return self; +} + +-(void) dealloc +{ + CCLOGINFO(@"cocos2d: deallocing %@", self); + [super dealloc]; +} + +-(NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag_]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] init]; + copy.tag = tag_; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + originalTarget_ = target_ = aTarget; +} + +-(void) stop +{ + target_ = nil; +} + +-(BOOL) isDone +{ + return YES; +} + +-(void) step: (ccTime) dt +{ + NSLog(@"[Action step]. override me"); +} + +-(void) update: (ccTime) time +{ + NSLog(@"[Action update]. override me"); +} +@end + +// +// FiniteTimeAction +// +#pragma mark - +#pragma mark FiniteTimeAction +@implementation CCFiniteTimeAction +@synthesize duration = duration_; + +- (CCFiniteTimeAction*) reverse +{ + CCLOG(@"cocos2d: FiniteTimeAction#reverse: Implement me"); + return nil; +} +@end + + +// +// RepeatForever +// +#pragma mark - +#pragma mark RepeatForever +@implementation CCRepeatForever ++(id) actionWithAction: (CCActionInterval*) action +{ + return [[[self alloc] initWithAction: action] autorelease]; +} + +-(id) initWithAction: (CCActionInterval*) action +{ + if( (self=[super init]) ) + other = [action retain]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] ]; + return copy; +} + +-(void) dealloc +{ + [other release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) step:(ccTime) dt +{ + [other step: dt]; + if( [other isDone] ) { + ccTime diff = dt + other.duration - other.elapsed; + [other startWithTarget:target_]; + + // to prevent jerk. issue #390 + [other step: diff]; + } +} + + +-(BOOL) isDone +{ + return NO; +} + +- (CCActionInterval *) reverse +{ + return [CCRepeatForever actionWithAction:[other reverse]]; +} + +@end + +// +// Speed +// +#pragma mark - +#pragma mark Speed +@implementation CCSpeed +@synthesize speed; + ++(id) actionWithAction: (CCActionInterval*) action speed:(float)r +{ + return [[[self alloc] initWithAction: action speed:r] autorelease]; +} + +-(id) initWithAction: (CCActionInterval*) action speed:(float)r +{ + if( (self=[super init]) ) { + other = [action retain]; + speed = r; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] speed:speed]; + return copy; +} + +-(void) dealloc +{ + [other release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) stop +{ + [other stop]; + [super stop]; +} + +-(void) step:(ccTime) dt +{ + [other step: dt * speed]; +} + +-(BOOL) isDone +{ + return [other isDone]; +} + +- (CCActionInterval *) reverse +{ + return [CCSpeed actionWithAction:[other reverse] speed:speed]; +} +@end + +// +// Follow +// +#pragma mark - +#pragma mark Follow +@implementation CCFollow + +@synthesize boundarySet; + ++(id) actionWithTarget:(CCNode *) fNode +{ + return [[[self alloc] initWithTarget:fNode] autorelease]; +} + ++(id) actionWithTarget:(CCNode *) fNode worldBoundary:(CGRect)rect +{ + return [[[self alloc] initWithTarget:fNode worldBoundary:rect] autorelease]; +} + +-(id) initWithTarget:(CCNode *)fNode +{ + if( (self=[super init]) ) { + + followedNode_ = [fNode retain]; + boundarySet = FALSE; + boundaryFullyCovered = FALSE; + + CGSize s = [[CCDirector sharedDirector] winSize]; + fullScreenSize = CGPointMake(s.width, s.height); + halfScreenSize = ccpMult(fullScreenSize, .5f); + } + + return self; +} + +-(id) initWithTarget:(CCNode *)fNode worldBoundary:(CGRect)rect +{ + if( (self=[super init]) ) { + + followedNode_ = [fNode retain]; + boundarySet = TRUE; + boundaryFullyCovered = FALSE; + + CGSize winSize = [[CCDirector sharedDirector] winSize]; + fullScreenSize = CGPointMake(winSize.width, winSize.height); + halfScreenSize = ccpMult(fullScreenSize, .5f); + + leftBoundary = -((rect.origin.x+rect.size.width) - fullScreenSize.x); + rightBoundary = -rect.origin.x ; + topBoundary = -rect.origin.y; + bottomBoundary = -((rect.origin.y+rect.size.height) - fullScreenSize.y); + + if(rightBoundary < leftBoundary) + { + // screen width is larger than world's boundary width + //set both in the middle of the world + rightBoundary = leftBoundary = (leftBoundary + rightBoundary) / 2; + } + if(topBoundary < bottomBoundary) + { + // screen width is larger than world's boundary width + //set both in the middle of the world + topBoundary = bottomBoundary = (topBoundary + bottomBoundary) / 2; + } + + if( (topBoundary == bottomBoundary) && (leftBoundary == rightBoundary) ) + boundaryFullyCovered = TRUE; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] init]; + copy.tag = tag_; + return copy; +} + +-(void) step:(ccTime) dt +{ +#define CLAMP(x,y,z) MIN(MAX(x,y),z) + + if(boundarySet) + { + // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased + if(boundaryFullyCovered) + return; + + CGPoint tempPos = ccpSub( halfScreenSize, followedNode_.position); + [target_ setPosition:ccp(CLAMP(tempPos.x,leftBoundary,rightBoundary), CLAMP(tempPos.y,bottomBoundary,topBoundary))]; + } + else + [target_ setPosition:ccpSub( halfScreenSize, followedNode_.position )]; + +#undef CLAMP +} + + +-(BOOL) isDone +{ + return !followedNode_.isRunning; +} + +-(void) stop +{ + target_ = nil; + [super stop]; +} + +-(void) dealloc +{ + [followedNode_ release]; + [super dealloc]; +} + +@end + + diff --git a/Classes/cocos2d/CCActionCamera.h b/Classes/cocos2d/CCActionCamera.h new file mode 100644 index 0000000..131c084 --- /dev/null +++ b/Classes/cocos2d/CCActionCamera.h @@ -0,0 +1,72 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#import "CCActionInterval.h" + +@class CCCamera; + +/** Base class for CCCamera actions + */ +@interface CCActionCamera : CCActionInterval +{ + float centerXOrig_; + float centerYOrig_; + float centerZOrig_; + + float eyeXOrig_; + float eyeYOrig_; + float eyeZOrig_; + + float upXOrig_; + float upYOrig_; + float upZOrig_; +} +@end + +/** CCOrbitCamera action + Orbits the camera around the center of the screen using spherical coordinates + */ +@interface CCOrbitCamera : CCActionCamera +{ + float radius_; + float deltaRadius_; + float angleZ_; + float deltaAngleZ_; + float angleX_; + float deltaAngleX_; + + float radZ_; + float radDeltaZ_; + float radX_; + float radDeltaX_; + +} +/** creates a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ ++(id) actionWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; +/** initializes a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ +-(id) initWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx; +/** positions the camera according to spherical coordinates */ +-(void) sphericalRadius:(float*) r zenith:(float*) zenith azimuth:(float*) azimuth; +@end diff --git a/Classes/cocos2d/CCActionCamera.m b/Classes/cocos2d/CCActionCamera.m new file mode 100644 index 0000000..5134c6f --- /dev/null +++ b/Classes/cocos2d/CCActionCamera.m @@ -0,0 +1,146 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + + +#import "CCActionCamera.h" +#import "CCNode.h" +#import "CCCamera.h" +#import "ccMacros.h" + +// +// CameraAction +// +@implementation CCActionCamera +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + CCCamera *camera = [target_ camera]; + [camera centerX:¢erXOrig_ centerY:¢erYOrig_ centerZ:¢erZOrig_]; + [camera eyeX:&eyeXOrig_ eyeY:&eyeYOrig_ eyeZ:&eyeZOrig_]; + [camera upX:&upXOrig_ upY:&upYOrig_ upZ: &upZOrig_]; +} + +-(id) reverse +{ + return [CCReverseTime actionWithAction:self]; +} +@end + +@implementation CCOrbitCamera ++(id) actionWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx +{ + return [[[self alloc] initWithDuration:t radius:r deltaRadius:dr angleZ:z deltaAngleZ:dz angleX:x deltaAngleX:dx] autorelease]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + return [[[self class] allocWithZone: zone] initWithDuration:duration_ radius:radius_ deltaRadius:deltaRadius_ angleZ:angleZ_ deltaAngleZ:deltaAngleZ_ angleX:angleX_ deltaAngleX:deltaAngleX_]; +} + + +-(id) initWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx +{ + if((self=[super initWithDuration:t]) ) { + + radius_ = r; + deltaRadius_ = dr; + angleZ_ = z; + deltaAngleZ_ = dz; + angleX_ = x; + deltaAngleX_ = dx; + + radDeltaZ_ = (CGFloat)CC_DEGREES_TO_RADIANS(dz); + radDeltaX_ = (CGFloat)CC_DEGREES_TO_RADIANS(dx); + } + + return self; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + float r, zenith, azimuth; + + [self sphericalRadius: &r zenith:&zenith azimuth:&azimuth]; + +#if 0 // isnan() is not supported on the simulator, and isnan() always returns false. + if( isnan(radius_) ) + radius_ = r; + + if( isnan( angleZ_) ) + angleZ_ = (CGFloat)CC_RADIANS_TO_DEGREES(zenith); + + if( isnan( angleX_ ) ) + angleX_ = (CGFloat)CC_RADIANS_TO_DEGREES(azimuth); +#endif + + radZ_ = (CGFloat)CC_DEGREES_TO_RADIANS(angleZ_); + radX_ = (CGFloat)CC_DEGREES_TO_RADIANS(angleX_); +} + +-(void) update: (ccTime) dt +{ + float r = (radius_ + deltaRadius_ * dt) *[CCCamera getZEye]; + float za = radZ_ + radDeltaZ_ * dt; + float xa = radX_ + radDeltaX_ * dt; + + float i = sinf(za) * cosf(xa) * r + centerXOrig_; + float j = sinf(za) * sinf(xa) * r + centerYOrig_; + float k = cosf(za) * r + centerZOrig_; + + [[target_ camera] setEyeX:i eyeY:j eyeZ:k]; +} + +-(void) sphericalRadius:(float*) newRadius zenith:(float*) zenith azimuth:(float*) azimuth +{ + float ex, ey, ez, cx, cy, cz, x, y, z; + float r; // radius + float s; + + CCCamera *camera = [target_ camera]; + [camera eyeX:&ex eyeY:&ey eyeZ:&ez]; + [camera centerX:&cx centerY:&cy centerZ:&cz]; + + x = ex-cx; + y = ey-cy; + z = ez-cz; + + r = sqrtf( x*x + y*y + z*z); + s = sqrtf( x*x + y*y); + if(s==0.0f) + s = FLT_EPSILON; + if(r==0.0f) + r = FLT_EPSILON; + + *zenith = acosf( z/r); + if( x < 0 ) + *azimuth = (float)M_PI - asinf(y/s); + else + *azimuth = asinf(y/s); + + *newRadius = r / [CCCamera getZEye]; +} +@end diff --git a/Classes/cocos2d/CCActionEase.h b/Classes/cocos2d/CCActionEase.h new file mode 100644 index 0000000..fced701 --- /dev/null +++ b/Classes/cocos2d/CCActionEase.h @@ -0,0 +1,159 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2009 Jason Booth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCActionInterval.h" + +/** Base class for Easing actions + */ +@interface CCActionEase : CCActionInterval +{ + CCActionInterval * other; +} +/** creates the action */ ++(id) actionWithAction: (CCActionInterval*) action; +/** initializes the action */ +-(id) initWithAction: (CCActionInterval*) action; +@end + +/** Base class for Easing actions with rate parameters + */ +@interface CCEaseRateAction : CCActionEase +{ + float rate; +} +/** rate value for the actions */ +@property (nonatomic,readwrite,assign) float rate; +/** Creates the action with the inner action and the rate parameter */ ++(id) actionWithAction: (CCActionInterval*) action rate:(float)rate; +/** Initializes the action with the inner action and the rate parameter */ +-(id) initWithAction: (CCActionInterval*) action rate:(float)rate; +@end + +/** CCEaseIn action with a rate + */ +@interface CCEaseIn : CCEaseRateAction {} @end + +/** CCEaseOut action with a rate + */ +@interface CCEaseOut : CCEaseRateAction {} @end + +/** CCEaseInOut action with a rate + */ +@interface CCEaseInOut : CCEaseRateAction {} @end + +/** CCEase Exponential In + */ +@interface CCEaseExponentialIn : CCActionEase {} @end +/** Ease Exponential Out + */ +@interface CCEaseExponentialOut : CCActionEase {} @end +/** Ease Exponential InOut + */ +@interface CCEaseExponentialInOut : CCActionEase {} @end +/** Ease Sine In + */ +@interface CCEaseSineIn : CCActionEase {} @end +/** Ease Sine Out + */ +@interface CCEaseSineOut : CCActionEase {} @end +/** Ease Sine InOut + */ +@interface CCEaseSineInOut : CCActionEase {} @end + +/** Ease Elastic abstract class + @since v0.8.2 + */ +@interface CCEaseElastic : CCActionEase +{ + float period_; +} + +/** period of the wave in radians. default is 0.3 */ +@property (nonatomic,readwrite) float period; + +/** Creates the action with the inner action and the period in radians (default is 0.3) */ ++(id) actionWithAction: (CCActionInterval*) action period:(float)period; +/** Initializes the action with the inner action and the period in radians (default is 0.3) */ +-(id) initWithAction: (CCActionInterval*) action period:(float)period; +@end + +/** Ease Elastic In action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseElasticIn : CCEaseElastic {} @end +/** Ease Elastic Out action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseElasticOut : CCEaseElastic {} @end +/** Ease Elastic InOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseElasticInOut : CCEaseElastic {} @end + +/** CCEaseBounce abstract class. + @since v0.8.2 +*/ +@interface CCEaseBounce : CCActionEase {} @end + +/** CCEaseBounceIn action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 +*/ +@interface CCEaseBounceIn : CCEaseBounce {} @end + +/** EaseBounceOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBounceOut : CCEaseBounce {} @end + +/** CCEaseBounceInOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBounceInOut : CCEaseBounce {} @end + +/** CCEaseBackIn action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBackIn : CCActionEase {} @end + +/** CCEaseBackOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBackOut : CCActionEase {} @end + +/** CCEaseBackInOut action. + @warning This action doesn't use a bijective fucntion. Actions like Sequence might have an unexpected result when used with this action. + @since v0.8.2 + */ +@interface CCEaseBackInOut : CCActionEase {} @end + diff --git a/Classes/cocos2d/CCActionEase.m b/Classes/cocos2d/CCActionEase.m new file mode 100644 index 0000000..f28be11 --- /dev/null +++ b/Classes/cocos2d/CCActionEase.m @@ -0,0 +1,534 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2009 Jason Booth + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +/* + * Elastic, Back and Bounce actions based on code from: + * http://github.com/NikhilK/silverlightfx/ + * + * by http://github.com/NikhilK + */ + +#import "CCActionEase.h" + +#ifndef M_PI_X_2 +#define M_PI_X_2 (float)M_PI * 2.0f +#endif + +#pragma mark EaseAction + +// +// EaseAction +// +@implementation CCActionEase + ++(id) actionWithAction: (CCActionInterval*) action +{ + return [[[self alloc] initWithAction: action] autorelease ]; +} + +-(id) initWithAction: (CCActionInterval*) action +{ + NSAssert( action!=nil, @"Ease: arguments must be non-nil"); + + if( (self=[super initWithDuration: action.duration]) ) + other = [action retain]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease]]; + return copy; +} + +-(void) dealloc +{ + [other release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) stop +{ + [other stop]; + [super stop]; +} + +-(void) update: (ccTime) t +{ + [other update: t]; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithAction: [other reverse]]; +} +@end + + +#pragma mark - +#pragma mark EaseRate + +// +// EaseRateAction +// +@implementation CCEaseRateAction +@synthesize rate; ++(id) actionWithAction: (CCActionInterval*) action rate:(float)aRate +{ + return [[[self alloc] initWithAction: action rate:aRate] autorelease ]; +} + +-(id) initWithAction: (CCActionInterval*) action rate:(float)aRate +{ + if( (self=[super initWithAction:action ]) ) + self.rate = aRate; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease] rate:rate]; + return copy; +} + +-(void) dealloc +{ + [super dealloc]; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithAction: [other reverse] rate:1/rate]; +} +@end + +// +// EeseIn +// +@implementation CCEaseIn +-(void) update: (ccTime) t +{ + [other update: powf(t,rate)]; +} +@end + +// +// EaseOut +// +@implementation CCEaseOut +-(void) update: (ccTime) t +{ + [other update: powf(t,1/rate)]; +} +@end + +// +// EaseInOut +// +@implementation CCEaseInOut +-(void) update: (ccTime) t +{ + int sign =1; + int r = (int) rate; + if (r % 2 == 0) + sign = -1; + t *= 2; + if (t < 1) + [other update: 0.5f * powf (t, rate)]; + else + [other update: sign*0.5f * (powf (t-2, rate) + sign*2)]; +} + +// InOut and OutIn are symmetrical +-(CCActionInterval*) reverse +{ + return [[self class] actionWithAction: [other reverse] rate:rate]; +} + +@end + +#pragma mark - +#pragma mark EaseExponential + +// +// EaseExponentialIn +// +@implementation CCEaseExponentialIn +-(void) update: (ccTime) t +{ + [other update: (t==0) ? 0 : powf(2, 10 * (t/1 - 1)) - 1 * 0.001f]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseExponentialOut actionWithAction: [other reverse]]; +} +@end + +// +// EaseExponentialOut +// +@implementation CCEaseExponentialOut +-(void) update: (ccTime) t +{ + [other update: (t==1) ? 1 : (-powf(2, -10 * t/1) + 1)]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseExponentialIn actionWithAction: [other reverse]]; +} +@end + +// +// EaseExponentialInOut +// +@implementation CCEaseExponentialInOut +-(void) update: (ccTime) t +{ + t /= 0.5f; + if (t < 1) + t = 0.5f * powf(2, 10 * (t - 1)); + else + t = 0.5f * (-powf(2, -10 * (t -1) ) + 2); + + [other update:t]; +} +@end + + +#pragma mark - +#pragma mark EaseSin actions + +// +// EaseSineIn +// +@implementation CCEaseSineIn +-(void) update: (ccTime) t +{ + [other update:-1*cosf(t * (float)M_PI_2) +1]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseSineOut actionWithAction: [other reverse]]; +} +@end + +// +// EaseSineOut +// +@implementation CCEaseSineOut +-(void) update: (ccTime) t +{ + [other update:sinf(t * (float)M_PI_2)]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseSineIn actionWithAction: [other reverse]]; +} +@end + +// +// EaseSineInOut +// +@implementation CCEaseSineInOut +-(void) update: (ccTime) t +{ + [other update:-0.5f*(cosf( (float)M_PI*t) - 1)]; +} +@end + +#pragma mark - +#pragma mark EaseElastic actions + +// +// EaseElastic +// +@implementation CCEaseElastic + +@synthesize period = period_; + ++(id) actionWithAction: (CCActionInterval*) action +{ + return [[[self alloc] initWithAction:action period:0.3f] autorelease]; +} + ++(id) actionWithAction: (CCActionInterval*) action period:(float)period +{ + return [[[self alloc] initWithAction:action period:period] autorelease]; +} + +-(id) initWithAction: (CCActionInterval*) action +{ + return [self initWithAction:action period:0.3f]; +} + +-(id) initWithAction: (CCActionInterval*) action period:(float)period +{ + if( (self=[super initWithAction:action]) ) + period_ = period; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other copy] autorelease] period:period_]; + return copy; +} + +-(CCActionInterval*) reverse +{ + NSAssert(NO,@"Override me"); + return nil; +} + +@end + +// +// EaseElasticIn +// + +@implementation CCEaseElasticIn +-(void) update: (ccTime) t +{ + ccTime newT = 0; + if (t == 0 || t == 1) + newT = t; + + else { + float s = period_ / 4; + t = t - 1; + newT = -powf(2, 10 * t) * sinf( (t-s) *M_PI_X_2 / period_); + } + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseElasticOut actionWithAction: [other reverse] period:period_]; +} + +@end + +// +// EaseElasticOut +// +@implementation CCEaseElasticOut + +-(void) update: (ccTime) t +{ + ccTime newT = 0; + if (t == 0 || t == 1) { + newT = t; + + } else { + float s = period_ / 4; + newT = powf(2, -10 * t) * sinf( (t-s) *M_PI_X_2 / period_) + 1; + } + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseElasticIn actionWithAction: [other reverse] period:period_]; +} + +@end + +// +// EaseElasticInOut +// +@implementation CCEaseElasticInOut +-(void) update: (ccTime) t +{ + ccTime newT = 0; + + if( t == 0 || t == 1 ) + newT = t; + else { + t = t * 2; + if(! period_ ) + period_ = 0.3f * 1.5f; + ccTime s = period_ / 4; + + t = t -1; + if( t < 0 ) + newT = -0.5f * powf(2, 10 * t) * sinf((t - s) * M_PI_X_2 / period_); + else + newT = powf(2, -10 * t) * sinf((t - s) * M_PI_X_2 / period_) * 0.5f + 1; + } + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseElasticInOut actionWithAction: [other reverse] period:period_]; +} + +@end + +#pragma mark - +#pragma mark EaseBounce actions + +// +// EaseBounce +// +@implementation CCEaseBounce +-(ccTime) bounceTime:(ccTime) t +{ + if (t < 1 / 2.75) { + return 7.5625f * t * t; + } + else if (t < 2 / 2.75) { + t -= 1.5f / 2.75f; + return 7.5625f * t * t + 0.75f; + } + else if (t < 2.5 / 2.75) { + t -= 2.25f / 2.75f; + return 7.5625f * t * t + 0.9375f; + } + + t -= 2.625f / 2.75f; + return 7.5625f * t * t + 0.984375f; +} +@end + +// +// EaseBounceIn +// + +@implementation CCEaseBounceIn + +-(void) update: (ccTime) t +{ + ccTime newT = 1 - [self bounceTime:1-t]; + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBounceOut actionWithAction: [other reverse]]; +} + +@end + +@implementation CCEaseBounceOut + +-(void) update: (ccTime) t +{ + ccTime newT = [self bounceTime:t]; + [other update:newT]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBounceIn actionWithAction: [other reverse]]; +} + +@end + +@implementation CCEaseBounceInOut + +-(void) update: (ccTime) t +{ + ccTime newT = 0; + if (t < 0.5) { + t = t * 2; + newT = (1 - [self bounceTime:1-t] ) * 0.5f; + } else + newT = [self bounceTime:t * 2 - 1] * 0.5f + 0.5f; + + [other update:newT]; +} +@end + +#pragma mark - +#pragma mark Ease Back actions + +// +// EaseBackIn +// +@implementation CCEaseBackIn + +-(void) update: (ccTime) t +{ + ccTime overshoot = 1.70158f; + [other update: t * t * ((overshoot + 1) * t - overshoot)]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBackOut actionWithAction: [other reverse]]; +} +@end + +// +// EaseBackOut +// +@implementation CCEaseBackOut +-(void) update: (ccTime) t +{ + ccTime overshoot = 1.70158f; + + t = t - 1; + [other update: t * t * ((overshoot + 1) * t + overshoot) + 1]; +} + +- (CCActionInterval*) reverse +{ + return [CCEaseBackIn actionWithAction: [other reverse]]; +} +@end + +// +// EaseBackInOut +// +@implementation CCEaseBackInOut + +-(void) update: (ccTime) t +{ + ccTime overshoot = 1.70158f * 1.525f; + + t = t * 2; + if (t < 1) + [other update: (t * t * ((overshoot + 1) * t - overshoot)) / 2]; + else { + t = t - 2; + [other update: (t * t * ((overshoot + 1) * t + overshoot)) / 2 + 1]; + } +} +@end diff --git a/Classes/cocos2d/CCActionGrid.h b/Classes/cocos2d/CCActionGrid.h new file mode 100644 index 0000000..13b6bc7 --- /dev/null +++ b/Classes/cocos2d/CCActionGrid.h @@ -0,0 +1,165 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCActionInterval.h" +#import "CCActionInstant.h" +#import "CCGrid.h" + +@class CCGridBase; + +/** Base class for Grid actions */ +@interface CCGridAction : CCActionInterval +{ + ccGridSize gridSize_; +} + +/** size of the grid */ +@property (nonatomic,readwrite) ccGridSize gridSize; + +/** creates the action with size and duration */ ++(id) actionWithSize:(ccGridSize)size duration:(ccTime)d; +/** initializes the action with size and duration */ +-(id) initWithSize:(ccGridSize)gridSize duration:(ccTime)d; +/** returns the grid */ +-(CCGridBase *)grid; + +@end + +//////////////////////////////////////////////////////////// + +/** Base class for CCGrid3D actions. + Grid3D actions can modify a non-tiled grid. + */ +@interface CCGrid3DAction : CCGridAction +{ +} + +/** returns the vertex than belongs to certain position in the grid */ +-(ccVertex3F)vertex:(ccGridSize)pos; +/** returns the non-transformed vertex than belongs to certain position in the grid */ +-(ccVertex3F)originalVertex:(ccGridSize)pos; +/** sets a new vertex to a certain position of the grid */ +-(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex; + +@end + +//////////////////////////////////////////////////////////// + +/** Base class for CCTiledGrid3D actions */ +@interface CCTiledGrid3DAction : CCGridAction +{ +} + +/** returns the tile that belongs to a certain position of the grid */ +-(ccQuad3)tile:(ccGridSize)pos; +/** returns the non-transformed tile that belongs to a certain position of the grid */ +-(ccQuad3)originalTile:(ccGridSize)pos; +/** sets a new tile to a certain position of the grid */ +-(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords; + +@end + +//////////////////////////////////////////////////////////// + +/** CCAccelDeccelAmplitude action */ +@interface CCAccelDeccelAmplitude : CCActionInterval +{ + float rate; + CCActionInterval *other; +} + +/** amplitude rate */ +@property (nonatomic,readwrite) float rate; + +/** creates the action with an inner action that has the amplitude property, and a duration time */ ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d; +/** initializes the action with an inner action that has the amplitude property, and a duration time */ +-(id)initWithAction:(CCAction*)action duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCAccelAmplitude action */ +@interface CCAccelAmplitude : CCActionInterval +{ + float rate; + CCActionInterval *other; +} + +/** amplitude rate */ +@property (nonatomic,readwrite) float rate; + +/** creates the action with an inner action that has the amplitude property, and a duration time */ ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d; +/** initializes the action with an inner action that has the amplitude property, and a duration time */ +-(id)initWithAction:(CCAction*)action duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCDeccelAmplitude action */ +@interface CCDeccelAmplitude : CCActionInterval +{ + float rate; + CCActionInterval *other; +} + +/** amplitude rate */ +@property (nonatomic,readwrite) float rate; + +/** creates the action with an inner action that has the amplitude property, and a duration time */ ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d; +/** initializes the action with an inner action that has the amplitude property, and a duration time */ +-(id)initWithAction:(CCAction*)action duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCStopGrid action. + Don't call this action if another grid action is active. + Call if you want to remove the the grid effect. Example: + [Sequence actions:[Lens ...], [StopGrid action], nil]; + */ +@interface CCStopGrid : CCActionInstant +{ +} +@end + +//////////////////////////////////////////////////////////// + +/** CCReuseGrid action */ +@interface CCReuseGrid : CCActionInstant +{ + int t; +} +/** creates an action with the number of times that the current grid will be reused */ ++(id) actionWithTimes: (int) times; +/** initializes an action with the number of times that the current grid will be reused */ +-(id) initWithTimes: (int) times; +@end diff --git a/Classes/cocos2d/CCActionGrid.m b/Classes/cocos2d/CCActionGrid.m new file mode 100644 index 0000000..b2d8f98 --- /dev/null +++ b/Classes/cocos2d/CCActionGrid.m @@ -0,0 +1,386 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCActionGrid.h" +#import "CCDirector.h" + +#pragma mark - +#pragma mark GridAction + +@implementation CCGridAction + +@synthesize gridSize = gridSize_; + ++(id) actionWithSize:(ccGridSize)size duration:(ccTime)d +{ + return [[[self alloc] initWithSize:size duration:d ] autorelease]; +} + +-(id) initWithSize:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + gridSize_ = gSize; + } + + return self; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + CCGridBase *newgrid = [self grid]; + + CCNode *t = (CCNode*) target_; + CCGridBase *targetGrid = [t grid]; + + if ( targetGrid && targetGrid.reuseGrid > 0 ) + { + if ( targetGrid.active && targetGrid.gridSize.x == gridSize_.x && targetGrid.gridSize.y == gridSize_.y && [targetGrid isKindOfClass:[newgrid class]] ) + [targetGrid reuse]; + else + [NSException raise:@"GridBase" format:@"Cannot reuse grid"]; + } + else + { + if ( targetGrid && targetGrid.active ) + targetGrid.active = NO; + + t.grid = newgrid; + t.grid.active = YES; + } +} + +-(CCGridBase *)grid +{ + [NSException raise:@"GridBase" format:@"Abstract class needs implementation"]; + return nil; +} + +- (CCActionInterval*) reverse +{ + return [CCReverseTime actionWithAction:self]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithSize:gridSize_ duration:duration_]; + return copy; +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Grid3DAction + +@implementation CCGrid3DAction + +-(CCGridBase *)grid +{ + return [CCGrid3D gridWithSize:gridSize_]; +} + +-(ccVertex3F)vertex:(ccGridSize)pos +{ + CCGrid3D *g = (CCGrid3D *)[target_ grid]; + return [g vertex:pos]; +} + +-(ccVertex3F)originalVertex:(ccGridSize)pos +{ + CCGrid3D *g = (CCGrid3D *)[target_ grid]; + return [g originalVertex:pos]; +} + +-(void)setVertex:(ccGridSize)pos vertex:(ccVertex3F)vertex +{ + CCGrid3D *g = (CCGrid3D *)[target_ grid]; + return [g setVertex:pos vertex:vertex]; +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark TiledGrid3DAction + +@implementation CCTiledGrid3DAction + +-(CCGridBase *)grid +{ + return [CCTiledGrid3D gridWithSize:gridSize_]; +} + +-(ccQuad3)tile:(ccGridSize)pos +{ + CCTiledGrid3D *g = (CCTiledGrid3D *)[target_ grid]; + return [g tile:pos]; +} + +-(ccQuad3)originalTile:(ccGridSize)pos +{ + CCTiledGrid3D *g = (CCTiledGrid3D *)[target_ grid]; + return [g originalTile:pos]; +} + +-(void)setTile:(ccGridSize)pos coords:(ccQuad3)coords +{ + CCTiledGrid3D *g = (CCTiledGrid3D *)[target_ grid]; + [g setTile:pos coords:coords]; +} + +@end + +//////////////////////////////////////////////////////////// + +@interface CCActionInterval (Amplitude) +-(void)setAmplitudeRate:(CGFloat)amp; +-(CGFloat)getAmplitudeRate; +@end + +@implementation CCActionInterval (Amplitude) +-(void)setAmplitudeRate:(CGFloat)amp +{ + [NSException raise:@"IntervalAction (Amplitude)" format:@"Abstract class needs implementation"]; +} + +-(CGFloat)getAmplitudeRate +{ + [NSException raise:@"IntervalAction (Amplitude)" format:@"Abstract class needs implementation"]; + return 0; +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark AccelDeccelAmplitude + +@implementation CCAccelDeccelAmplitude + +@synthesize rate; + ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d +{ + return [[[self alloc] initWithAction:action duration:d ] autorelease]; +} + +-(id)initWithAction:(CCAction *)action duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + rate = 1.0f; + other = [action retain]; + } + + return self; +} + +-(void)dealloc +{ + [other release]; + [super dealloc]; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) update: (ccTime) time +{ + float f = time*2; + + if (f > 1) + { + f -= 1; + f = 1 - f; + } + + [other setAmplitudeRate:powf(f, rate)]; + [other update:time]; +} + +- (CCActionInterval*) reverse +{ + return [CCAccelDeccelAmplitude actionWithAction:[other reverse] duration:duration_]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark AccelAmplitude + +@implementation CCAccelAmplitude + +@synthesize rate; + ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d +{ + return [[[self alloc] initWithAction:action duration:d ] autorelease]; +} + +-(id)initWithAction:(CCAction *)action duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + rate = 1.0f; + other = [action retain]; + } + + return self; +} + +-(void)dealloc +{ + [other release]; + [super dealloc]; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) update: (ccTime) time +{ + [other setAmplitudeRate:powf(time, rate)]; + [other update:time]; +} + +- (CCActionInterval*) reverse +{ + return [CCAccelAmplitude actionWithAction:[other reverse] duration:self.duration]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark DeccelAmplitude + +@implementation CCDeccelAmplitude + +@synthesize rate; + ++(id)actionWithAction:(CCAction*)action duration:(ccTime)d +{ + return [[[self alloc] initWithAction:action duration:d ] autorelease]; +} + +-(id)initWithAction:(CCAction *)action duration:(ccTime)d +{ + if ( (self = [super initWithDuration:d]) ) + { + rate = 1.0f; + other = [action retain]; + } + + return self; +} + +-(void)dealloc +{ + [other release]; + [super dealloc]; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) update: (ccTime) time +{ + [other setAmplitudeRate:powf((1-time), rate)]; + [other update:time]; +} + +- (CCActionInterval*) reverse +{ + return [CCDeccelAmplitude actionWithAction:[other reverse] duration:self.duration]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark StopGrid + +@implementation CCStopGrid + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + if ( [[self target] grid] && [[[self target] grid] active] ) { + [[[self target] grid] setActive: NO]; + +// [[self target] setGrid: nil]; + } +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark ReuseGrid + +@implementation CCReuseGrid + ++(id)actionWithTimes:(int)times +{ + return [[[self alloc] initWithTimes:times ] autorelease]; +} + +-(id)initWithTimes:(int)times +{ + if ( (self = [super init]) ) + t = times; + + return self; +} + +-(void)startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + CCNode *myTarget = (CCNode*) [self target]; + if ( myTarget.grid && myTarget.grid.active ) + myTarget.grid.reuseGrid += t; +} + +@end diff --git a/Classes/cocos2d/CCActionGrid3D.h b/Classes/cocos2d/CCActionGrid3D.h new file mode 100644 index 0000000..a8003f4 --- /dev/null +++ b/Classes/cocos2d/CCActionGrid3D.h @@ -0,0 +1,208 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCActionGrid.h" + +/** CCWaves3D action */ +@interface CCWaves3D : CCGrid3DAction +{ + int waves; + float amplitude; + float amplitudeRate; +} + +/** amplitude of the wave */ +@property (nonatomic,readwrite) float amplitude; +/** amplitude rate of the wave */ +@property (nonatomic,readwrite) float amplitudeRate; + ++(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; +-(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCFlipX3D action */ +@interface CCFlipX3D : CCGrid3DAction +{ +} + +/** creates the action with duration */ ++(id) actionWithDuration:(ccTime)d; +/** initizlies the action with duration */ +-(id) initWithDuration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCFlipY3D action */ +@interface CCFlipY3D : CCFlipX3D +{ +} + +@end + +//////////////////////////////////////////////////////////// + +/** CCLens3D action */ +@interface CCLens3D : CCGrid3DAction +{ + CGPoint position_; + CGPoint positionInPixels_; + float radius_; + float lensEffect_; + BOOL dirty_; +} + +/** lens effect. Defaults to 0.7 - 0 means no effect, 1 is very strong effect */ +@property (nonatomic,readwrite) float lensEffect; +/** lens center position in Points */ +@property (nonatomic,readwrite) CGPoint position; + +/** creates the action with center position in Points, radius, a grid size and duration */ ++(id)actionWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gridSize duration:(ccTime)d; +/** initializes the action with center position in Points, radius, a grid size and duration */ +-(id)initWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCRipple3D action */ +@interface CCRipple3D : CCGrid3DAction +{ + CGPoint position_; + CGPoint positionInPixels_; + float radius_; + int waves_; + float amplitude_; + float amplitudeRate_; +} + +/** center position in Points */ +@property (nonatomic,readwrite) CGPoint position; +/** amplitude */ +@property (nonatomic,readwrite) float amplitude; +/** amplitude rate */ +@property (nonatomic,readwrite) float amplitudeRate; + +/** creates the action with a position in points, radius, number of waves, amplitude, a grid size and duration */ ++(id)actionWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; +/** initializes the action with a position in points, radius, number of waves, amplitude, a grid size and duration */ +-(id)initWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCShaky3D action */ +@interface CCShaky3D : CCGrid3DAction +{ + int randrange; + BOOL shakeZ; +} + +/** creates the action with a range, shake Z vertices, a grid and duration */ ++(id)actionWithRange:(int)range shakeZ:(BOOL)shakeZ grid:(ccGridSize)gridSize duration:(ccTime)d; +/** initializes the action with a range, shake Z vertices, a grid and duration */ +-(id)initWithRange:(int)range shakeZ:(BOOL)shakeZ grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCLiquid action */ +@interface CCLiquid : CCGrid3DAction +{ + int waves; + float amplitude; + float amplitudeRate; + +} + +/** amplitude */ +@property (nonatomic,readwrite) float amplitude; +/** amplitude rate */ +@property (nonatomic,readwrite) float amplitudeRate; + +/** creates the action with amplitude, a grid and duration */ ++(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; +/** initializes the action with amplitude, a grid and duration */ +-(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCWaves action */ +@interface CCWaves : CCGrid3DAction +{ + int waves; + float amplitude; + float amplitudeRate; + BOOL vertical; + BOOL horizontal; +} + +/** amplitude */ +@property (nonatomic,readwrite) float amplitude; +/** amplitude rate */ +@property (nonatomic,readwrite) float amplitudeRate; + +/** initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration */ ++(id)actionWithWaves:(int)wav amplitude:(float)amp horizontal:(BOOL)h vertical:(BOOL)v grid:(ccGridSize)gridSize duration:(ccTime)d; +/** creates the action with amplitude, horizontal sin, vertical sin, a grid and duration */ +-(id)initWithWaves:(int)wav amplitude:(float)amp horizontal:(BOOL)h vertical:(BOOL)v grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end + +//////////////////////////////////////////////////////////// + +/** CCTwirl action */ +@interface CCTwirl : CCGrid3DAction +{ + CGPoint position_; + CGPoint positionInPixels_; + int twirls_; + float amplitude_; + float amplitudeRate_; +} + +/** twirl center */ +@property (nonatomic,readwrite) CGPoint position; +/** amplitude */ +@property (nonatomic,readwrite) float amplitude; +/** amplitude rate */ +@property (nonatomic,readwrite) float amplitudeRate; + +/** creates the action with center position, number of twirls, amplitude, a grid size and duration */ ++(id)actionWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; +/** initializes the action with center position, number of twirls, amplitude, a grid size and duration */ +-(id)initWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d; + +@end diff --git a/Classes/cocos2d/CCActionGrid3D.m b/Classes/cocos2d/CCActionGrid3D.m new file mode 100644 index 0000000..1d4a783 --- /dev/null +++ b/Classes/cocos2d/CCActionGrid3D.m @@ -0,0 +1,659 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2009 On-Core + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCActionGrid3D.h" +#import "ccMacros.h" +#import "Support/CGPointExtension.h" + +#pragma mark - +#pragma mark Waves3D + +@implementation CCWaves3D + +@synthesize amplitude; +@synthesize amplitudeRate; + ++(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithWaves:wav amplitude:amp grid:gridSize duration:d] autorelease]; +} + +-(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + waves = wav; + amplitude = amp; + amplitudeRate = 1.0f; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude grid:gridSize_ duration:duration_]; + return copy; +} + + +-(void)update:(ccTime)time +{ + int i, j; + + for( i = 0; i < (gridSize_.x+1); i++ ) + { + for( j = 0; j < (gridSize_.y+1); j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + v.z += (sinf((CGFloat)M_PI*time*waves*2 + (v.y+v.x) * .01f) * amplitude * amplitudeRate); + [self setVertex:ccg(i,j) vertex:v]; + } + } +} +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark FlipX3D + +@implementation CCFlipX3D + ++(id) actionWithDuration:(ccTime)d +{ + return [[[self alloc] initWithSize:ccg(1,1) duration:d] autorelease]; +} + +-(id) initWithDuration:(ccTime)d +{ + return [super initWithSize:ccg(1,1) duration:d]; +} + +-(id)initWithSize:(ccGridSize)gSize duration:(ccTime)d +{ + if ( gSize.x != 1 || gSize.y != 1 ) + { + [NSException raise:@"FlipX3D" format:@"Grid size must be (1,1)"]; + } + + return [super initWithSize:gSize duration:d]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithSize:gridSize_ duration:duration_]; + return copy; +} + + +-(void)update:(ccTime)time +{ + CGFloat angle = (CGFloat)M_PI * time; // 180 degrees + CGFloat mz = sinf( angle ); + angle = angle / 2.0f; // x calculates degrees from 0 to 90 + CGFloat mx = cosf( angle ); + + ccVertex3F v0, v1, v, diff; + + v0 = [self originalVertex:ccg(1,1)]; + v1 = [self originalVertex:ccg(0,0)]; + + CGFloat x0 = v0.x; + CGFloat x1 = v1.x; + CGFloat x; + ccGridSize a, b, c, d; + + if ( x0 > x1 ) + { + // Normal Grid + a = ccg(0,0); + b = ccg(0,1); + c = ccg(1,0); + d = ccg(1,1); + x = x0; + } + else + { + // Reversed Grid + c = ccg(0,0); + d = ccg(0,1); + a = ccg(1,0); + b = ccg(1,1); + x = x1; + } + + diff.x = ( x - x * mx ); + diff.z = fabsf( floorf( (x * mz) / 4.0f ) ); + +// bottom-left + v = [self originalVertex:a]; + v.x = diff.x; + v.z += diff.z; + [self setVertex:a vertex:v]; + +// upper-left + v = [self originalVertex:b]; + v.x = diff.x; + v.z += diff.z; + [self setVertex:b vertex:v]; + +// bottom-right + v = [self originalVertex:c]; + v.x -= diff.x; + v.z -= diff.z; + [self setVertex:c vertex:v]; + +// upper-right + v = [self originalVertex:d]; + v.x -= diff.x; + v.z -= diff.z; + [self setVertex:d vertex:v]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark FlipY3D + +@implementation CCFlipY3D + +-(void)update:(ccTime)time +{ + CGFloat angle = (CGFloat)M_PI * time; // 180 degrees + CGFloat mz = sinf( angle ); + angle = angle / 2.0f; // x calculates degrees from 0 to 90 + CGFloat my = cosf( angle ); + + ccVertex3F v0, v1, v, diff; + + v0 = [self originalVertex:ccg(1,1)]; + v1 = [self originalVertex:ccg(0,0)]; + + CGFloat y0 = v0.y; + CGFloat y1 = v1.y; + CGFloat y; + ccGridSize a, b, c, d; + + if ( y0 > y1 ) + { + // Normal Grid + a = ccg(0,0); + b = ccg(0,1); + c = ccg(1,0); + d = ccg(1,1); + y = y0; + } + else + { + // Reversed Grid + b = ccg(0,0); + a = ccg(0,1); + d = ccg(1,0); + c = ccg(1,1); + y = y1; + } + + diff.y = y - y * my; + diff.z = fabsf( floorf( (y * mz) / 4.0f ) ); + + // bottom-left + v = [self originalVertex:a]; + v.y = diff.y; + v.z += diff.z; + [self setVertex:a vertex:v]; + + // upper-left + v = [self originalVertex:b]; + v.y -= diff.y; + v.z -= diff.z; + [self setVertex:b vertex:v]; + + // bottom-right + v = [self originalVertex:c]; + v.y = diff.y; + v.z += diff.z; + [self setVertex:c vertex:v]; + + // upper-right + v = [self originalVertex:d]; + v.y -= diff.y; + v.z -= diff.z; + [self setVertex:d vertex:v]; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Lens3D + +@implementation CCLens3D + +@synthesize lensEffect=lensEffect_; + ++(id)actionWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithPosition:pos radius:r grid:gridSize duration:d] autorelease]; +} + +-(id)initWithPosition:(CGPoint)pos radius:(float)r grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + position_ = ccp(-1,-1); + self.position = pos; + radius_ = r; + lensEffect_ = 0.7f; + dirty_ = YES; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithPosition:position_ radius:radius_ grid:gridSize_ duration:duration_]; + return copy; +} + +-(void) setPosition:(CGPoint)pos +{ + if( ! CGPointEqualToPoint(pos, position_) ) { + position_ = pos; + positionInPixels_.x = pos.x * CC_CONTENT_SCALE_FACTOR(); + positionInPixels_.y = pos.y * CC_CONTENT_SCALE_FACTOR(); + + dirty_ = YES; + } +} + +-(CGPoint) position +{ + return position_; +} + +-(void)update:(ccTime)time +{ + if ( dirty_ ) + { + int i, j; + + for( i = 0; i < gridSize_.x+1; i++ ) + { + for( j = 0; j < gridSize_.y+1; j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + CGPoint vect = ccpSub(positionInPixels_, ccp(v.x,v.y)); + CGFloat r = ccpLength(vect); + + if ( r < radius_ ) + { + r = radius_ - r; + CGFloat pre_log = r / radius_; + if ( pre_log == 0 ) pre_log = 0.001f; + float l = logf(pre_log) * lensEffect_; + float new_r = expf( l ) * radius_; + + if ( ccpLength(vect) > 0 ) + { + vect = ccpNormalize(vect); + CGPoint new_vect = ccpMult(vect, new_r); + v.z += ccpLength(new_vect) * lensEffect_; + } + } + + [self setVertex:ccg(i,j) vertex:v]; + } + } + + dirty_ = NO; + } +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Ripple3D + +@implementation CCRipple3D + +@synthesize amplitude = amplitude_; +@synthesize amplitudeRate = amplitudeRate_; + ++(id)actionWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithPosition:pos radius:r waves:wav amplitude:amp grid:gridSize duration:d] autorelease]; +} + +-(id)initWithPosition:(CGPoint)pos radius:(float)r waves:(int)wav amplitude:(float)amp grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + self.position = pos; + radius_ = r; + waves_ = wav; + amplitude_ = amp; + amplitudeRate_ = 1.0f; + } + + return self; +} + +-(CGPoint) position +{ + return position_; +} + +-(void) setPosition:(CGPoint)pos +{ + position_ = pos; + positionInPixels_.x = pos.x * CC_CONTENT_SCALE_FACTOR(); + positionInPixels_.y = pos.y * CC_CONTENT_SCALE_FACTOR(); +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithPosition:position_ radius:radius_ waves:waves_ amplitude:amplitude_ grid:gridSize_ duration:duration_]; + return copy; +} + + +-(void)update:(ccTime)time +{ + int i, j; + + for( i = 0; i < (gridSize_.x+1); i++ ) + { + for( j = 0; j < (gridSize_.y+1); j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + CGPoint vect = ccpSub(positionInPixels_, ccp(v.x,v.y)); + CGFloat r = ccpLength(vect); + + if ( r < radius_ ) + { + r = radius_ - r; + CGFloat rate = powf( r / radius_, 2); + v.z += (sinf( time*(CGFloat)M_PI*waves_*2 + r * 0.1f) * amplitude_ * amplitudeRate_ * rate ); + } + + [self setVertex:ccg(i,j) vertex:v]; + } + } +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Shaky3D + +@implementation CCShaky3D + ++(id)actionWithRange:(int)range shakeZ:(BOOL)sz grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithRange:range shakeZ:sz grid:gridSize duration:d] autorelease]; +} + +-(id)initWithRange:(int)range shakeZ:(BOOL)sz grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + randrange = range; + shakeZ = sz; + } + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithRange:randrange shakeZ:shakeZ grid:gridSize_ duration:duration_]; + return copy; +} + +-(void)update:(ccTime)time +{ + int i, j; + + for( i = 0; i < (gridSize_.x+1); i++ ) + { + for( j = 0; j < (gridSize_.y+1); j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + v.x += ( rand() % (randrange*2) ) - randrange; + v.y += ( rand() % (randrange*2) ) - randrange; + if( shakeZ ) + v.z += ( rand() % (randrange*2) ) - randrange; + + [self setVertex:ccg(i,j) vertex:v]; + } + } +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Liquid + +@implementation CCLiquid + +@synthesize amplitude; +@synthesize amplitudeRate; + ++(id)actionWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithWaves:wav amplitude:amp grid:gridSize duration:d] autorelease]; +} + +-(id)initWithWaves:(int)wav amplitude:(float)amp grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + waves = wav; + amplitude = amp; + amplitudeRate = 1.0f; + } + + return self; +} + +-(void)update:(ccTime)time +{ + int i, j; + + for( i = 1; i < gridSize_.x; i++ ) + { + for( j = 1; j < gridSize_.y; j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + v.x = (v.x + (sinf(time*(CGFloat)M_PI*waves*2 + v.x * .01f) * amplitude * amplitudeRate)); + v.y = (v.y + (sinf(time*(CGFloat)M_PI*waves*2 + v.y * .01f) * amplitude * amplitudeRate)); + [self setVertex:ccg(i,j) vertex:v]; + } + } +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude grid:gridSize_ duration:duration_]; + return copy; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Waves + +@implementation CCWaves + +@synthesize amplitude; +@synthesize amplitudeRate; + ++(id)actionWithWaves:(int)wav amplitude:(float)amp horizontal:(BOOL)h vertical:(BOOL)v grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithWaves:wav amplitude:amp horizontal:h vertical:v grid:gridSize duration:d] autorelease]; +} + +-(id)initWithWaves:(int)wav amplitude:(float)amp horizontal:(BOOL)h vertical:(BOOL)v grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + waves = wav; + amplitude = amp; + amplitudeRate = 1.0f; + horizontal = h; + vertical = v; + } + + return self; +} + +-(void)update:(ccTime)time +{ + int i, j; + + for( i = 0; i < (gridSize_.x+1); i++ ) + { + for( j = 0; j < (gridSize_.y+1); j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + + if ( vertical ) + v.x = (v.x + (sinf(time*(CGFloat)M_PI*waves*2 + v.y * .01f) * amplitude * amplitudeRate)); + + if ( horizontal ) + v.y = (v.y + (sinf(time*(CGFloat)M_PI*waves*2 + v.x * .01f) * amplitude * amplitudeRate)); + + [self setVertex:ccg(i,j) vertex:v]; + } + } +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithWaves:waves amplitude:amplitude horizontal:horizontal vertical:vertical grid:gridSize_ duration:duration_]; + return copy; +} + +@end + +//////////////////////////////////////////////////////////// + +#pragma mark - +#pragma mark Twirl + +@implementation CCTwirl + +@synthesize amplitude = amplitude_; +@synthesize amplitudeRate = amplitudeRate_; + ++(id)actionWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGridSize)gridSize duration:(ccTime)d +{ + return [[[self alloc] initWithPosition:pos twirls:t amplitude:amp grid:gridSize duration:d] autorelease]; +} + +-(id)initWithPosition:(CGPoint)pos twirls:(int)t amplitude:(float)amp grid:(ccGridSize)gSize duration:(ccTime)d +{ + if ( (self = [super initWithSize:gSize duration:d]) ) + { + self.position = pos; + twirls_ = t; + amplitude_ = amp; + amplitudeRate_ = 1.0f; + } + + return self; +} + +-(void) setPosition:(CGPoint)pos +{ + position_ = pos; + positionInPixels_.x = pos.x * CC_CONTENT_SCALE_FACTOR(); + positionInPixels_.y = pos.y * CC_CONTENT_SCALE_FACTOR(); +} + +-(CGPoint) position +{ + return position_; +} + +-(void)update:(ccTime)time +{ + int i, j; + CGPoint c = positionInPixels_; + + for( i = 0; i < (gridSize_.x+1); i++ ) + { + for( j = 0; j < (gridSize_.y+1); j++ ) + { + ccVertex3F v = [self originalVertex:ccg(i,j)]; + + CGPoint avg = ccp(i-(gridSize_.x/2.0f), j-(gridSize_.y/2.0f)); + CGFloat r = ccpLength( avg ); + + CGFloat amp = 0.1f * amplitude_ * amplitudeRate_; + CGFloat a = r * cosf( (CGFloat)M_PI/2.0f + time * (CGFloat)M_PI * twirls_ * 2 ) * amp; + + float cosA = cosf(a); + float sinA = sinf(a); + + CGPoint d = { + sinA * (v.y-c.y) + cosA * (v.x-c.x), + cosA * (v.y-c.y) - sinA * (v.x-c.x) + }; + + v.x = c.x + d.x; + v.y = c.y + d.y; + + [self setVertex:ccg(i,j) vertex:v]; + } + } +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCGridAction *copy = [[[self class] allocWithZone:zone] initWithPosition:position_ + twirls:twirls_ + amplitude:amplitude_ + grid:gridSize_ + duration:duration_]; + return copy; +} + + +@end diff --git a/Classes/cocos2d/CCActionInstant.h b/Classes/cocos2d/CCActionInstant.h new file mode 100644 index 0000000..40eb15f --- /dev/null +++ b/Classes/cocos2d/CCActionInstant.h @@ -0,0 +1,197 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCAction.h" + +/** Instant actions are immediate actions. They don't have a duration like + the CCIntervalAction actions. +*/ +@interface CCActionInstant : CCFiniteTimeAction +{ +} +@end + +/** Show the node + */ + @interface CCShow : CCActionInstant +{ +} +@end + +/** Hide the node + */ +@interface CCHide : CCActionInstant +{ +} +@end + +/** Toggles the visibility of a node + */ +@interface CCToggleVisibility : CCActionInstant +{ +} +@end + +/** Flips the sprite horizontally + @since v0.99.0 + */ +@interface CCFlipX : CCActionInstant +{ + BOOL flipX; +} ++(id) actionWithFlipX:(BOOL)x; +-(id) initWithFlipX:(BOOL)x; +@end + +/** Flips the sprite vertically + @since v0.99.0 + */ +@interface CCFlipY : CCActionInstant +{ + BOOL flipY; +} ++(id) actionWithFlipY:(BOOL)y; +-(id) initWithFlipY:(BOOL)y; +@end + +/** Places the node in a certain position + */ +@interface CCPlace : CCActionInstant +{ + CGPoint position; +} +/** creates a Place action with a position */ ++(id) actionWithPosition: (CGPoint) pos; +/** Initializes a Place action with a position */ +-(id) initWithPosition: (CGPoint) pos; +@end + +/** Calls a 'callback' + */ +@interface CCCallFunc : CCActionInstant +{ + id targetCallback_; + SEL selector_; +} +/** creates the action with the callback */ ++(id) actionWithTarget: (id) t selector:(SEL) s; +/** initializes the action with the callback */ +-(id) initWithTarget: (id) t selector:(SEL) s; +/** exeuctes the callback */ +-(void) execute; +@end + +/** Calls a 'callback' with the node as the first argument. + N means Node + */ +@interface CCCallFuncN : CCCallFunc +{ +} +@end + +typedef void (*CC_CALLBACK_ND)(id, SEL, id, void *); +/** Calls a 'callback' with the node as the first argument and the 2nd argument is data. + * ND means: Node and Data. Data is void *, so it could be anything. + */ +@interface CCCallFuncND : CCCallFuncN +{ + void *data_; + CC_CALLBACK_ND callbackMethod_; +} + +/** Invocation object that has the target#selector and the parameters */ +@property (nonatomic,readwrite) CC_CALLBACK_ND callbackMethod; + +/** creates the action with the callback and the data to pass as an argument */ ++(id) actionWithTarget: (id) t selector:(SEL) s data:(void*)d; +/** initializes the action with the callback and the data to pass as an argument */ +-(id) initWithTarget:(id) t selector:(SEL) s data:(void*) d; +@end + +/** Calls a 'callback' with an object as the first argument. + O means Object. + @since v0.99.5 + */ +@interface CCCallFuncO : CCCallFunc +{ + id object_; +} +/** creates the action with the callback and the object to pass as an argument */ ++(id) actionWithTarget: (id) t selector:(SEL) s object:(id)object; +/** initializes the action with the callback and the object to pass as an argument */ +-(id) initWithTarget:(id) t selector:(SEL) s object:(id)object; + +@end + +#pragma mark Blocks Support + +#if NS_BLOCKS_AVAILABLE + +/** Executes a callback using a block. + */ +@interface CCCallBlock : CCActionInstant +{ + void (^block_)(); +} + +/** creates the action with the specified block, to be used as a callback. + The block will be "copied". + */ ++(id) actionWithBlock:(void(^)())block; + +/** initialized the action with the specified block, to be used as a callback. + The block will be "copied". + */ +-(id) initWithBlock:(void(^)())block; + +/** executes the callback */ +-(void) execute; +@end + +@class CCNode; + +/** Executes a callback using a block with a single CCNode parameter. + */ +@interface CCCallBlockN : CCActionInstant +{ + void (^block_)(CCNode *); +} + +/** creates the action with the specified block, to be used as a callback. + The block will be "copied". + */ ++(id) actionWithBlock:(void(^)(CCNode *node))block; + +/** initialized the action with the specified block, to be used as a callback. + The block will be "copied". + */ +-(id) initWithBlock:(void(^)(CCNode *node))block; + +/** executes the callback */ +-(void) execute; +@end + +#endif diff --git a/Classes/cocos2d/CCActionInstant.m b/Classes/cocos2d/CCActionInstant.m new file mode 100644 index 0000000..2b9072c --- /dev/null +++ b/Classes/cocos2d/CCActionInstant.m @@ -0,0 +1,472 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCBlockSupport.h" +#import "CCActionInstant.h" +#import "CCNode.h" +#import "CCSprite.h" + + +// +// InstantAction +// +#pragma mark CCActionInstant + +@implementation CCActionInstant + +-(id) init +{ + if( (self=[super init]) ) + duration_ = 0; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] init]; + return copy; +} + +- (BOOL) isDone +{ + return YES; +} + +-(void) step: (ccTime) dt +{ + [self update: 1]; +} + +-(void) update: (ccTime) t +{ + // ignore +} + +-(CCFiniteTimeAction*) reverse +{ + return [[self copy] autorelease]; +} +@end + +// +// Show +// +#pragma mark CCShow + +@implementation CCShow +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).visible = YES; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCHide action]; +} +@end + +// +// Hide +// +#pragma mark CCHide + +@implementation CCHide +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).visible = NO; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCShow action]; +} +@end + +// +// ToggleVisibility +// +#pragma mark CCToggleVisibility + +@implementation CCToggleVisibility +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).visible = !((CCNode *)target_).visible; +} +@end + +// +// FlipX +// +#pragma mark CCFlipX + +@implementation CCFlipX ++(id) actionWithFlipX:(BOOL)x +{ + return [[[self alloc] initWithFlipX:x] autorelease]; +} + +-(id) initWithFlipX:(BOOL)x +{ + if(( self=[super init])) + flipX = x; + + return self; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [(CCSprite*)aTarget setFlipX:flipX]; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCFlipX actionWithFlipX:!flipX]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithFlipX:flipX]; + return copy; +} +@end + +// +// FlipY +// +#pragma mark CCFlipY + +@implementation CCFlipY ++(id) actionWithFlipY:(BOOL)y +{ + return [[[self alloc] initWithFlipY:y] autorelease]; +} + +-(id) initWithFlipY:(BOOL)y +{ + if(( self=[super init])) + flipY = y; + + return self; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [(CCSprite*)aTarget setFlipY:flipY]; +} + +-(CCFiniteTimeAction*) reverse +{ + return [CCFlipY actionWithFlipY:!flipY]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithFlipY:flipY]; + return copy; +} +@end + + +// +// Place +// +#pragma mark CCPlace + +@implementation CCPlace ++(id) actionWithPosition: (CGPoint) pos +{ + return [[[self alloc]initWithPosition:pos]autorelease]; +} + +-(id) initWithPosition: (CGPoint) pos +{ + if( (self=[super init]) ) + position = pos; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithPosition: position]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + ((CCNode *)target_).position = position; +} + +@end + +// +// CallFunc +// +#pragma mark CCCallFunc + +@implementation CCCallFunc ++(id) actionWithTarget: (id) t selector:(SEL) s +{ + return [[[self alloc] initWithTarget: t selector: s] autorelease]; +} + +-(id) initWithTarget: (id) t selector:(SEL) s +{ + if( (self=[super init]) ) { + targetCallback_ = [t retain]; + selector_ = s; + } + return self; +} + +-(NSString*) description +{ + return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i | target = %@ | selector = %@>", + [self class], + self, + tag_, + [targetCallback_ class], + NSStringFromSelector(selector_) + ]; +} + +-(void) dealloc +{ + [targetCallback_ release]; + [super dealloc]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [self execute]; +} + +-(void) execute +{ + [targetCallback_ performSelector:selector_]; +} +@end + +// +// CallFuncN +// +#pragma mark CCCallFuncN + +@implementation CCCallFuncN + +-(void) execute +{ + [targetCallback_ performSelector:selector_ withObject:target_]; +} +@end + +// +// CallFuncND +// +#pragma mark CCCallFuncND + +@implementation CCCallFuncND + +@synthesize callbackMethod = callbackMethod_; + ++(id) actionWithTarget:(id)t selector:(SEL)s data:(void*)d +{ + return [[[self alloc] initWithTarget:t selector:s data:d] autorelease]; +} + +-(id) initWithTarget:(id)t selector:(SEL)s data:(void*)d +{ + if( (self=[super initWithTarget:t selector:s]) ) { + data_ = d; + +#if COCOS2D_DEBUG + NSMethodSignature * sig = [t methodSignatureForSelector:s]; // added + NSAssert(sig !=0 , @"Signature not found for selector - does it have the following form? -(void)name:(id)sender data:(void*)data"); +#endif + callbackMethod_ = (CC_CALLBACK_ND) [t methodForSelector:s]; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_ data:data_]; + return copy; +} + +-(void) dealloc +{ + // nothing to dealloc really. Everything is dealloc on super (CCCallFuncN) + [super dealloc]; +} + +-(void) execute +{ + callbackMethod_(targetCallback_,selector_,target_, data_); +} +@end + +@implementation CCCallFuncO + ++(id) actionWithTarget: (id) t selector:(SEL) s object:(id)object +{ + return [[[self alloc] initWithTarget:t selector:s object:object] autorelease]; +} + +-(id) initWithTarget:(id) t selector:(SEL) s object:(id)object +{ + if( (self=[super initWithTarget:t selector:s] ) ) + object_ = [object retain]; + + return self; +} + +- (void) dealloc +{ + [object_ release]; + [super dealloc]; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithTarget:targetCallback_ selector:selector_ object:object_]; + return copy; +} + + +-(void) execute +{ + [targetCallback_ performSelector:selector_ withObject:object_]; +} + +@end + + +#pragma mark - +#pragma mark Blocks + +#if NS_BLOCKS_AVAILABLE + +#pragma mark CCCallBlock + +@implementation CCCallBlock + ++(id) actionWithBlock:(void(^)())block +{ + return [[[self alloc] initWithBlock:block] autorelease]; +} + +-(id) initWithBlock:(void(^)())block +{ + if ((self = [super init])) + block_ = [block copy]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithBlock:block_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [self execute]; +} + +-(void) execute +{ + block_(); +} + +-(void) dealloc +{ + [block_ release]; + [super dealloc]; +} + +@end + +#pragma mark CCCallBlockN + +@implementation CCCallBlockN + ++(id) actionWithBlock:(void(^)(CCNode *node))block +{ + return [[[self alloc] initWithBlock:block] autorelease]; +} + +-(id) initWithBlock:(void(^)(CCNode *node))block +{ + if ((self = [super init])) + block_ = [block copy]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCActionInstant *copy = [[[self class] allocWithZone: zone] initWithBlock:block_]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [self execute]; +} + +-(void) execute +{ + block_(target_); +} + +-(void) dealloc +{ + [block_ release]; + [super dealloc]; +} + +@end + + +#endif // NS_BLOCKS_AVAILABLE diff --git a/Classes/cocos2d/CCActionInterval.h b/Classes/cocos2d/CCActionInterval.h new file mode 100644 index 0000000..035bd50 --- /dev/null +++ b/Classes/cocos2d/CCActionInterval.h @@ -0,0 +1,384 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + +#import "CCNode.h" +#import "CCAction.h" +#import "CCProtocols.h" + +#include + +/** An interval action is an action that takes place within a certain period of time. +It has an start time, and a finish time. The finish time is the parameter +duration plus the start time. + +These CCActionInterval actions have some interesting properties, like: + - They can run normally (default) + - They can run reversed with the reverse method + - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions. + +For example, you can simulate a Ping Pong effect running the action normally and +then running it again in Reverse mode. + +Example: + + CCAction * pingPongAction = [CCSequence actions: action, [action reverse], nil]; +*/ +@interface CCActionInterval: CCFiniteTimeAction +{ + ccTime elapsed_; + BOOL firstTick_; +} + +/** how many seconds had elapsed since the actions started to run. */ +@property (nonatomic,readonly) ccTime elapsed; + +/** creates the action */ ++(id) actionWithDuration: (ccTime) d; +/** initializes the action */ +-(id) initWithDuration: (ccTime) d; +/** returns YES if the action has finished */ +-(BOOL) isDone; +/** returns a reversed action */ +- (CCActionInterval*) reverse; +@end + +/** Runs actions sequentially, one after another + */ +@interface CCSequence : CCActionInterval +{ + CCFiniteTimeAction *actions[2]; + ccTime split; + int last; +} +/** helper contructor to create an array of sequenceable actions */ ++(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION; +/** creates the action */ ++(id) actionOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo; +/** initializes the action */ +-(id) initOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo; +@end + + +/** Repeats an action a number of times. + * To repeat an action forever use the CCRepeatForever action. + */ +@interface CCRepeat : CCActionInterval +{ + unsigned int times_; + unsigned int total_; + CCFiniteTimeAction *other_; +} +/** creates a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) */ ++(id) actionWithAction:(CCFiniteTimeAction*)action times: (unsigned int)times; +/** initializes a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) */ +-(id) initWithAction:(CCFiniteTimeAction*)action times: (unsigned int)times; +@end + +/** Spawn a new action immediately + */ +@interface CCSpawn : CCActionInterval +{ + CCFiniteTimeAction *one; + CCFiniteTimeAction *two; +} +/** helper constructor to create an array of spawned actions */ ++(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION; +/** creates the Spawn action */ ++(id) actionOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two; +/** initializes the Spawn action with the 2 actions to spawn */ +-(id) initOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two; +@end + +/** Rotates a CCNode object to a certain angle by modifying it's + rotation attribute. + The direction will be decided by the shortest angle. +*/ +@interface CCRotateTo : CCActionInterval +{ + float dstAngle; + float startAngle; + float diffAngle; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)duration angle:(float)angle; +/** initializes the action */ +-(id) initWithDuration:(ccTime)duration angle:(float)angle; +@end + +/** Rotates a CCNode object clockwise a number of degrees by modiying it's rotation attribute. +*/ +@interface CCRotateBy : CCActionInterval +{ + float angle; + float startAngle; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)duration angle:(float)deltaAngle; +/** initializes the action */ +-(id) initWithDuration:(ccTime)duration angle:(float)deltaAngle; +@end + +/** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute. +*/ +@interface CCMoveTo : CCActionInterval +{ + CGPoint endPosition; + CGPoint startPosition; + CGPoint delta; +} +/** creates the action */ ++(id) actionWithDuration:(ccTime)duration position:(CGPoint)position; +/** initializes the action */ +-(id) initWithDuration:(ccTime)duration position:(CGPoint)position; +@end + +/** Moves a CCNode object x,y pixels by modifying it's position attribute. + x and y are relative to the position of the object. + Duration is is seconds. +*/ +@interface CCMoveBy : CCMoveTo +{ +} +/** creates the action */ ++(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition; +/** initializes the action */ +-(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition; +@end + +/** Moves a CCNode object simulating a parabolic jump movement by modifying it's position attribute. +*/ + @interface CCJumpBy : CCActionInterval +{ + CGPoint startPosition; + CGPoint delta; + ccTime height; + int jumps; +} +/** creates the action */ ++(id) actionWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(int)jumps; +/** initializes the action */ +-(id) initWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(int)jumps; +@end + +/** Moves a CCNode object to a parabolic position simulating a jump movement by modifying it's position attribute. +*/ + @interface CCJumpTo : CCJumpBy +{ +} +@end + +/** bezier configuration structure + */ +typedef struct _ccBezierConfig { + //! end position of the bezier + CGPoint endPosition; + //! Bezier control point 1 + CGPoint controlPoint_1; + //! Bezier control point 2 + CGPoint controlPoint_2; +} ccBezierConfig; + +/** An action that moves the target with a cubic Bezier curve by a certain distance. + */ +@interface CCBezierBy : CCActionInterval +{ + ccBezierConfig config; + CGPoint startPosition; +} + +/** creates the action with a duration and a bezier configuration */ ++(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c; + +/** initializes the action with a duration and a bezier configuration */ +-(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c; +@end + +/** An action that moves the target with a cubic Bezier curve to a destination point. + @since v0.8.2 + */ +@interface CCBezierTo : CCBezierBy +{ +} +@end + +/** Scales a CCNode object to a zoom factor by modifying it's scale attribute. + @warning This action doesn't support "reverse" + */ +@interface CCScaleTo : CCActionInterval +{ + float scaleX; + float scaleY; + float startScaleX; + float startScaleY; + float endScaleX; + float endScaleY; + float deltaX; + float deltaY; +} +/** creates the action with the same scale factor for X and Y */ ++(id) actionWithDuration: (ccTime)duration scale:(float) s; +/** initializes the action with the same scale factor for X and Y */ +-(id) initWithDuration: (ccTime)duration scale:(float) s; +/** creates the action with and X factor and a Y factor */ ++(id) actionWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy; +/** initializes the action with and X factor and a Y factor */ +-(id) initWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy; +@end + +/** Scales a CCNode object a zoom factor by modifying it's scale attribute. +*/ +@interface CCScaleBy : CCScaleTo +{ +} +@end + +/** Blinks a CCNode object by modifying it's visible attribute +*/ +@interface CCBlink : CCActionInterval +{ + int times; +} +/** creates the action */ ++(id) actionWithDuration: (ccTime)duration blinks:(unsigned int)blinks; +/** initilizes the action */ +-(id) initWithDuration: (ccTime)duration blinks:(unsigned int)blinks; +@end + +/** Fades In an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 0 to 255. + The "reverse" of this action is FadeOut + */ +@interface CCFadeIn : CCActionInterval +{ +} +@end + +/** Fades Out an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 255 to 0. + The "reverse" of this action is FadeIn +*/ +@interface CCFadeOut : CCActionInterval +{ +} +@end + +/** Fades an object that implements the CCRGBAProtocol protocol. It modifies the opacity from the current value to a custom one. + @warning This action doesn't support "reverse" + */ +@interface CCFadeTo : CCActionInterval +{ + GLubyte toOpacity; + GLubyte fromOpacity; +} +/** creates an action with duration and opactiy */ ++(id) actionWithDuration:(ccTime)duration opacity:(GLubyte)opactiy; +/** initializes the action with duration and opacity */ +-(id) initWithDuration:(ccTime)duration opacity:(GLubyte)opacity; +@end + +/** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one. + @warning This action doesn't support "reverse" + @since v0.7.2 +*/ +@interface CCTintTo : CCActionInterval +{ + ccColor3B to; + ccColor3B from; +} +/** creates an action with duration and color */ ++(id) actionWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue; +/** initializes the action with duration and color */ +-(id) initWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue; +@end + +/** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one. + @since v0.7.2 + */ +@interface CCTintBy : CCActionInterval +{ + GLshort deltaR, deltaG, deltaB; + GLshort fromR, fromG, fromB; +} +/** creates an action with duration and color */ ++(id) actionWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue; +/** initializes the action with duration and color */ +-(id) initWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue; +@end + +/** Delays the action a certain amount of seconds +*/ +@interface CCDelayTime : CCActionInterval +{ +} +@end + +/** Executes an action in reverse order, from time=duration to time=0 + + @warning Use this action carefully. This action is not + sequenceable. Use it as the default "reversed" method + of your own actions, but using it outside the "reversed" + scope is not recommended. +*/ +@interface CCReverseTime : CCActionInterval +{ + CCFiniteTimeAction * other; +} +/** creates the action */ ++(id) actionWithAction: (CCFiniteTimeAction*) action; +/** initializes the action */ +-(id) initWithAction: (CCFiniteTimeAction*) action; +@end + + +@class CCAnimation; +@class CCTexture2D; +/** Animates a sprite given the name of an Animation */ +@interface CCAnimate : CCActionInterval +{ + CCAnimation *animation_; + id origFrame; + BOOL restoreOriginalFrame; +} +/** animation used for the animage */ +@property (readwrite,nonatomic,retain) CCAnimation * animation; + +/** creates the action with an Animation and will restore the original frame when the animation is over */ ++(id) actionWithAnimation:(CCAnimation*) a; +/** initializes the action with an Animation and will restore the original frame when the animtion is over */ +-(id) initWithAnimation:(CCAnimation*) a; +/** creates the action with an Animation */ ++(id) actionWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b; +/** initializes the action with an Animation */ +-(id) initWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b; +/** creates an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not. + The 'delay' parameter of the animation will be overrided by the duration parameter. + @since v0.99.0 + */ ++(id) actionWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b; +/** initializes an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not. + The 'delay' parameter of the animation will be overrided by the duration parameter. + @since v0.99.0 + */ +-(id) initWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b; +@end \ No newline at end of file diff --git a/Classes/cocos2d/CCActionInterval.m b/Classes/cocos2d/CCActionInterval.m new file mode 100644 index 0000000..148bb0a --- /dev/null +++ b/Classes/cocos2d/CCActionInterval.m @@ -0,0 +1,1213 @@ +/* + * cocos2d for iPhone: http://www.cocos2d-iphone.org + * + * Copyright (c) 2008-2010 Ricardo Quesada + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + + + +#import "CCActionInterval.h" +#import "CCSprite.h" +#import "CCSpriteFrame.h" +#import "CCAnimation.h" +#import "CCNode.h" +#import "Support/CGPointExtension.h" + +// +// IntervalAction +// +#pragma mark - +#pragma mark IntervalAction +@implementation CCActionInterval + +@synthesize elapsed = elapsed_; + +-(id) init +{ + NSAssert(NO, @"IntervalActionInit: Init not supported. Use InitWithDuration"); + [self release]; + return nil; +} + ++(id) actionWithDuration: (ccTime) d +{ + return [[[self alloc] initWithDuration:d ] autorelease]; +} + +-(id) initWithDuration: (ccTime) d +{ + if( (self=[super init]) ) { + duration_ = d; + + // prevent division by 0 + // This comparison could be in step:, but it might decrease the performance + // by 3% in heavy based action games. + if( duration_ == 0 ) + duration_ = FLT_EPSILON; + elapsed_ = 0; + firstTick_ = YES; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] ]; + return copy; +} + +- (BOOL) isDone +{ + return (elapsed_ >= duration_); +} + +-(void) step: (ccTime) dt +{ + if( firstTick_ ) { + firstTick_ = NO; + elapsed_ = 0; + } else + elapsed_ += dt; + + [self update: MIN(1, elapsed_/duration_)]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + elapsed_ = 0.0f; + firstTick_ = YES; +} + +- (CCActionInterval*) reverse +{ + NSAssert(NO, @"CCIntervalAction: reverse not implemented."); + return nil; +} +@end + +// +// Sequence +// +#pragma mark - +#pragma mark Sequence +@implementation CCSequence ++(id) actionOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two +{ + return [[[self alloc] initOne:one two:two ] autorelease]; +} + ++(id) actions: (CCFiniteTimeAction*) action1, ... +{ + va_list params; + va_start(params,action1); + + CCFiniteTimeAction *now; + CCFiniteTimeAction *prev = action1; + + while( action1 ) { + now = va_arg(params,CCFiniteTimeAction*); + if ( now ) + prev = [self actionOne: prev two: now]; + else + break; + } + va_end(params); + return prev; +} + +-(id) initOne: (CCFiniteTimeAction*) one_ two: (CCFiniteTimeAction*) two_ +{ + NSAssert( one_!=nil, @"Sequence: argument one must be non-nil"); + NSAssert( two_!=nil, @"Sequence: argument two must be non-nil"); + + CCFiniteTimeAction *one = one_; + CCFiniteTimeAction *two = two_; + + ccTime d = [one duration] + [two duration]; + [super initWithDuration: d]; + + actions[0] = [one retain]; + actions[1] = [two retain]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initOne:[[actions[0] copy] autorelease] two:[[actions[1] copy] autorelease] ]; + return copy; +} + +-(void) dealloc +{ + [actions[0] release]; + [actions[1] release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + split = [actions[0] duration] / duration_; + last = -1; +} + +-(void) stop +{ + [actions[0] stop]; + [actions[1] stop]; + [super stop]; +} + +-(void) update: (ccTime) t +{ + int found = 0; + ccTime new_t = 0.0f; + + if( t >= split ) { + found = 1; + if ( split == 1 ) + new_t = 1; + else + new_t = (t-split) / (1 - split ); + } else { + found = 0; + if( split != 0 ) + new_t = t / split; + else + new_t = 1; + } + + if (last == -1 && found==1) { + [actions[0] startWithTarget:target_]; + [actions[0] update:1.0f]; + [actions[0] stop]; + } + + if (last != found ) { + if( last != -1 ) { + [actions[last] update: 1.0f]; + [actions[last] stop]; + } + [actions[found] startWithTarget:target_]; + } + [actions[found] update: new_t]; + last = found; +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionOne: [actions[1] reverse] two: [actions[0] reverse ] ]; +} +@end + +// +// Repeat +// +#pragma mark - +#pragma mark CCRepeat +@implementation CCRepeat ++(id) actionWithAction:(CCFiniteTimeAction*)action times:(unsigned int)times +{ + return [[[self alloc] initWithAction:action times:times] autorelease]; +} + +-(id) initWithAction:(CCFiniteTimeAction*)action times:(unsigned int)times +{ + ccTime d = [action duration] * times; + + if( (self=[super initWithDuration: d ]) ) { + times_ = times; + other_ = [action retain]; + + total_ = 0; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone:zone] initWithAction:[[other_ copy] autorelease] times:times_]; + return copy; +} + +-(void) dealloc +{ + [other_ release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + total_ = 0; + [super startWithTarget:aTarget]; + [other_ startWithTarget:aTarget]; +} + +-(void) stop +{ + [other_ stop]; + [super stop]; +} + + +// issue #80. Instead of hooking step:, hook update: since it can be called by any +// container action like Repeat, Sequence, AccelDeccel, etc.. +-(void) update:(ccTime) dt +{ + ccTime t = dt * times_; + if( t > total_+1 ) { + [other_ update:1.0f]; + total_++; + [other_ stop]; + [other_ startWithTarget:target_]; + + // repeat is over ? + if( total_== times_ ) + // so, set it in the original position + [other_ update:0]; + else { + // no ? start next repeat with the right update + // to prevent jerk (issue #390) + [other_ update: t-total_]; + } + + } else { + + float r = fmodf(t, 1.0f); + + // fix last repeat position + // else it could be 0. + if( dt== 1.0f) { + r = 1.0f; + total_++; // this is the added line + } + [other_ update: MIN(r,1)]; + } +} + +-(BOOL) isDone +{ + return ( total_ == times_ ); +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionWithAction:[other_ reverse] times:times_]; +} +@end + +// +// Spawn +// +#pragma mark - +#pragma mark Spawn + +@implementation CCSpawn ++(id) actions: (CCFiniteTimeAction*) action1, ... +{ + va_list params; + va_start(params,action1); + + CCFiniteTimeAction *now; + CCFiniteTimeAction *prev = action1; + + while( action1 ) { + now = va_arg(params,CCFiniteTimeAction*); + if ( now ) + prev = [self actionOne: prev two: now]; + else + break; + } + va_end(params); + return prev; +} + ++(id) actionOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two +{ + return [[[self alloc] initOne:one two:two ] autorelease]; +} + +-(id) initOne: (CCFiniteTimeAction*) one_ two: (CCFiniteTimeAction*) two_ +{ + NSAssert( one_!=nil, @"Spawn: argument one must be non-nil"); + NSAssert( two_!=nil, @"Spawn: argument two must be non-nil"); + + ccTime d1 = [one_ duration]; + ccTime d2 = [two_ duration]; + + [super initWithDuration: fmaxf(d1,d2)]; + + one = one_; + two = two_; + + if( d1 > d2 ) + two = [CCSequence actionOne: two_ two:[CCDelayTime actionWithDuration: (d1-d2)] ]; + else if( d1 < d2) + one = [CCSequence actionOne: one_ two: [CCDelayTime actionWithDuration: (d2-d1)] ]; + + [one retain]; + [two retain]; + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initOne: [[one copy] autorelease] two: [[two copy] autorelease] ]; + return copy; +} + +-(void) dealloc +{ + [one release]; + [two release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [one startWithTarget:target_]; + [two startWithTarget:target_]; +} + +-(void) stop +{ + [one stop]; + [two stop]; + [super stop]; +} + +-(void) update: (ccTime) t +{ + [one update:t]; + [two update:t]; +} + +- (CCActionInterval *) reverse +{ + return [[self class] actionOne: [one reverse] two: [two reverse ] ]; +} +@end + +// +// RotateTo +// +#pragma mark - +#pragma mark RotateTo + +@implementation CCRotateTo ++(id) actionWithDuration: (ccTime) t angle:(float) a +{ + return [[[self alloc] initWithDuration:t angle:a ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t angle:(float) a +{ + if( (self=[super initWithDuration: t]) ) + dstAngle = a; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] angle: dstAngle]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + + startAngle = [target_ rotation]; + if (startAngle > 0) + startAngle = fmodf(startAngle, 360.0f); + else + startAngle = fmodf(startAngle, -360.0f); + + diffAngle = dstAngle - startAngle; + if (diffAngle > 180) + diffAngle -= 360; + if (diffAngle < -180) + diffAngle += 360; +} +-(void) update: (ccTime) t +{ + [target_ setRotation: startAngle + diffAngle * t]; +} +@end + + +// +// RotateBy +// +#pragma mark - +#pragma mark RotateBy + +@implementation CCRotateBy ++(id) actionWithDuration: (ccTime) t angle:(float) a +{ + return [[[self alloc] initWithDuration:t angle:a ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t angle:(float) a +{ + if( (self=[super initWithDuration: t]) ) + angle = a; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] angle: angle]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + startAngle = [target_ rotation]; +} + +-(void) update: (ccTime) t +{ + // XXX: shall I add % 360 + [target_ setRotation: (startAngle + angle * t )]; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ angle:-angle]; +} + +@end + +// +// MoveTo +// +#pragma mark - +#pragma mark MoveTo + +@implementation CCMoveTo ++(id) actionWithDuration: (ccTime) t position: (CGPoint) p +{ + return [[[self alloc] initWithDuration:t position:p ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t position: (CGPoint) p +{ + if( (self=[super initWithDuration: t]) ) + endPosition = p; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: endPosition]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + startPosition = [(CCNode*)target_ position]; + delta = ccpSub( endPosition, startPosition ); +} + +-(void) update: (ccTime) t +{ + [target_ setPosition: ccp( (startPosition.x + delta.x * t ), (startPosition.y + delta.y * t ) )]; +} +@end + +// +// MoveBy +// +#pragma mark - +#pragma mark MoveBy + +@implementation CCMoveBy ++(id) actionWithDuration: (ccTime) t position: (CGPoint) p +{ + return [[[self alloc] initWithDuration:t position:p ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t position: (CGPoint) p +{ + if( (self=[super initWithDuration: t]) ) + delta = p; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: delta]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + CGPoint dTmp = delta; + [super startWithTarget:aTarget]; + delta = dTmp; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ position:ccp( -delta.x, -delta.y)]; +} +@end + +// +// JumpBy +// +#pragma mark - +#pragma mark JumpBy + +@implementation CCJumpBy ++(id) actionWithDuration: (ccTime) t position: (CGPoint) pos height: (ccTime) h jumps:(int)j +{ + return [[[self alloc] initWithDuration: t position: pos height: h jumps:j] autorelease]; +} + +-(id) initWithDuration: (ccTime) t position: (CGPoint) pos height: (ccTime) h jumps:(int)j +{ + if( (self=[super initWithDuration:t]) ) { + delta = pos; + height = h; + jumps = j; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: delta height:height jumps:jumps]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + startPosition = [(CCNode*)target_ position]; +} + +-(void) update: (ccTime) t +{ + // Sin jump. Less realistic +// ccTime y = height * fabsf( sinf(t * (CGFloat)M_PI * jumps ) ); +// y += delta.y * t; +// ccTime x = delta.x * t; +// [target setPosition: ccp( startPosition.x + x, startPosition.y + y )]; + + // parabolic jump (since v0.8.2) + ccTime frac = fmodf( t * jumps, 1.0f ); + ccTime y = height * 4 * frac * (1 - frac); + y += delta.y * t; + ccTime x = delta.x * t; + [target_ setPosition: ccp( startPosition.x + x, startPosition.y + y )]; + +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ position: ccp(-delta.x,-delta.y) height: height jumps:jumps]; +} +@end + +// +// JumpTo +// +#pragma mark - +#pragma mark JumpTo + +@implementation CCJumpTo +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + delta = ccp( delta.x - startPosition.x, delta.y - startPosition.y ); +} +@end + + +#pragma mark - +#pragma mark BezierBy + +// Bezier cubic formula: +// ((1 - t) + t)3 = 1 +// Expands to… +// (1 - t)3 + 3t(1-t)2 + 3t2(1 - t) + t3 = 1 +static inline float bezierat( float a, float b, float c, float d, ccTime t ) +{ + return (powf(1-t,3) * a + + 3*t*(powf(1-t,2))*b + + 3*powf(t,2)*(1-t)*c + + powf(t,3)*d ); +} + +// +// BezierBy +// +@implementation CCBezierBy ++(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c +{ + return [[[self alloc] initWithDuration:t bezier:c ] autorelease]; +} + +-(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c +{ + if( (self=[super initWithDuration: t]) ) { + config = c; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] bezier: config]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + startPosition = [(CCNode*)target_ position]; +} + +-(void) update: (ccTime) t +{ + float xa = 0; + float xb = config.controlPoint_1.x; + float xc = config.controlPoint_2.x; + float xd = config.endPosition.x; + + float ya = 0; + float yb = config.controlPoint_1.y; + float yc = config.controlPoint_2.y; + float yd = config.endPosition.y; + + float x = bezierat(xa, xb, xc, xd, t); + float y = bezierat(ya, yb, yc, yd, t); + [target_ setPosition: ccpAdd( startPosition, ccp(x,y))]; +} + +- (CCActionInterval*) reverse +{ + ccBezierConfig r; + + r.endPosition = ccpNeg(config.endPosition); + r.controlPoint_1 = ccpAdd(config.controlPoint_2, ccpNeg(config.endPosition)); + r.controlPoint_2 = ccpAdd(config.controlPoint_1, ccpNeg(config.endPosition)); + + CCBezierBy *action = [[self class] actionWithDuration:[self duration] bezier:r]; + return action; +} +@end + +// +// BezierTo +// +#pragma mark - +#pragma mark BezierTo +@implementation CCBezierTo +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + config.controlPoint_1 = ccpSub(config.controlPoint_1, startPosition); + config.controlPoint_2 = ccpSub(config.controlPoint_2, startPosition); + config.endPosition = ccpSub(config.endPosition, startPosition); +} +@end + + +// +// ScaleTo +// +#pragma mark - +#pragma mark ScaleTo +@implementation CCScaleTo ++(id) actionWithDuration: (ccTime) t scale:(float) s +{ + return [[[self alloc] initWithDuration: t scale:s] autorelease]; +} + +-(id) initWithDuration: (ccTime) t scale:(float) s +{ + if( (self=[super initWithDuration: t]) ) { + endScaleX = s; + endScaleY = s; + } + return self; +} + ++(id) actionWithDuration: (ccTime) t scaleX:(float)sx scaleY:(float)sy +{ + return [[[self alloc] initWithDuration: t scaleX:sx scaleY:sy] autorelease]; +} + +-(id) initWithDuration: (ccTime) t scaleX:(float)sx scaleY:(float)sy +{ + if( (self=[super initWithDuration: t]) ) { + endScaleX = sx; + endScaleY = sy; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] scaleX:endScaleX scaleY:endScaleY]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + startScaleX = [target_ scaleX]; + startScaleY = [target_ scaleY]; + deltaX = endScaleX - startScaleX; + deltaY = endScaleY - startScaleY; +} + +-(void) update: (ccTime) t +{ + [target_ setScaleX: (startScaleX + deltaX * t ) ]; + [target_ setScaleY: (startScaleY + deltaY * t ) ]; +} +@end + +// +// ScaleBy +// +#pragma mark - +#pragma mark ScaleBy +@implementation CCScaleBy +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + deltaX = startScaleX * endScaleX - startScaleX; + deltaY = startScaleY * endScaleY - startScaleY; +} + +-(CCActionInterval*) reverse +{ + return [[self class] actionWithDuration:duration_ scaleX: 1/endScaleX scaleY:1/endScaleY]; +} +@end + +// +// Blink +// +#pragma mark - +#pragma mark Blink +@implementation CCBlink ++(id) actionWithDuration: (ccTime) t blinks: (unsigned int) b +{ + return [[[ self alloc] initWithDuration: t blinks: b] autorelease]; +} + +-(id) initWithDuration: (ccTime) t blinks: (unsigned int) b +{ + if( (self=[super initWithDuration: t] ) ) + times = b; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] blinks: times]; + return copy; +} + +-(void) update: (ccTime) t +{ + if( ! [self isDone] ) { + ccTime slice = 1.0f / times; + ccTime m = fmodf(t, slice); + [target_ setVisible: (m > slice/2) ? YES : NO]; + } +} + +-(CCActionInterval*) reverse +{ + // return 'self' + return [[self class] actionWithDuration:duration_ blinks: times]; +} +@end + +// +// FadeIn +// +#pragma mark - +#pragma mark FadeIn +@implementation CCFadeIn +-(void) update: (ccTime) t +{ + [(id) target_ setOpacity: 255 *t]; +} + +-(CCActionInterval*) reverse +{ + return [CCFadeOut actionWithDuration:duration_]; +} +@end + +// +// FadeOut +// +#pragma mark - +#pragma mark FadeOut +@implementation CCFadeOut +-(void) update: (ccTime) t +{ + [(id) target_ setOpacity: 255 *(1-t)]; +} + +-(CCActionInterval*) reverse +{ + return [CCFadeIn actionWithDuration:duration_]; +} +@end + +// +// FadeTo +// +#pragma mark - +#pragma mark FadeTo +@implementation CCFadeTo ++(id) actionWithDuration: (ccTime) t opacity: (GLubyte) o +{ + return [[[ self alloc] initWithDuration: t opacity: o] autorelease]; +} + +-(id) initWithDuration: (ccTime) t opacity: (GLubyte) o +{ + if( (self=[super initWithDuration: t] ) ) + toOpacity = o; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] opacity: toOpacity]; + return copy; +} + +-(void) startWithTarget:(CCNode *)aTarget +{ + [super startWithTarget:aTarget]; + fromOpacity = [(id)target_ opacity]; +} + +-(void) update: (ccTime) t +{ + [(id)target_ setOpacity: fromOpacity + ( toOpacity - fromOpacity ) * t]; +} +@end + +// +// TintTo +// +#pragma mark - +#pragma mark TintTo +@implementation CCTintTo ++(id) actionWithDuration:(ccTime)t red:(GLubyte)r green:(GLubyte)g blue:(GLubyte)b +{ + return [[(CCTintTo*)[ self alloc] initWithDuration:t red:r green:g blue:b] autorelease]; +} + +-(id) initWithDuration: (ccTime) t red:(GLubyte)r green:(GLubyte)g blue:(GLubyte)b +{ + if( (self=[super initWithDuration: t] ) ) + to = ccc3(r,g,b); + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + CCAction *copy = [(CCTintTo*)[[self class] allocWithZone: zone] initWithDuration: [self duration] red:to.r green:to.g blue:to.b]; + return copy; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + id tn = (id) target_; + from = [tn color]; +} + +-(void) update: (ccTime) t +{ + id tn = (id) target_; + [tn setColor:ccc3(from.r + (to.r - from.r) * t, from.g + (to.g - from.g) * t, from.b + (to.b - from.b) * t)]; +} +@end + +// +// TintBy +// +#pragma mark - +#pragma mark TintBy +@implementation CCTintBy ++(id) actionWithDuration:(ccTime)t red:(GLshort)r green:(GLshort)g blue:(GLshort)b +{ + return [[(CCTintBy*)[ self alloc] initWithDuration:t red:r green:g blue:b] autorelease]; +} + +-(id) initWithDuration:(ccTime)t red:(GLshort)r green:(GLshort)g blue:(GLshort)b +{ + if( (self=[super initWithDuration: t] ) ) { + deltaR = r; + deltaG = g; + deltaB = b; + } + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + return[(CCTintBy*)[[self class] allocWithZone: zone] initWithDuration: [self duration] red:deltaR green:deltaG blue:deltaB]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + + id tn = (id) target_; + ccColor3B color = [tn color]; + fromR = color.r; + fromG = color.g; + fromB = color.b; +} + +-(void) update: (ccTime) t +{ + id tn = (id) target_; + [tn setColor:ccc3( fromR + deltaR * t, fromG + deltaG * t, fromB + deltaB * t)]; +} + +- (CCActionInterval*) reverse +{ + return [CCTintBy actionWithDuration:duration_ red:-deltaR green:-deltaG blue:-deltaB]; +} +@end + +// +// DelayTime +// +#pragma mark - +#pragma mark DelayTime +@implementation CCDelayTime +-(void) update: (ccTime) t +{ + return; +} + +-(id)reverse +{ + return [[self class] actionWithDuration:duration_]; +} +@end + +// +// ReverseTime +// +#pragma mark - +#pragma mark ReverseTime +@implementation CCReverseTime ++(id) actionWithAction: (CCFiniteTimeAction*) action +{ + // casting to prevent warnings + CCReverseTime *a = [super alloc]; + return [[a initWithAction:action] autorelease]; +} + +-(id) initWithAction: (CCFiniteTimeAction*) action +{ + if( (self=[super initWithDuration: [action duration]]) ) + other = [action retain]; + + return self; +} + +-(id) copyWithZone: (NSZone*) zone +{ + return [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] ]; +} + +-(void) dealloc +{ + [other release]; + [super dealloc]; +} + +-(void) startWithTarget:(id)aTarget +{ + [super startWithTarget:aTarget]; + [other startWithTarget:target_]; +} + +-(void) stop +{ + [other stop]; + [super stop]; +} + +-(void) update:(ccT