Click here to Skip to main content
15,867,308 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: c++ sms send dll Pin
vidhya 360 com14-Oct-18 20:38
vidhya 360 com14-Oct-18 20:38 
QuestionSharpen filter of bmp image Pin
Jakub Bartczak27-Aug-18 21:21
Jakub Bartczak27-Aug-18 21:21 
AnswerRe: Sharpen filter of bmp image Pin
Jochen Arndt27-Aug-18 22:56
professionalJochen Arndt27-Aug-18 22:56 
Questionplease explain this lines of code Pin
Hiếu Ngô2-Aug-18 18:18
Hiếu Ngô2-Aug-18 18:18 
AnswerRe: please explain this lines of code Pin
Richard MacCutchan2-Aug-18 21:47
mveRichard MacCutchan2-Aug-18 21:47 
AnswerRe: please explain this lines of code Pin
Jochen Arndt2-Aug-18 22:29
professionalJochen Arndt2-Aug-18 22:29 
NewsC++/CLI support comes to ReSharper C++ Pin
John Schroedl23-Jul-18 6:22
professionalJohn Schroedl23-Jul-18 6:22 
QuestionTo find the angle of turn in a car racing game in C++/SFML Pin
Tarun Jha21-Jul-18 23:39
Tarun Jha21-Jul-18 23:39 
in the code below i would like to know how the logic of finding the angle at a turn works.

int main()
{
	RenderWindow app(VideoMode(640, 480), "Car Racing Game!");
	app.setFramerateLimit(60);

	Texture t1, t2;
	t1.loadFromFile("images/background.png");
	t2.loadFromFile("images/car.png");

	Sprite sBackground(t1), sCar(t2);
	sCar.setPosition(300, 300);
	sCar.setOrigin(22, 22);

	float x = 300, y = 300;
	float speed = 0, angle = 0;
	float maxSpeed = 12.0;
	float acc = 0.2, dec = 0.3;
	float turnSpeed = 0.08;

	while (app.isOpen())
	{
		Event event;
		while (app.pollEvent(event))
		{
			if (event.type == Event::Closed)
				app.close();
			if (Keyboard::isKeyPressed(Keyboard::Escape))
				app.close();
		}

		bool Up = false, Right = false, Down = false, Left = false;
		if (Keyboard::isKeyPressed(Keyboard::Up))		Up = true;
		if (Keyboard::isKeyPressed(Keyboard::Right))	Right = true;
		if (Keyboard::isKeyPressed(Keyboard::Down))		Down = true;
		if (Keyboard::isKeyPressed(Keyboard::Left))		Left = true;

		// Car Movements
		if (Up && speed < maxSpeed)
			if (speed < 0)	speed += dec;
			else speed += acc;

		if (Down && speed > -maxSpeed)
			if (speed > 0)	speed -= dec;
			else speed -= acc;

		if (!Up && !Down)
			if (speed - dec > 0)	speed -= dec;
			else if (speed + dec < 0)	speed += dec;
			else speed = 0;
                
                //--------- How this logic works ?
		if (Right && speed != 0)	angle += turnSpeed * speed / maxSpeed;
		if (Left && speed != 0)		angle -= turnSpeed * speed / maxSpeed;

		x += sin(angle) * speed ;
		y -= cos(angle) * speed ;
          
               //------------- //


		// Draw
		app.clear(Color::White);
		app.draw(sBackground);

		sCar.setPosition(x, y);
		sCar.setRotation(angle * 180 / 3.141592) ;
		sCar.setColor(Color::Red);
		app.draw(sCar);

		app.display();
	}
    return 0;
}


How the below logic works ?
Quote:
if (Right && speed != 0) angle += turnSpeed * speed / maxSpeed;
if (Left && speed != 0) angle -= turnSpeed * speed / maxSpeed;

x += sin(angle) * speed ;
y -= cos(angle) * speed ;


Thank you
AnswerRe: To find the angle of turn in a car racing game in C++/SFML Pin
John Schroedl23-Jul-18 6:41
professionalJohn Schroedl23-Jul-18 6:41 
GeneralRe: To find the angle of turn in a car racing game in C++/SFML Pin
Tarun Jha25-Jul-18 7:36
Tarun Jha25-Jul-18 7:36 
QuestionSmall RAII-like cleanup class in C++/CLI Pin
John Schroedl15-Jun-18 9:08
professionalJohn Schroedl15-Jun-18 9:08 
QuestionInformation Edit Source code for c++ Pin
Member 1165875229-May-18 19:48
Member 1165875229-May-18 19:48 
AnswerRe: Information Edit Source code for c++ Pin
Richard MacCutchan29-May-18 21:05
mveRichard MacCutchan29-May-18 21:05 
AnswerRe: Information Edit Source code for c++ Pin
Jochen Arndt30-May-18 2:55
professionalJochen Arndt30-May-18 2:55 
QuestionError On a Project I'm Working On. (Sorry If Not descriptive enough, 1st time) Pin
CyberFaggot9-May-18 15:53
CyberFaggot9-May-18 15:53 
AnswerRe: Error On a Project I'm Working On. (Sorry If Not descriptive enough, 1st time) Pin
Richard MacCutchan11-May-18 21:19
mveRichard MacCutchan11-May-18 21:19 
QuestionPrint causes in afxtls.cpp Pin
Erich Ruth19-Apr-18 5:37
Erich Ruth19-Apr-18 5:37 
AnswerRe: Print causes in afxtls.cpp Pin
Richard Andrew x6413-May-18 7:22
professionalRichard Andrew x6413-May-18 7:22 
QuestionWhat is the alternative of _kbhit_ in linux ? Pin
Tarun Jha16-Apr-18 4:04
Tarun Jha16-Apr-18 4:04 
AnswerRe: What is the alternative of _kbhit_ in linux ? Pin
Maria Okta25-Jul-18 19:23
professionalMaria Okta25-Jul-18 19:23 
QuestionMore Than One Operator "+" Matches These Operands Pin
Paramu197313-Apr-18 5:26
Paramu197313-Apr-18 5:26 
QuestionRe: More Than One Operator "+" Matches These Operands Pin
Richard MacCutchan13-Apr-18 5:51
mveRichard MacCutchan13-Apr-18 5:51 
AnswerRe: More Than One Operator "+" Matches These Operands Pin
Paramu197313-Apr-18 6:05
Paramu197313-Apr-18 6:05 
GeneralRe: More Than One Operator "+" Matches These Operands Pin
Richard MacCutchan13-Apr-18 6:40
mveRichard MacCutchan13-Apr-18 6:40 
GeneralRe: More Than One Operator "+" Matches These Operands Pin
Paramu197313-Apr-18 14:18
Paramu197313-Apr-18 14:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.