Forráskód Böngészése

PathFinding steering

-Added steering to path, need to add scriptable maxforce
-Fix: Custom cursor. The problem seems to be the cursor being shown before the custom cursor is set. Now the showCursor is called in script after a custom cursor has been set rather than in the same call.
marauder2k7 5 éve
szülő
commit
61f2383a20

+ 18 - 14
engine/source/2d/sceneobject/Path.cc

@@ -68,7 +68,7 @@ void Path::preIntegrate(const F32 totalTime, const F32 elapsedTime, DebugStats *
       Vector2 cDst = mNodes[pObj.mCurrNode].position;
       F32 distance = (cDst - cPos).Length();
 
-      if (distance < (pObj.mMaxSpeed * elapsedTime) || distance < mNodes[pObj.mCurrNode].distance)
+      if (distance < (pObj.mMaxSpeed * elapsedTime) || distance < cNode.distance )
       {
          S32 nCount = mNodes.size();
          S32 end = nCount - 1;
@@ -205,17 +205,21 @@ void Path::moveObject(PathObject& obj)
    Vector2 currVel = obj.mObj->getLinearVelocity();
    dir.Normalize();
 
-   Vector2 steer = seek(cDest, oPos, obj.mMaxSpeed, currVel, slowRad);
+   F32 maxSpeed = obj.mMaxSpeed;
+   F32 maxForce = 1.2f;
 
-   steer = truncate(steer, obj.mMaxSpeed);
-   steer = steer * 1 / 2;
-   currVel = currVel + steer;
-   currVel = truncate(currVel, obj.mMaxSpeed);
-   Vector2 pos = Vector2(oPos + currVel);
+   Vector2 steer = seek(cDest, oPos, maxSpeed, currVel, slowRad);
+   steer = truncate(steer, maxForce);
+   steer = steer.scale(0.5);
+   currVel = currVel.add(steer);
+   currVel = truncate(currVel.add(steer), maxSpeed);
+   Vector2 pos = oPos.add(currVel);
 
-   //obj.mObj->applyForce(pos);
+   //Steering Behavior
+   obj.mObj->applyForce(pos, obj.mObj->getWorldCenter());
 
-   obj.mObj->setLinearVelocity(dir * obj.mMaxSpeed);
+   //Simple direct move.
+   //obj.mObj->setLinearVelocity(dir * obj.mMaxSpeed);
 
    if (obj.mOrient)
    {
@@ -232,26 +236,26 @@ Vector2 Path::truncate(Vector2 vec, F32 max)
 {
    F32 i = max;
    i = i < 1.0f ? 1.0f : i;
-   vec = vec * max;
+   vec = vec.scale(max);
    return vec;
 }
 
 Vector2 Path::seek(Vector2 target, Vector2 objPos, F32 max, Vector2 curr, F32 slowRad)
 {
-   Vector2 des = target - objPos;
+   Vector2 des = target.sub(objPos);
    F32 dist = des.Length();
    des.Normalize();
 
    if (dist < slowRad)
    {
-      des = des * (max * dist / slowRad);
+      des = des.scale(max * dist / slowRad);
    }
    else
    {
-      des = des * max;
+      des = des.scale(max);
    }
 
-   Vector2 force = des - curr;
+   Vector2 force = des.sub(curr);
 
    return force;
 }

+ 4 - 4
engine/source/gui/guiCanvas.cc

@@ -58,7 +58,7 @@ GuiCanvas::GuiCanvas()
 
    cursorON    = true;
    mShowCursor = false;
-   mUseNativeCursor = true;
+   //mUseNativeCursor = true;
 
    lastCursorON = false;
    rLastFrameTime = 0.0f;
@@ -137,7 +137,7 @@ void GuiCanvas::setCursorON(bool onOff)
       mMouseControl = NULL;
 }
 
-bool GuiCanvas::getUseNativeCursor(void)
+/*bool GuiCanvas::getUseNativeCursor(void)
 {
    return mUseNativeCursor;
 }
@@ -145,7 +145,7 @@ bool GuiCanvas::getUseNativeCursor(void)
 void GuiCanvas::useNativeCursor(bool useNative)
 {
    mUseNativeCursor = useNative;
-}
+}*/
 
 void GuiCanvas::setCursorPos(const Point2I &pt)   
 { 
@@ -1310,7 +1310,7 @@ void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */)
       dglSetClipRect(updateUnion);
 
       //temp draw the mouse
-      if (cursorON && mShowCursor && !mouseCursor && Canvas->getUseNativeCursor())
+      if (cursorON && mShowCursor && !mouseCursor /*&& Canvas->getUseNativeCursor()*/)
       {
 #if defined(TORQUE_OS_IOS) || defined(TORQUE_OS_ANDROID) || defined(TORQUE_OS_EMSCRIPTEN)
          glColor4ub(255, 0, 0, 255);

+ 3 - 3
engine/source/gui/guiCanvas.h

@@ -109,7 +109,7 @@ protected:
    GuiCursor   *defaultCursor;
    GuiCursor   *lastCursor;
    bool        lastCursorON;
-   bool        mUseNativeCursor;
+   //bool        mUseNativeCursor;
    /// @}
 
    /// @name Mouse Input
@@ -253,8 +253,8 @@ public:
    /// @param   cursor   New cursor to use.
    virtual void setCursor(GuiCursor *cursor);
 
-   virtual bool getUseNativeCursor(void);
-   virtual void useNativeCursor(bool useNative);
+   //virtual bool getUseNativeCursor(void);
+   //virtual void useNativeCursor(bool useNative);
 
    /// Returns true if the cursor is on.
    virtual bool isCursorON() {return cursorON; }

+ 3 - 3
engine/source/gui/guiCanvas_ScriptBinding.h

@@ -147,9 +147,9 @@ ConsoleMethodWithDocs( GuiCanvas, setCursor, ConsoleVoid, 3, 3, ( cursorHandle )
          return;
       }
    }
-   Canvas->useNativeCursor(false);
+   //Canvas->useNativeCursor(false);
    Canvas->setCursor(curs);
-   Canvas->showCursor(true);
+   //Canvas->showCursor(true);
 }
 
 /*! Returns the cursor to the system default.
@@ -157,7 +157,7 @@ ConsoleMethodWithDocs( GuiCanvas, setCursor, ConsoleVoid, 3, 3, ( cursorHandle )
 */
 ConsoleMethodWithDocs(GuiCanvas, resetCursor, void, 2, 2, ())
 {
-   Canvas->useNativeCursor(true);
+  // Canvas->useNativeCursor(true);
    Canvas->showCursor(false);
    Input::refreshCursor();
 }

+ 2 - 0
engine/source/gui/guiControl.cc

@@ -1538,6 +1538,8 @@ void GuiControl::renderJustifiedText(Point2I offset, Point2I extent, const char
 
 void GuiControl::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent)
 {
+   lastGuiEvent;
+
    if(GuiControl::smCursorChanged != -1 && !isMouseLocked())
    {
       // We've already changed the cursor, 

+ 1 - 5
engine/source/platformWin32/winWindow.cc

@@ -953,7 +953,7 @@ case WM_NCMOUSEMOVE:
 
 case WM_MOUSEMOVE:
    // keep trying until we actually show it
-   Input::refreshCursor();
+   //Input::refreshCursor();
 
    if ( !windowLocked )
    {
@@ -974,10 +974,6 @@ case WM_MOUSEMOVE:
       Game->postEvent(event);
    }
    break;
-case WM_SETCURSOR:
-   if ((LOWORD(lParam) == HTCLIENT) && !(Canvas->getUseNativeCursor()))
-      SetCursor(NULL);
-   break;
 case WM_LBUTTONDOWN:
    mouseButtonEvent(SI_MAKE, KEY_BUTTON0);
    break;

+ 3 - 1
modules/AppCore/1/main.cs

@@ -26,6 +26,7 @@ function AppCore::create( %this )
     exec("./scripts/constants.cs");
     exec("./scripts/defaultPreferences.cs");
     exec("./scripts/canvas.cs");
+	exec("./scripts/cursor.cs");
     exec("./scripts/openal.cs");
     
     // Initialize the canvas
@@ -37,7 +38,8 @@ function AppCore::create( %this )
     
     // Initialize audio
     initializeOpenAL();
-    
+    Canvas.setCursor(DefaultCursor);
+	Canvas.showCursor();
     ModuleDatabase.loadGroup("gameBase");
 }
 

+ 5 - 5
modules/PathToy/1/main.cs

@@ -50,10 +50,10 @@ function PathToy::reset( %this )
 function PathToy::createPath(%this)
 {
 	%path = new Path(SquarePath);
-	%path.addNode(10.0 , 10.0, 5.0);
-	%path.addNode(-10.0 , 10.0, 5.0);
-	%path.addNode(-10.0 , -10.0, 5.0);
-	%path.addNode(10.0 , -10.0, 5.0);
+	%path.addNode(10.0 , 10.0, 3.0);
+	%path.addNode(-10.0 , 10.0, 3.0);
+	%path.addNode(-10.0 , -10.0, 3.0);
+	%path.addNode(10.0 , -10.0, 3.0);
 	
 	SandboxScene.add(%path);
 }
@@ -66,5 +66,5 @@ function PathToy::createTarget(%this)
     %object.setBodyType( dynamic );
     SandboxScene.add( %object );
 	
-	SquarePath.attachObject(%object, 20.0, true, 90.0);
+	SquarePath.attachObject(%object, 15.5, true, 90.0);
 }

+ 1 - 0
modules/Sandbox/1/gui/guiProfiles.cs

@@ -343,6 +343,7 @@ if(!isObject(SandboxWindowProfile)) new GuiControlProfile (SandboxWindowProfile
     fontType = $platformFontType;
     fontSize = $platformFontSize;
     fontColor = "255 255 255 255";
+	lockMouse = "0";
 }; 
 
 //-----------------------------------------------------------------------------

+ 3 - 1
modules/Sandbox/1/main.cs

@@ -31,13 +31,15 @@ function Sandbox::create( %this )
     exec( "./scripts/customToolboxGui.cs" );
     exec( "./scripts/manipulation.cs" );
     exec( "./scripts/scene.cs" );
-    exec( "./scripts/toys.cs" );        
+    exec( "./scripts/toys.cs" );
         
     // Load GUI profiles.
     exec("./gui/guiProfiles.cs");
 
     // Create the sandbox window.
     CreateSandboxWindow();
+	
+	Canvas.setCursor(DefaultCursor);
     
     // Load and configure the console.
     Sandbox.add( TamlRead("./gui/ConsoleDialog.gui.taml") );

+ 2 - 1
modules/TruckToy/1/main.cs

@@ -58,9 +58,10 @@ function TruckToy::create( %this )
     addFlagOption("Front Wheel Drive", "setFrontWheelDrive", TruckToy.FrontWheelDrive, false, "Whether the motor on the front wheel is active or not." );
     addFlagOption("Rear Wheel Drive", "setRearWheelDrive", TruckToy.RearWheelDrive, false, "Whether the motor on the rear wheel is active or not." );
     addFlagOption("Rotate Camera", "setRotateCamera", TruckToy.RotateCamera, true, "Whether the rotate the camera that is mounted to the truck or not." );
-	
+	Canvas.setCursor(DefaultCursor);
     // Reset the toy.
     %this.reset();
+	
 }
 
 //-----------------------------------------------------------------------------