Skip to content

akinbezatoglu/Wire-Car

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

Wire-Car

Creating an animated wire car using OpenGL. Wire Car is a project that I developed for the Computer Graphics lesson.

INTRODUCTION

This code creates a wire car that the user can play with steering and wheel movements. Four Tires, Cube, Axles, Steering Wheel, and Steering Column are required to create the Wire Car. In this code, the Tires function creates four tires, the DrawCube function creates cube, the SteeringWheel function creates the steering wheel and steering column, the Axles function creates axles.

1- The initial situation when the project is started. The tires seem to go forward. Initially, the wire car cannot be moved.

2- Tires rotate to the left when the 'A' key is pressed and to the right when the 'D' key is pressed.

3- The tires stop turning when the 'M' key is pressed. Turning the car forward, backward, left or right is left to the user. It can be moved forward by pressing the 'W' key, backward by pressing the 'S' key, left by pressing the 'A' key, and right by pressing the 'D' key.

Basic ideas that provide a leading role in the development of the wire car

Drawing Cube

void DrawCube(double* center, double heightlenRatio, double minorlenRatio, double majorlenRatio, double Ratio)

Front-right point of Wire Car = ( Cx - cos(β) * d, Cy + sin(β) * d , Cz )
Back-right point of Wire Car = ( Cx + cos(β) * d, Cy + sin(β) * d , Cz )
Front-left point of Wire Car = ( Cx - cos(β) * d, Cy - sin(β) * d , Cz )
Back-left point of Wire Car = ( Cx + cos(β) * d, Cy - sin(β) * d , Cz )

It is enough to raise these four points by h to get the cube.

Drawing Circle

void Tires(double radius, double num_segments) void SteeringWheel(double radius , double num_segments)

When you examine the code, you will ask why

Why do I calculate "d" to find the vertex points of the cube in figure 1 ? Why don't I just add or subtract x' and y' to the center?

The wire car is intended to provide forward, backward, left, right turn and movement with keyboard controls. This is basically achieved by forming all the determined points connected to the center. Therefore, the distance of the point to the center is calculated.

The understanding of why beta defined as 'CubeRotateAngle - 45'

Let us visualize that the x obtained according to the definition of 'x= x * cos(α) – y * sin(α) ' in Figure 2 is added to the x and y coordinates of the center. The front wheels looked like ellipses when I added the same value to the x and y coordinates of the center of the tires. I managed to fix this error on the rear tires, but when I tried the front wheels, this time I prevented the wheels from turning. c_b = cosf(beta *PI / 180; s_b = sinf(beta *PI / 180);

I tried this for the front wheels =>
x = (c_b - s_b) * x + cx;
y = (c_b - s_b) * x + cy;

I tried this for the rear wheels =>
x = cos(CubeRotateAngle * PI / 180) * x + cx;
y = sin(CubeRotateAngle * PI / 180) * x + cy;


Thus, the position of the rear wheels will always be parallel to the cube. Since no CubeRotateAngel is used on the front wheels, a 45-degree angle is formed as shown in figure 3. For the front wheels to be parallel to the cube, the initial value of beta must be equal to 'CubeRotateAngel'. For example, let us say CubeRotateAngel is 30. Beta would then be -15 degrees. This allows the front wheels to move about 15 degrees to the left. Since an angle of 45 degrees with respect to the x-axis is formed initially, 30 degrees is obtained from '45 + (-15) 'and the front wheels are made parallel to the cube.

REFERENCES

  1. https://learnopengl.com/Getting-started/Camera
  2. http://slabode.exofire.net/circle_draw.shtml
  3. https://stackoverflow.com/questions/4704986/switch-statement-using-or
  4. https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml
  5. https://www.opengl.org/resources/libraries/glut/spec3/node51.html
  6. https://www.opengl.org/resources/libraries/glut/spec3/node50.html
  7. https://www.opengl.org/resources/libraries/glut/spec3/node49.html
  8. https://www.opengl.org/resources/libraries/glut/spec3/node46.html

Releases

No releases published

Packages

No packages published

Languages