Advertisement

05.19.2008 at 08:50AM PDT, ID: 23414104
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Game development Path finding

Asked by RockBaby in C Programming Language, C++ Programming Language

Hi,

I trying to draw a yellow line. After i getting the 2 entity position, i call draw_path(); to draw the yellow line.
but the yellow line seems to appear and blink off. Any idea?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
#define WIN32_LEAN_AND_MEAN		
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
 
//include the engine data types, variables, and functions
#include "adll.h"
#include "init_engine.h"
#include "grid.h"
 
ENTITY* gStartEnt = NULL;    //pointer to start entity
ENTITY* gGoalEnt = NULL;     //pointer to goal entity
int gStartNode = -1;         //start node, initialized to -1
int gGoalNode = -1;          //goal node, initialized to -1
 
 
//draw path from goal position to goal node, then along all connections back to start node, then to start position
void draw_path()
{
  COLOR cColour; //colour vector
  VECTOR vTemp;  //temp vector
  
  //set the colour to light grey
  cColour.blue = _VAR(0);
  cColour.green = _VAR(255);
  cColour.red = _VAR(255);                                                                                                  
 
  //set temp vector to goal position
  vTemp.x = gGoalEnt->x;
  vTemp.y = gGoalEnt->y;
  vTemp.z = _VAR(30); 
  //place the draw position there, (pass colour as NULL because don't want to start drawing yet)
  draw_line3d(&vTemp, NULL, _VAR(100));
  //set it to the correct colour
  draw_line3d(&vTemp, &cColour, _VAR(100));
  
  //set temp vector to goal position
  vTemp.x = gStartEnt->x;
  vTemp.y = gStartEnt->y;
  vTemp.z = _VAR(30); 
  draw_line3d(&vTemp, &cColour, _VAR(100));
}
 
//this function handles left mouse clicks
void handle_leftclick()
{
  VECTOR position;     //temp position variable
  int i, closest_node;     //for loop counter and variable for closest node found so far
  float closest_distance, temp_distance;      //variables for closest distance found so far and temp distance
  
  //if there is no start node
  if(gStartNode == -1)
  {
    if(get_position(&position, gStartNode))    //if mouse clicked on valid position
    {
      gStartEnt = ent_create("blue_target.mdl", &position, NULL); //create entity at start position
    }
  }
  //if there is no goal node
  else if(gGoalNode == -1)
  {
    if(get_position(&position, gGoalNode))      //if mouse clicked on valid position
    {
      gGoalEnt = ent_create("target.mdl", &position, NULL);        //create entity at goal position
 
      draw_path();
/////////////////////////////////////////////////////////////////////////////////////////////////////    
//CALL YOUR PATH FINDING FUNCTION HERE
 
///////////////////////////////////////////////////////////////////////////////////////////////////// 
    }
  }
  else       //reset
  {
    if(gStartEnt != NULL)     //check whether there is a start entity (just in case)
    {
      ent_remove(gStartEnt);  //remove entity
      gStartEnt = NULL;       //reset pointer to NULL
    }
    if(gGoalEnt != NULL)      //check whether there is a goal entity (just in case)
    {
      ent_remove(gGoalEnt);   //remove entity
      gGoalEnt = NULL;        //reset pointer to NULL
    }
    gStartNode = -1;          //reset start node
    gGoalNode = -1;           //reset goal node
    
    reset_node_records();     //reset node records
  }
}
 
//main function
int APIENTRY WinMain(HINSTANCE hInstance,	
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,	
                     int       nCmdShow)	
{
  engine_init();     //calls function that initializes the engine
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  //initialise everything you need before entering main rendering loop
 
  init_grid();            //setup the grid
  reset_node_records();   //initialize the node records
 
  //assign function for left mouse click
  v(on_mouse_left) = (EVENT)handle_leftclick;
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  //main rendering loop, this will loop once every frame until you quit
  while(engine_frame()) 
  {
    //update debug text display
    update_debug_text();
  }
  
  //DO NOT CHANGE
  engine_close();     //engine frees all created entities, bitmaps and sounds automatically when closing
  return 0;
}
[+][-]05.19.2008 at 09:35AM PDT, ID: 21599301

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C Programming Language, C++ Programming Language
Sign Up Now!
Solution Provided By: anmalaver
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.19.2008 at 11:34AM PDT, ID: 21600313

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 08:24PM PDT, ID: 21603369

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 07:10AM PDT, ID: 21606286

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 05:15PM PDT, ID: 21611320

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 10:13PM PDT, ID: 21621055

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 10:14PM PDT, ID: 21621060

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-38 / EE_QW_2_20070628