Translating Steering Behaviour Pursuit sample

dbomb101
  • Translating Steering Behaviour Pursuit sample dbomb101

    I've come across a C++ Sample of from Programming Game AI by Example. For the most part it is fairly understandable, the only thing confusing me is the reference to "m_pVehicle->Heading()" I'm not sure what it means by heading. If anyone could clarify this, I would really appreciate it.

     Vector2D SteeringBehaviors::Pursuit(const Vehicle* evader)
        {
          //if the evader is ahead and facing the agent then we can just seek
          //for the evader's current position.
          Vector2D ToEvader = evader->Pos() - m_pVehicle->Pos();
    
          double RelativeHeading = m_pVehicle->Heading().Dot(evader->Heading());
    
          if ((ToEvader.Dot(m_pVehicle->Heading()) > 0) &&
              (RelativeHeading < -0.95))  //acos(0.95)=18 degs
          {
            return Seek(evader->Pos());
          }
    
          //Not considered ahead so we predict where the evader will be.
    
          //the look-ahead time is proportional to the distance between the evader
          //and the pursuer; and is inversely proportional to the sum of the
          //agents' velocities
          double LookAheadTime = ToEvader.Length() /
                                (m_pVehicle->MaxSpeed() + evader->Speed());
    
          //now seek to the predicted future position of the evader
          return Seek(evader->Pos() + evader->Velocity() * LookAheadTime);
        }
    

  • On p.87 of the book, you will find the definition of m_vHeading as:

    //a normalized vector pointing in the direction the entity is heading.
    SVector2D m_vHeading;
    

    If you look through the source, you will find:

    Vector2D  Heading()const{return m_vHeading;}
    

    Right before your code snippet he explains that if the target being pursued is ahead and almost directly facing the agent, it should just seek directly towards the target's position.

    A way to easily determine if the target is ahead, or "in front", of the agent is by using the dot product of the vector from the agent's position to the target's position ToEvader and the agent's heading vector m_pVehicle->Heading(). If the dot product is greater than 0, the target is in front of the agent:

    (ToEvader.Dot(m_pVehicle->Heading()) > 0)
    

    You can read more on the dot product and it's uses on pages 23-26.

Tags
c++ ai
Related questions and answers
  • ]; Vec3f pos = v1-&gt;pos * (1 - frac) + v2-&gt;pos * frac; Vec3f normal = v1-&gt;normal * (1 - frac) + v2-&gt;normal * frac; if (normal[0] == 0 &amp;&amp; normal[1...); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle = triangles + i; for(int j = 0; j < 3; j++) { MD2Vertex* v1 = frame1-&gt;vertices + triangle-&gt;vertices[j

  • code shows the changes I made to get accurate physics. void GameState::createScene() { m_pSceneMgr-&gt;createLight("Light")-&gt;setPosition(75,75,75); // Physics // As a test we want a floor plane...::createScene() { m_pSceneMgr-&gt;createLight("Light")-&gt;setPosition(75,75,75); // Physics // As a test we want a floor plane for things to collide with Ogre::Entity *ent; Ogre::Plane p; p.normal = Ogre... *) (node)); // Add it to the physics world World-&gt;addRigidBody(RigidBody); Objects.push_back(RigidBody); m_pNumEntities++; // End Physics } I then have a method to create a cube and give it rigid body

  • i think i just found the solution. 1) the problem is that backbuffer surface and source surface are of different formats - that is why exception was thrown. 2) the image path needed double slash "C...(D3D_SDK_VERSION))) return false; std::wstring wsPath = L"C:\wood.bmp"; // path to the image D3DXIMAGE_INFO Info; if (FAILED(D3DXGetImageInfoFromFile(wsPath.c_str(), &amp;Info...); //================================================================================================================================// code starts here //================// int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { if (!initWindow(hInstance)) return

  • == 0)) { //lines are parallel return false; } double r = rTop/rBot; double s = sTop/sBot; if( (r &gt; 0) &amp;&amp; (r < 1) &amp;&amp; (s &gt; 0) &amp;&amp; (s..., Vector2D D, double& dist, Vector2D&amp; point) { double rTop = (A.y-C.y)*(D.x-C.x)-(A.x-C.x)*(D.y-C.y); double...I have a tile based engine and in the middle of translating out the example wall avoidance alogrithm in the book AI programming by example. I was wondering if the method below can be modified so

  • matFinal = temporaryLines[i].scale * temporaryLines[i].rotation * temporaryLines[i].position * matView * matProjection; pTransform-&gt;SetMatrix(&amp;matFinal._11); pRotation-&gt;SetMatrix(&amp;temporaryLines[i].rotation._11); // set the rotation matrix in the effect pPass-&gt;Apply(0); device-&gt;DrawIndexed(2, 0, 0); } temporaryLines.clear... float4 Colour; // a struct for the vertex shader return value struct VSOut { float4 Col : COLOR; // vertex normal float4 Pos : SV_POSITION; // vertex screen coordinates }; // the vertex

  • ! A line of about 2 long fills the whole screen. Why is this? How can I modify my shader to 'think' in screen coordinates? // a struct for the vertex shader return value struct VSOut { float4 Col : COLOR; // vertex color float4 Pos : SV_POSITION; // vertex screen coordinates }; // the vertex shader VSOut VS(float4 Col : COLOR, float4 Pos : POSITION) { VSOut Output; Output.Pos = Pos; // set the vertex position to the input's position Output.Col = Col; // set the vertex color to the input's color return Output; // send the modified vertex data to the Rasterizer Stage

  • it returned: %i", rval); return 1; } allegro_message("Setting Graphics Mode...Press X To Begin Game. Default Missile count: %i", bullets-&gt;size()); set_color_depth(32); int ret = set_gfx_mode(GFX_AUTODETECT,480,272,0,0); if (ret != 0) { allegro_message("Error setting grahpic mode! Because of it returned: %i", ret); return ret; } background... it is the pad that is causing the problem. Maybe the bullet is being drawn out of the screen already. But I am not sure since I cannot debug maybe somebody can see the flaw in my code. main.cpp class

  • Dear all, this is going to be tough: I have created a game object factory that generates objects of my wish. However, I get memory leaks which I can not fix. Memory leaks are generated by return new Object(); in the bottom part of the code sample. static BaseObject * CreateObjectFunc() { return new Object(); } How and where to delete the pointers? I wrote bool ReleaseClassType(). Despite...() to call stored function that generates desired object. The position of the appropriate function in the vFactories is identical to the nObjectTypeID, so I can use indexing to access the function. So

  • ]; Vec3f pos = v1-&gt;pos * (1 - frac) + v2-&gt;pos * frac; Vec3f normal = v1-&gt;normal * (1 - frac) + v2-&gt;normal * frac; if (normal[0] == 0 &amp;&amp; normal[1] == 0 &amp...]; Vec3f pos = v1-&gt;pos * (1 - frac) + v2-&gt;pos * frac; Vec3f normal = v1-&gt;normal * (1 - frac) + v2-&gt;normal * frac; if (normal[0] == 0 &amp;&amp; normal[1] == 0 &amp... = frame1-&gt;vertices + triangle-&gt;vertices[j]; MD2Vertex* v2 = frame2-&gt;vertices + triangle-&gt;vertices[j]; Vec3f pos = v1-&gt;pos * (1 - frac) + v2-&gt;pos * frac

Data information