This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:projects:racing_game [2010/06/13 20:35] – mikk.leini | en:projects:racing_game [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Racing game ====== | ====== Racing game ====== | ||
| + | |||
| + | Platform: ARM-CAN kit | ||
| [{{ : | [{{ : | ||
| Line 56: | Line 58: | ||
| ===== Polygon drawing ===== | ===== Polygon drawing ===== | ||
| - | As there are no polygon drawing functions in StellarisWare Graphics Library it is implemented in " | + | As there are no polygon drawing functions in StellarisWare Graphics Library it is implemented in " |
| <code c> | <code c> | ||
| Line 100: | Line 102: | ||
| </ | </ | ||
| - | To get the track data with | + | [{{ : |
| + | |||
| + | To get the edges of the track, // | ||
| + | |||
| + | But there are problems - these rectangles are not connected like a racing track might be. Too understand it, take a look at the blue and green rectangle on the picture. Firstly, there is a gap on the outer side of corner, secondly the rectangles intersect in the inner corner. Intersection point of two rectangles is solved in // | ||
| + | |||
| + | The rendering of the track in // | ||
| + | |||
| + | Because it is not an offroad racing game, some collision detection is needed to check if the car is on the road or not. This check is achieved with the help of // | ||
| <code c> | <code c> | ||
| void TrackGenerate(void); | void TrackGenerate(void); | ||
| void TrackRender(tContext *pContext); | void TrackRender(tContext *pContext); | ||
| + | tBoolean GetLinesIntersectionPoint(tPoint *pA1, tPoint *pA2, tPoint *pB1, | ||
| + | | ||
| tBoolean PointInPolygon(tPoint pPolygonPoints[], | tBoolean PointInPolygon(tPoint pPolygonPoints[], | ||
| | | ||
| Line 113: | Line 125: | ||
| ===== Rendering car ===== | ===== Rendering car ===== | ||
| - | ===== Main program ===== | + | The car in the game is also made up of polygons. It has a rectangular body and roof polygon, plus two circles as headlights. As the viewpoint do not rotate, the car has to rotate to give the right visual effect. Rotating means trigometric functions and it is most easily achieved by converting polar coordinates to Cartesian coordinates. That is why the points of the car are defined by radius and angle as seen below. |
| - | The main function | + | <code c> |
| + | tPolarPoint pBodyPoints[4]; | ||
| + | |||
| + | pBodyPoints[0].sRadius = 200; | ||
| + | pBodyPoints[0].ulAngle = DEGREES_TO_FIX32(330); | ||
| + | |||
| + | pBodyPoints[1].sRadius = 200; | ||
| + | pBodyPoints[1].ulAngle = DEGREES_TO_FIX32(30); | ||
| + | |||
| + | pBodyPoints[2].sRadius = 200; | ||
| + | pBodyPoints[2].ulAngle = DEGREES_TO_FIX32(150); | ||
| + | |||
| + | pBodyPoints[3].sRadius = 200; | ||
| + | pBodyPoints[3].ulAngle = DEGREES_TO_FIX32(210); | ||
| + | </ | ||
| + | |||
| + | All the points of the body parts are converted to x, y coordinates in // | ||
| + | |||
| + | < | ||
| + | void CalculateScreenPoint(tPoint *pScreenPoint, | ||
| + | | ||
| + | void CarRender(tContext *pContext, tCar *pCar); | ||
| + | </ | ||
| + | |||
| + | ===== Main program ===== | ||
| [{{ : | [{{ : | ||
| + | |||
| + | The main function resides in " | ||
| <code c> | <code c> | ||
| Line 123: | Line 161: | ||
| void DoCarDriving(tCar *pCar); | void DoCarDriving(tCar *pCar); | ||
| void PrepareCar(void); | void PrepareCar(void); | ||
| - | </ | ||
| - | |||
| - | <code c> | ||
| - | void GrPolyDraw(const tContext *pContext, const tPoint *pPoints, | ||
| - | | ||
| - | void GrPolyFill(const tContext *pContext, const tPoint *pPoints, | ||
| - | | ||
| </ | </ | ||