Skip to content
Snippets Groups Projects
Commit 00cce7f9 authored by hermabe's avatar hermabe
Browse files

Added handouts for O12

parent d5ccb196
No related branches found
No related tags found
No related merge requests found
O12/Sprites/boostSprite.jpeg

13.1 KiB

O12/Sprites/peelSprite.jpeg

12.9 KiB

O12/Sprites/spillSprite.jpeg

15.3 KiB

#include <chrono>
#include <thread>
#include <memory>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include "utilities.h"
int main() {
auto win = std::make_unique<Fl_Double_Window>(screenWidth, screenHeight, "NASCAR");
win->color(FL_WHITE);
// Instansier nye objekt mellom dei to etterfølgjande linjene.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
win->end();
win->show();
auto nextDrawing = std::chrono::steady_clock::now();
while (win->shown())
{
// Sov til neste teikning
std::this_thread::sleep_until(nextDrawing);
nextDrawing += std::chrono::microseconds(1'000'000 / 60);
Fl::check(); // Handterar input
Fl::redraw(); // Kallar draw
}
}
\ No newline at end of file
#include "utilities.h"
void PhysicsState::slide(double slideAngle){
grip += 0.01 * (1 - grip);
speed -= 0.036 * grip * speed;
angle += 0.12 * grip;
x += speed * cos(slideAngle);
y += speed * sin(slideAngle);
}
void PhysicsState::update(double translationAcceleration, double angularAcceleration){
// Desse skal vere i intervallet [-1,1]
translationAcceleration = std::max(-1.0, std::min(1.0, translationAcceleration));
angularAcceleration = std::max(-1.0, std::min(1.0, angularAcceleration));
grip += 0.01 * (1 - grip);
speed += 0.006 * grip * translationAcceleration * (6 - abs(speed));
if ((speed > 0) != (translationAcceleration > 0)) // Bremsing
speed += 0.03 * grip * translationAcceleration;
angle += 0.03 * grip * angularAcceleration;
x += speed * cos(angle);
y += speed * sin(angle);
}
double angleBetween(std::pair<double, double> vec1, std::pair<double, double> vec2)
// Returnerer vinkel mellom to vektorar i radianar.
{
double dot = vec1.first * vec2.first + vec1.second * vec2.second;
double det = vec1.first * vec2.second - vec1.second * vec2.first;
return atan2(det, dot);
}
\ No newline at end of file
#pragma once
#include <tuple>
#include <vector>
#include <cmath>
#include <algorithm>
constexpr int screenWidth = 1000;
constexpr int screenHeight = 600;
constexpr double vehicleRadius = 15;
constexpr double goalRadius = 30;
constexpr double spillRadius = 20;
constexpr double boostRadius = 10;
constexpr double peelRadius = 5;
class PhysicsState{
public:
double x, y, angle, speed = 0, grip = 1;
void update(double translationAcceleration, double angularAcceleration);
void slide(double slideAngle);
};
double angleBetween(std::pair<double, double> vec1,std::pair<double, double> vec2);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment