Browse Source

Final fixes to polar velocity and aligned particles.

William Lee Sims 12 years ago
parent
commit
1b4197fe03

+ 1 - 1
engine/source/2d/core/Vector2_ScriptBinding.h

@@ -263,7 +263,7 @@ ConsoleFunctionWithDocs( Vector2AngleBetween, ConsoleFloat, 3, 3, (Vector2 v1, V
 /*! Angle from one point to another.
 /*! Angle from one point to another.
 	@return the angle from p1 to p2.
 	@return the angle from p1 to p2.
 */
 */
-ConsoleFunctionWithDocs( Vector2AngleToPoint, ConsoleFloat, 3, 3, (Vector2 p1, Vector2 p1))
+ConsoleFunctionWithDocs( Vector2AngleToPoint, ConsoleFloat, 3, 3, (Vector2 p1, Vector2 p2))
 {
 {
     // Check Parameters.
     // Check Parameters.
     if (Utility::mGetStringElementCount(argv[1]) < 2 ||Utility::mGetStringElementCount(argv[2]) < 2 )
     if (Utility::mGetStringElementCount(argv[1]) < 2 ||Utility::mGetStringElementCount(argv[2]) < 2 )

+ 1 - 1
engine/source/2d/sceneobject/ParticlePlayer.cc

@@ -1439,7 +1439,7 @@ void ParticlePlayer::integrateParticle( EmitterNode* pEmitterNode, ParticleSyste
             movementAngle += 360.0f;
             movementAngle += 360.0f;
 
 
         // Set new Orientation Angle.
         // Set new Orientation Angle.
-        pParticleNode->mOrientationAngle = -movementAngle - pParticleAssetEmitter->getAlignedAngleOffset();
+        pParticleNode->mOrientationAngle = movementAngle - pParticleAssetEmitter->getAlignedAngleOffset();
 
 
     }
     }
     else
     else

+ 1 - 1
engine/source/2d/sceneobject/SceneObject_ScriptBinding.h

@@ -1643,7 +1643,7 @@ ConsoleMethodWithDocs(SceneObject, setLinearVelocityPolar, ConsoleVoid, 4, 4, (f
     mSinCos( angle, sin, cos );
     mSinCos( angle, sin, cos );
 
 
     // Set Gross Linear Velocity.
     // Set Gross Linear Velocity.
-    object->setLinearVelocity( Vector2( cos*speed, -sin*speed ) );
+    object->setLinearVelocity( Vector2( cos*speed, sin*speed ) );
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 22 - 12
modules/AngleToy/1/main.cs

@@ -47,6 +47,8 @@ function AngleToy::reset( %this )
     
     
     // Create Mathematical Objects/Labels
     // Create Mathematical Objects/Labels
     %this.createMathematicalObjects();
     %this.createMathematicalObjects();
+    
+    AngleToy.repointTarget = "0 0";
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -115,11 +117,12 @@ function AngleToy::createBackground( %this )
 function AngleToy::createTargets( %this )
 function AngleToy::createTargets( %this )
 {
 {
     // Create the sprite.
     // Create the sprite.
-    %object = new Sprite();
+    %object = new Sprite() { class = "MagicTarget"; };
     AngleToy.TargetObject = %object;
     AngleToy.TargetObject = %object;
     %object.Image = "ToyAssets:hollowArrow";
     %object.Image = "ToyAssets:hollowArrow";
     %object.Size = 5;
     %object.Size = 5;
-    %object.setBodyType( static );
+    %object.setBodyType( dynamic );
+    %object.startTimer( repoint, 100 );
     SandboxScene.add( %object );
     SandboxScene.add( %object );
 
 
     %effect = new ParticleAsset();
     %effect = new ParticleAsset();
@@ -128,11 +131,13 @@ function AngleToy::createTargets( %this )
     %emitter = %effect.createEmitter();
     %emitter = %effect.createEmitter();
     AngleToy.EmitterParameters = %emitter;
     AngleToy.EmitterParameters = %emitter;
     %emitter.EmitterName = "AngledParticles";
     %emitter.EmitterName = "AngledParticles";
+    %emitter.setKeepAligned( true );
+    %emitter.setOrientationType( ALIGNED );
     %emitter.Image = "ToyAssets:Crosshair3";
     %emitter.Image = "ToyAssets:Crosshair3";
     %emitter.selectField( "Lifetime" );
     %emitter.selectField( "Lifetime" );
     %emitter.addDataKey( 0, 1 );
     %emitter.addDataKey( 0, 1 );
     %emitter.selectField( "Quantity" );
     %emitter.selectField( "Quantity" );
-    %emitter.addDataKey( 0, 50 );
+    %emitter.addDataKey( 0, 250 );
     %emitter.selectField( "Speed" );
     %emitter.selectField( "Speed" );
     %emitter.addDataKey( 0, 4 );
     %emitter.addDataKey( 0, 4 );
     %emitter.selectField( "EmissionAngle" );
     %emitter.selectField( "EmissionAngle" );
@@ -141,11 +146,6 @@ function AngleToy::createTargets( %this )
     %emitter.addDataKey( 0, 0 );
     %emitter.addDataKey( 0, 0 );
     %emitter.selectField( "EmissionForceVariation" );
     %emitter.selectField( "EmissionForceVariation" );
     %emitter.addDataKey( 0, 0 );
     %emitter.addDataKey( 0, 0 );
-    %emitter.selectField( "AlphaChannel" );
-    %emitter.addDataKey( 0, 0 );
-    %emitter.addDataKey( 0.25, 1 );
-    %emitter.addDataKey( 0.75, 1 );
-    %emitter.addDataKey( 1, 0 );
     %emitter.deselectField();
     %emitter.deselectField();
     
     
     %assetId = AssetDatabase.addPrivateAsset( %effect );
     %assetId = AssetDatabase.addPrivateAsset( %effect );
@@ -214,13 +214,12 @@ function AngleToy::createMathematicalObjects( %this )
 
 
 function AngleToy::onTouchMoved(%this, %touchID, %worldPosition)
 function AngleToy::onTouchMoved(%this, %touchID, %worldPosition)
 {
 {
+    // Used to let the repointing target kno  
+    AngleToy.repointTarget = %worldPosition;
+
     // Calculate the angle to the mouse.
     // Calculate the angle to the mouse.
-    %origin = AngleToy.TargetObject.getPosition();
     %angle = mAtan( %worldPosition );
     %angle = mAtan( %worldPosition );
     
     
-    //Rotate to the touched angle.
-    AngleToy.TargetObject.SetAngle( %angle - 90 ); // Image points at 90 degrees, so we need to subtract that off.
-    
     // "Point" particles towards cursor
     // "Point" particles towards cursor
     AngleToy.EmitterParameters.selectField( "EmissionAngle" );
     AngleToy.EmitterParameters.selectField( "EmissionAngle" );
     AngleToy.EmitterParameters.addDataKey( 0, %angle );
     AngleToy.EmitterParameters.addDataKey( 0, %angle );
@@ -258,6 +257,17 @@ function AngleToy::onTouchMoved(%this, %touchID, %worldPosition)
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
+function MagicTarget::repoint( %this )
+{
+    %myPosition = %this.getPosition();
+    %angle = Vector2AngleToPoint( %myPosition, AngleToy.repointTarget );
+    %this.rotateTo( %angle - 90, 360 ); // Image points at 90 degrees, so we need to subtract that off.
+    %this.setLinearVelocityPolar( %angle,
+        Vector2Length( Vector2Sub( AngleToy.repointTarget, %myPosition  ) ) );
+}
+
+//-----------------------------------------------------------------------------
+
 function LineSegment::draw( %this, %from, %to )
 function LineSegment::draw( %this, %from, %to )
 {
 {
     %length = Vector2Distance( %from, %to );
     %length = Vector2Distance( %from, %to );