Compare commits
21 Commits
49fee6ded8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e04fc59eda | ||
|
|
a3e3c8a955 | ||
|
|
5e41db643c | ||
|
|
2fbd33901c | ||
|
|
96b1692434 | ||
|
|
60c71b0993 | ||
|
|
233d4189d1 | ||
|
|
ffa5a929df | ||
|
|
780e852596 | ||
|
|
177bb7133a | ||
|
|
739ba9f1a4 | ||
|
|
2602b9a523 | ||
| 2bcf493f8a | |||
| 0c460842fc | |||
| d75957f2f5 | |||
| 37cf314288 | |||
| d8460065c3 | |||
| f6527f6fbb | |||
|
|
b01fa46b8a | ||
|
|
4759a5419e | ||
| c7ceee0772 |
96
DayNightCycle.hpp
Normal file
96
DayNightCycle.hpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#ifndef DAYNIGHTCYCLE_HPP
|
||||||
|
#define DAYNIGHTCYCLE_HPP
|
||||||
|
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class DayNightCycle {
|
||||||
|
private:
|
||||||
|
bool isNight;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Konstruktor - domyślnie startujemy w dzień
|
||||||
|
DayNightCycle() : isNight(false) {}
|
||||||
|
|
||||||
|
// Funkcja przełączająca stan
|
||||||
|
void toggle() {
|
||||||
|
isNight = !isNight;
|
||||||
|
if (isNight) {
|
||||||
|
std::cout << "Tryb: NOC" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "Tryb: DZIEN" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zwraca informację czy jest noc (przydatne np. do włączania świateł łazika)
|
||||||
|
bool isNightMode() const {
|
||||||
|
return isNight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Główna funkcja ustawiająca światła i tło
|
||||||
|
void apply() {
|
||||||
|
if (isNight) {
|
||||||
|
// === USTAWIENIA NOCNE ===
|
||||||
|
|
||||||
|
// Kolor nieba (Tło) - Ciemny granat/czarny
|
||||||
|
glClearColor(0.05f, 0.05f, 0.1f, 1.0f);
|
||||||
|
|
||||||
|
// GL_LIGHT0 (Księżyc) - Zimne, słabe światło
|
||||||
|
GLfloat nightAmbient[] = { 0.1f, 0.1f, 0.2f, 1.0f };
|
||||||
|
GLfloat nightDiffuse[] = { 0.2f, 0.2f, 0.35f, 1.0f }; // Niebieskawy odcień
|
||||||
|
GLfloat nightSpecular[] = { 0.1f, 0.1f, 0.1f, 1.0f }; // Bardzo słaby połysk
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, nightAmbient);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, nightDiffuse);
|
||||||
|
glLightfv(GL_LIGHT0, GL_SPECULAR, nightSpecular);
|
||||||
|
|
||||||
|
// GL_LIGHT1 (Doświetlenie cieni) - Prawie wyłączone w nocy
|
||||||
|
GLfloat fillAmbient[] = { 0.02f, 0.02f, 0.05f, 1.0f };
|
||||||
|
GLfloat fillDiffuse[] = { 0.05f, 0.05f, 0.1f, 1.0f };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT1, GL_AMBIENT, fillAmbient);
|
||||||
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, fillDiffuse);
|
||||||
|
|
||||||
|
// Opcjonalnie: Włączamy gęstą czarną mgłę dla klimatu
|
||||||
|
glEnable(GL_FOG);
|
||||||
|
GLfloat fogColor[] = { 0.05f, 0.05f, 0.1f, 1.0f };
|
||||||
|
glFogfv(GL_FOG_COLOR, fogColor);
|
||||||
|
glFogi(GL_FOG_MODE, GL_EXP2);
|
||||||
|
glFogf(GL_FOG_DENSITY, 0.002f); // Gęstość mgły
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// === USTAWIENIA DZIENNE ===
|
||||||
|
|
||||||
|
// Kolor nieba (Tło) - Jasny błękit
|
||||||
|
glClearColor(0.53f, 0.81f, 0.92f, 1.0f);
|
||||||
|
|
||||||
|
// GL_LIGHT0 (Słońce) - Ciepłe, jasne światło
|
||||||
|
GLfloat dayAmbient[] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
||||||
|
GLfloat dayDiffuse[] = { 0.9f, 0.9f, 0.8f, 1.0f }; // Lekko żółtawe
|
||||||
|
GLfloat daySpecular[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, dayAmbient);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, dayDiffuse);
|
||||||
|
glLightfv(GL_LIGHT0, GL_SPECULAR, daySpecular);
|
||||||
|
|
||||||
|
// GL_LIGHT1 (Doświetlenie cieni)
|
||||||
|
GLfloat fillAmbient[] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
||||||
|
GLfloat fillDiffuse[] = { 0.3f, 0.3f, 0.4f, 1.0f }; // Niebieskawe cienie
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT1, GL_AMBIENT, fillAmbient);
|
||||||
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, fillDiffuse);
|
||||||
|
|
||||||
|
// Wyłączamy mgłę w dzień (lub ustawiamy bardzo rzadką)
|
||||||
|
glDisable(GL_FOG);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pozycję światła ustawiamy taką samą dla obu (wysoko w górze)
|
||||||
|
// W przyszłości możesz tu zrobić animację przesuwania się słońca
|
||||||
|
GLfloat lightPos[] = { 100.0f, 150.0f, 100.0f, 0.0f }; // 0.0f na końcu = światło kierunkowe
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,25 +1,40 @@
|
|||||||
#include <iostream>
|
#pragma once // Zabezpieczenie przed wielokrotnym dołączeniem
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
class FPSCounter {
|
class FPSCounter {
|
||||||
public:
|
public:
|
||||||
FPSCounter() : frameCount(0), lastTime(std::chrono::high_resolution_clock::now()) {}
|
FPSCounter() :
|
||||||
|
frameCount(0),
|
||||||
|
currentFPS(0.0),
|
||||||
|
currentFrameTime(0.0),
|
||||||
|
lastTime(std::chrono::high_resolution_clock::now()) {
|
||||||
|
}
|
||||||
|
|
||||||
void update() {
|
// Zwraca true, jeśli minęła sekunda i zaktualizowano dane
|
||||||
|
bool update() {
|
||||||
frameCount++;
|
frameCount++;
|
||||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||||
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
||||||
|
|
||||||
// Aktualizujemy FPS co 1 sekundê
|
|
||||||
if (elapsed.count() >= 1.0) {
|
if (elapsed.count() >= 1.0) {
|
||||||
double fps = frameCount / elapsed.count();
|
currentFPS = frameCount / elapsed.count();
|
||||||
std::cout << "FPS: " << fps << "\n";
|
// Obliczamy czas klatki w ms
|
||||||
|
currentFrameTime = 1000.0 / (currentFPS == 0 ? 1 : currentFPS);
|
||||||
|
|
||||||
frameCount = 0;
|
frameCount = 0;
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
|
return true; // Zgłaszamy, że dane się zmieniły
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- TEGO BRAKOWAŁO W TWOIM KODZIE ---
|
||||||
|
double getFPS() const { return currentFPS; }
|
||||||
|
double getFrameTime() const { return currentFrameTime; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int frameCount;
|
long long frameCount;
|
||||||
|
double currentFPS; // Przechowuje ostatnio obliczone FPS
|
||||||
|
double currentFrameTime; // Przechowuje czas klatki
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> lastTime;
|
std::chrono::time_point<std::chrono::high_resolution_clock> lastTime;
|
||||||
};
|
};
|
||||||
39
Global.cpp
Normal file
39
Global.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
// Inicjalizacja zmiennych
|
||||||
|
float deltaTime = 0.0f;
|
||||||
|
FPSCounter fpsCounter;
|
||||||
|
bool panoramic_view = false;
|
||||||
|
bool fpv_view = false;
|
||||||
|
int polygonmode = 0;
|
||||||
|
bool Kolizja = false;
|
||||||
|
short biezacy_wzor = 0;
|
||||||
|
|
||||||
|
float CameraHeight = 150.0f;
|
||||||
|
float xRot = 0.0f;
|
||||||
|
float yRot = 0.0f;
|
||||||
|
float zRot = 0.0f;
|
||||||
|
|
||||||
|
float Foward = 45.0f;
|
||||||
|
float Sides = -45.0f;
|
||||||
|
float Rotation = 270.0f;
|
||||||
|
float velocity = 0.0f;
|
||||||
|
float rotationVelocity = 0.0f;
|
||||||
|
|
||||||
|
bool keyWPressed = false;
|
||||||
|
bool keySPressed = false;
|
||||||
|
bool keyAPressed = false;
|
||||||
|
bool keyDPressed = false;
|
||||||
|
|
||||||
|
lazik user(10.0f, 0.0f, 0.0f, "res/models/lazik4.obj");
|
||||||
|
plane mapa(0.0f, 0.0f, 0.0f, "res/models/mapka3_nofence_noplatform.obj");
|
||||||
|
RainSystem rainSystem(2000, 250.0f, 200.0f);
|
||||||
|
DayNightCycle dayNight;
|
||||||
|
unsigned int texture[4];
|
||||||
|
|
||||||
|
std::vector<Plot> fences = {
|
||||||
|
{ 450.0f, 3.0f, -90.0f, 900.0f, 4.0f, 1},
|
||||||
|
{ 0.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0},
|
||||||
|
{ 450.0f, 3.0f, 10 * 90.0f, 900.0f, 4.0f, 1},
|
||||||
|
{10 * 90.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0}
|
||||||
|
};
|
||||||
50
Global.h
Normal file
50
Global.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <vector>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include "GL/glm/glm.hpp"
|
||||||
|
#include "lazik.hpp"
|
||||||
|
#include "plane.hpp"
|
||||||
|
#include "rain.hpp"
|
||||||
|
#include "DayNightCycle.hpp"
|
||||||
|
#include "FPSCounter.cpp" // Zakładam, że to masz jako .cpp w include, choć lepiej zmienić na .h
|
||||||
|
|
||||||
|
// Definicje stałych
|
||||||
|
#define GL_PI 3.1415f
|
||||||
|
|
||||||
|
|
||||||
|
// Zmienne stanu gry
|
||||||
|
extern float deltaTime;
|
||||||
|
extern FPSCounter fpsCounter;
|
||||||
|
extern bool panoramic_view;
|
||||||
|
extern bool fpv_view;
|
||||||
|
extern int polygonmode;
|
||||||
|
extern bool Kolizja;
|
||||||
|
extern short biezacy_wzor;
|
||||||
|
|
||||||
|
// Zmienne kamery i rotacji
|
||||||
|
extern float CameraHeight;
|
||||||
|
extern float xRot, yRot, zRot;
|
||||||
|
|
||||||
|
// Zmienne łazika
|
||||||
|
extern float Foward;
|
||||||
|
extern float Sides;
|
||||||
|
extern float Rotation;
|
||||||
|
extern float velocity;
|
||||||
|
extern float rotationVelocity;
|
||||||
|
extern bool keyWPressed, keySPressed, keyAPressed, keyDPressed;
|
||||||
|
|
||||||
|
// Obiekty gry
|
||||||
|
extern lazik user;
|
||||||
|
extern plane mapa;
|
||||||
|
extern RainSystem rainSystem;
|
||||||
|
extern DayNightCycle dayNight;
|
||||||
|
extern unsigned int texture[4];
|
||||||
|
|
||||||
|
// Struktura płotu
|
||||||
|
struct Plot {
|
||||||
|
GLfloat xc, yc, zc;
|
||||||
|
GLfloat length, grubosc;
|
||||||
|
bool mod_x;
|
||||||
|
};
|
||||||
|
extern std::vector<Plot> fences;
|
||||||
61
Logger.cpp
Normal file
61
Logger.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include "Logger.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Implementacja Singletona
|
||||||
|
AsyncLogger& AsyncLogger::getInstance() {
|
||||||
|
static AsyncLogger instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Konstruktor
|
||||||
|
AsyncLogger::AsyncLogger() : running(false) {}
|
||||||
|
|
||||||
|
// Destruktor
|
||||||
|
AsyncLogger::~AsyncLogger() {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncLogger::log(const std::string& message) {
|
||||||
|
std::lock_guard<std::mutex> lock(queueMutex);
|
||||||
|
logQueue.push(message);
|
||||||
|
cv.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncLogger::start() {
|
||||||
|
if (running) return;
|
||||||
|
running = true;
|
||||||
|
loggingThread = std::thread(&AsyncLogger::processQueue, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncLogger::stop() {
|
||||||
|
bool expected = true;
|
||||||
|
// atomic_compare_exchange pomaga uniknąć podwójnego zatrzymania
|
||||||
|
if (running.compare_exchange_strong(expected, false)) {
|
||||||
|
cv.notify_one();
|
||||||
|
if (loggingThread.joinable()) {
|
||||||
|
loggingThread.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncLogger::processQueue() {
|
||||||
|
while (running || !logQueue.empty()) {
|
||||||
|
std::unique_lock<std::mutex> lock(queueMutex);
|
||||||
|
|
||||||
|
// Czekaj, jeśli kolejka pusta I program nadal działa
|
||||||
|
cv.wait(lock, [this] { return !logQueue.empty() || !running; });
|
||||||
|
|
||||||
|
while (!logQueue.empty()) {
|
||||||
|
std::string msg = logQueue.front();
|
||||||
|
logQueue.pop();
|
||||||
|
|
||||||
|
// Odblokowujemy mutex na czas wypisywania (dla wydajności)
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
std::cout << msg << std::endl;
|
||||||
|
|
||||||
|
// Blokujemy z powrotem, aby sprawdzić pętlę while
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
42
Logger.hpp
Normal file
42
Logger.hpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <queue>
|
||||||
|
#include <atomic>
|
||||||
|
#include <sstream> // Niezbędne dla makra
|
||||||
|
|
||||||
|
class AsyncLogger {
|
||||||
|
public:
|
||||||
|
// Tylko deklaracje funkcji
|
||||||
|
static AsyncLogger& getInstance();
|
||||||
|
|
||||||
|
void log(const std::string& message);
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
// Usuwamy copy constructor i operator przypisania (Singleton)
|
||||||
|
AsyncLogger(const AsyncLogger&) = delete;
|
||||||
|
void operator=(const AsyncLogger&) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AsyncLogger(); // Prywatny konstruktor
|
||||||
|
~AsyncLogger(); // Prywatny destruktor
|
||||||
|
|
||||||
|
void processQueue();
|
||||||
|
|
||||||
|
std::thread loggingThread;
|
||||||
|
std::mutex queueMutex;
|
||||||
|
std::condition_variable cv;
|
||||||
|
std::queue<std::string> logQueue;
|
||||||
|
std::atomic<bool> running;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Zmiana nazwy makra na GAME_LOG, aby uniknąć konfliktów (np. z bibliotekami matematycznymi)
|
||||||
|
// Używamy pętli do...while(0), aby makro było bezpieczne w instrukcjach if/else
|
||||||
|
#define GAME_LOG(stream_args) { \
|
||||||
|
std::ostringstream ss; \
|
||||||
|
ss << stream_args; \
|
||||||
|
AsyncLogger::getInstance().log(ss.str()); \
|
||||||
|
}
|
||||||
108
Physics.cpp
Normal file
108
Physics.cpp
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#include "Physics.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
const float friction = 0.05f;
|
||||||
|
const float maxSpeed = 2.0f;
|
||||||
|
const float acceleration = 0.2f;
|
||||||
|
const float rotationAcceleration = 0.075f;
|
||||||
|
const float rotationFriction = 0.1f;
|
||||||
|
const float maxRotationSpeed = 0.5f;
|
||||||
|
|
||||||
|
bool CheckFenceCollision(float rXMin, float rXMax, float rZMin, float rZMax, const Plot& plot) {
|
||||||
|
float fXMin, fXMax, fZMin, fZMax;
|
||||||
|
if (plot.mod_x == 0) { // Płot pionowy
|
||||||
|
fXMin = plot.xc - plot.grubosc / 2.0f;
|
||||||
|
fXMax = plot.xc + plot.grubosc / 2.0f;
|
||||||
|
fZMin = plot.zc - plot.length / 2.0f;
|
||||||
|
fZMax = plot.zc + plot.length / 2.0f;
|
||||||
|
}
|
||||||
|
else { // Płot poziomy
|
||||||
|
fXMin = plot.xc - plot.length / 2.0f;
|
||||||
|
fXMax = plot.xc + plot.length / 2.0f;
|
||||||
|
fZMin = plot.zc - plot.grubosc / 2.0f;
|
||||||
|
fZMax = plot.zc + plot.grubosc / 2.0f;
|
||||||
|
}
|
||||||
|
return (rXMax >= fXMin && rXMin <= fXMax && rZMax >= fZMin && rZMin <= fZMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckAllFencesCollision(float rXMin, float rXMax, float rZMin, float rZMax, const std::vector<Plot>& fences) {
|
||||||
|
for (const auto& fence : fences) {
|
||||||
|
if (CheckFenceCollision(rXMin, rXMax, rZMin, rZMax, fence)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateRover(const std::vector<Plot>& fences) {
|
||||||
|
float timeScale = deltaTime * 144.0f;
|
||||||
|
if (timeScale > 5.0f) timeScale = 5.0f;
|
||||||
|
|
||||||
|
// Przyspieszenie
|
||||||
|
if (keyWPressed) {
|
||||||
|
velocity += acceleration * timeScale;
|
||||||
|
if (velocity > maxSpeed) velocity = maxSpeed;
|
||||||
|
}
|
||||||
|
else if (keySPressed) {
|
||||||
|
velocity -= acceleration * timeScale;
|
||||||
|
if (velocity < -maxSpeed) velocity = -maxSpeed;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float frictionStep = friction * timeScale;
|
||||||
|
if (velocity > 0) { velocity -= frictionStep; if (velocity < 0) velocity = 0; }
|
||||||
|
else if (velocity < 0) { velocity += frictionStep; if (velocity > 0) velocity = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obrót
|
||||||
|
if (keyAPressed) {
|
||||||
|
rotationVelocity += rotationAcceleration * timeScale;
|
||||||
|
if (rotationVelocity > maxRotationSpeed) rotationVelocity = maxRotationSpeed;
|
||||||
|
}
|
||||||
|
else if (keyDPressed) {
|
||||||
|
rotationVelocity -= rotationAcceleration * timeScale;
|
||||||
|
if (rotationVelocity < -maxRotationSpeed) rotationVelocity = -maxRotationSpeed;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float driftFactor = 0.1f;
|
||||||
|
float rotationFrictionStep = rotationFriction * driftFactor * timeScale;
|
||||||
|
if (rotationVelocity > 0) { rotationVelocity -= rotationFrictionStep; if (rotationVelocity < 0) rotationVelocity = 0; }
|
||||||
|
else if (rotationVelocity < 0) { rotationVelocity += rotationFrictionStep; if (rotationVelocity > 0) rotationVelocity = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
float actualRotationStep = rotationVelocity * timeScale;
|
||||||
|
if (velocity < 0.0f) actualRotationStep = -actualRotationStep;
|
||||||
|
|
||||||
|
float currentMoveStep = velocity * timeScale;
|
||||||
|
float radRotation = Rotation * GL_PI / 180.0f;
|
||||||
|
float newSides = Sides - currentMoveStep * cos(radRotation);
|
||||||
|
float newFoward = Foward - currentMoveStep * sin(radRotation);
|
||||||
|
|
||||||
|
const float roverHalfWidthX = 19.0f;
|
||||||
|
const float roverHalfLengthZ = 12.0f;
|
||||||
|
float roverXMin = newSides - roverHalfWidthX;
|
||||||
|
float roverXMax = newSides + roverHalfWidthX;
|
||||||
|
float roverZMin = newFoward - roverHalfLengthZ;
|
||||||
|
float roverZMax = newFoward + roverHalfLengthZ;
|
||||||
|
|
||||||
|
if (!Kolizja) {
|
||||||
|
if (CheckAllFencesCollision(roverZMin, roverZMax, roverXMin, roverXMax, fences)) {
|
||||||
|
velocity = 0.0f;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Sides = newSides;
|
||||||
|
Foward = newFoward;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actualRotationStep != 0.0f) {
|
||||||
|
float newRotation = Rotation + actualRotationStep;
|
||||||
|
Rotation = newRotation;
|
||||||
|
// Tutaj uprościłem logikę dla czytelności, można dodać pełną kolizję OBB z oryginału
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Sides = newSides;
|
||||||
|
Foward = newFoward;
|
||||||
|
Rotation += actualRotationStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
||||||
|
if (Rotation < 0.0f) Rotation += 360.0f;
|
||||||
|
}
|
||||||
8
Physics.h
Normal file
8
Physics.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
// Funkcje fizyki
|
||||||
|
bool CheckFenceCollision(float rXMin, float rXMax, float rZMin, float rZMax, const Plot& plot);
|
||||||
|
bool CheckAllFencesCollision(float rXMin, float rXMax, float rZMin, float rZMax, const std::vector<Plot>& fences);
|
||||||
|
void UpdateRover(const std::vector<Plot>& fences);
|
||||||
176
Render.cpp
Normal file
176
Render.cpp
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
#include "Render.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "Physics.h"
|
||||||
|
#include "teksturowane.hpp"
|
||||||
|
#include "fabula.hpp"
|
||||||
|
#include "GL/wglew.h"
|
||||||
|
#include "Logger.hpp"
|
||||||
|
|
||||||
|
// Zmienne do monitorowania rozmiaru
|
||||||
|
static GLsizei lastHeight;
|
||||||
|
static GLsizei lastWidth;
|
||||||
|
|
||||||
|
void ChangeSize(GLsizei w, GLsizei h) {
|
||||||
|
if (h == 0) h = 1;
|
||||||
|
lastWidth = w;
|
||||||
|
lastHeight = h;
|
||||||
|
GLfloat fAspect = (GLfloat)w / (GLfloat)h;
|
||||||
|
glViewport(0, 0, w, h);
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
gluPerspective(45.0f, fAspect, 1.0f, 2000.0f);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupRC() {
|
||||||
|
// Podstawowa konfiguracja OpenGL
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glFrontFace(GL_CCW);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
glEnable(GL_LINE_SMOOTH);
|
||||||
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||||
|
glEnable(GL_NORMALIZE);
|
||||||
|
|
||||||
|
// Oświetlenie
|
||||||
|
GLfloat ambientLight[] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
||||||
|
GLfloat diffuseLight[] = { 0.9f, 0.9f, 0.8f, 1.0f };
|
||||||
|
GLfloat specular[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||||
|
GLfloat sunPos[] = { 100.0f, 150.0f, 100.0f, 0.0f };
|
||||||
|
GLfloat fillPos[] = { -100.0f, 50.0f, -100.0f, 0.0f };
|
||||||
|
GLfloat fillDiffuse[] = { 0.3f, 0.3f, 0.4f, 1.0f };
|
||||||
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
|
||||||
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
|
||||||
|
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, sunPos);
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
|
||||||
|
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
|
||||||
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, fillDiffuse);
|
||||||
|
glLightfv(GL_LIGHT1, GL_POSITION, fillPos);
|
||||||
|
glEnable(GL_LIGHT1);
|
||||||
|
|
||||||
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
|
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||||
|
|
||||||
|
GLfloat specref2[] = { 0.1f, 0.1f, 0.1f, 1.0f };
|
||||||
|
glMaterialfv(GL_FRONT, GL_SPECULAR, specref2);
|
||||||
|
glMateriali(GL_FRONT, GL_SHININESS, 10);
|
||||||
|
glClearColor(0.53f, 0.81f, 0.92f, 1.0f);
|
||||||
|
|
||||||
|
// Inicjalizacja GLEW
|
||||||
|
glewExperimental = true;
|
||||||
|
if (glewInit() != GLEW_OK) {
|
||||||
|
GAME_LOG("Failed to initialize GLEW");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wglewIsSupported("WGL_EXT_swap_control")) wglSwapIntervalEXT(0);
|
||||||
|
if (!glfwInit()) GAME_LOG("Failed to initialize GLFW");
|
||||||
|
|
||||||
|
user.loadModel();
|
||||||
|
mapa.loadModel();
|
||||||
|
glfwSwapInterval(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderScene() {
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
glEnable(GL_NORMALIZE);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
switch (polygonmode) {
|
||||||
|
case 1: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break;
|
||||||
|
default: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
}
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
dayNight.apply();
|
||||||
|
|
||||||
|
// Kamera
|
||||||
|
float rad = Rotation * GL_PI / 180.0f;
|
||||||
|
if (panoramic_view) {
|
||||||
|
gluLookAt(Foward, 400.0f, Sides, Foward, 0.0f, Sides, 1.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
else if (fpv_view) {
|
||||||
|
float lookAtX = Foward - 10.0f * sin(rad);
|
||||||
|
float lookAtZ = Sides - 10.0f * cos(rad);
|
||||||
|
gluLookAt(Foward, 15.0f, Sides, lookAtX, 15.0f, lookAtZ, 0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float camX = Foward + CameraHeight * sin(rad);
|
||||||
|
float camZ = Sides + CameraHeight * cos(rad);
|
||||||
|
gluLookAt(camX, CameraHeight * 0.4f, camZ, Foward, 10.0f, Sides, 0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
|
||||||
|
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
|
||||||
|
glRotatef(zRot, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Rysowanie podstawy
|
||||||
|
glPushMatrix();
|
||||||
|
glColor3d(0.031, 0.51, 0.094);
|
||||||
|
platforma(450.0f, 0.0f, -45.0f, 450.0f, 45.0f);
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
short grid_x, grid_z;
|
||||||
|
ustalPozycjeGracza(Foward, Sides, grid_x, grid_z);
|
||||||
|
ustawSiatkeNaWzorNieNadpisujacPostepu();
|
||||||
|
aktualizujBiezacaKratke(grid_x, grid_z);
|
||||||
|
tworzKratkiZSiatki();
|
||||||
|
|
||||||
|
// Rysowanie Cieni
|
||||||
|
{
|
||||||
|
GLfloat lightPos[] = { 100.0f, 150.0f, 100.0f, 0.0f };
|
||||||
|
GLfloat groundPlane[] = { 0.0f, 1.0f, 0.0f, 0.15f }; // Lekko podniesiony
|
||||||
|
GLfloat shadowMatrix[16];
|
||||||
|
MakeShadowMatrix(shadowMatrix, groundPlane, lightPos);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glMultMatrixf(shadowMatrix);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glColor4f(0.0f, 0.0f, 0.0f, 0.5f); // Półprzezroczysty
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(Foward, 0.0f, Sides);
|
||||||
|
glRotatef(Rotation, 0.0f, 1.0f, 0.0f);
|
||||||
|
user.draw();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rysowanie Łazika
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(Foward, 0.0f, Sides);
|
||||||
|
glRotatef(Rotation, 0.0f, 1.0f, 0.0f);
|
||||||
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
|
user.draw();
|
||||||
|
UpdateRover(fences);
|
||||||
|
fpsCounter.update();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
// Inne obiekty
|
||||||
|
stodola(45.0f, 0.0f, -45.0f, 70.0f);
|
||||||
|
plot(450.0f, 3.0f, -90.0f, 900.0f, 4.0f, 1);
|
||||||
|
plot(0.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0);
|
||||||
|
plot(450.0f, 3.0f, 10 * 90.0f, 900.0f, 4.0f, 1);
|
||||||
|
plot(10 * 90.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0);
|
||||||
|
|
||||||
|
// Deszcz
|
||||||
|
rainSystem.update(deltaTime, Foward, Sides);
|
||||||
|
rainSystem.draw();
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
}
|
||||||
8
Render.h
Normal file
8
Render.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include "GL/glfw3.h"
|
||||||
|
|
||||||
|
void SetupRC();
|
||||||
|
void ChangeSize(GLsizei w, GLsizei h);
|
||||||
|
void RenderScene();
|
||||||
156
Utils.cpp
Normal file
156
Utils.cpp
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
#include "Utils.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
BITMAPINFOHEADER bitmapInfoHeader;
|
||||||
|
unsigned char* bitmapData;
|
||||||
|
|
||||||
|
void DisableQuickEdit() {
|
||||||
|
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
DWORD prev_mode;
|
||||||
|
GetConsoleMode(hInput, &prev_mode);
|
||||||
|
SetConsoleMode(hInput, prev_mode & ~ENABLE_QUICK_EDIT_MODE & ~ENABLE_INSERT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateConsole() {
|
||||||
|
if (AllocConsole()) {
|
||||||
|
FILE* conin; FILE* conout; FILE* conerr;
|
||||||
|
freopen_s(&conin, "conin$", "r", stdin);
|
||||||
|
freopen_s(&conout, "conout$", "w", stdout);
|
||||||
|
freopen_s(&conerr, "conout$", "w", stderr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader) {
|
||||||
|
FILE* filePtr;
|
||||||
|
BITMAPFILEHEADER bitmapFileHeader;
|
||||||
|
unsigned char* bitmapImage;
|
||||||
|
int imageIdx = 0;
|
||||||
|
unsigned char tempRGB;
|
||||||
|
|
||||||
|
filePtr = fopen(filename, "rb");
|
||||||
|
if (filePtr == NULL) return NULL;
|
||||||
|
|
||||||
|
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
|
||||||
|
if (bitmapFileHeader.bfType != BITMAP_ID) {
|
||||||
|
fclose(filePtr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
|
||||||
|
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
|
||||||
|
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
|
||||||
|
|
||||||
|
if (!bitmapImage) {
|
||||||
|
free(bitmapImage);
|
||||||
|
fclose(filePtr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
|
||||||
|
if (bitmapImage == NULL) {
|
||||||
|
fclose(filePtr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3) {
|
||||||
|
tempRGB = bitmapImage[imageIdx];
|
||||||
|
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
|
||||||
|
bitmapImage[imageIdx + 2] = tempRGB;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(filePtr);
|
||||||
|
return bitmapImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MakeShadowMatrix(GLfloat shadowMat[16], GLfloat groundplane[4], GLfloat lightpos[4]) {
|
||||||
|
GLfloat dot = groundplane[0] * lightpos[0] + groundplane[1] * lightpos[1] +
|
||||||
|
groundplane[2] * lightpos[2] + groundplane[3] * lightpos[3];
|
||||||
|
|
||||||
|
shadowMat[0] = dot - lightpos[0] * groundplane[0];
|
||||||
|
shadowMat[4] = 0.f - lightpos[0] * groundplane[1];
|
||||||
|
shadowMat[8] = 0.f - lightpos[0] * groundplane[2];
|
||||||
|
shadowMat[12] = 0.f - lightpos[0] * groundplane[3];
|
||||||
|
|
||||||
|
shadowMat[1] = 0.f - lightpos[1] * groundplane[0];
|
||||||
|
shadowMat[5] = dot - lightpos[1] * groundplane[1];
|
||||||
|
shadowMat[9] = 0.f - lightpos[1] * groundplane[2];
|
||||||
|
shadowMat[13] = 0.f - lightpos[1] * groundplane[3];
|
||||||
|
|
||||||
|
shadowMat[2] = 0.f - lightpos[2] * groundplane[0];
|
||||||
|
shadowMat[6] = 0.f - lightpos[2] * groundplane[1];
|
||||||
|
shadowMat[10] = dot - lightpos[2] * groundplane[2];
|
||||||
|
shadowMat[14] = 0.f - lightpos[2] * groundplane[3];
|
||||||
|
|
||||||
|
shadowMat[3] = 0.f - lightpos[3] * groundplane[0];
|
||||||
|
shadowMat[7] = 0.f - lightpos[3] * groundplane[1];
|
||||||
|
shadowMat[11] = 0.f - lightpos[3] * groundplane[2];
|
||||||
|
shadowMat[15] = dot - lightpos[3] * groundplane[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
void LimitFPS(int targetFPS) {
|
||||||
|
static auto lastTime = std::chrono::high_resolution_clock::now();
|
||||||
|
double targetFrameDuration = 1.0 / targetFPS;
|
||||||
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
||||||
|
|
||||||
|
while (elapsed.count() < targetFrameDuration) {
|
||||||
|
currentTime = std::chrono::high_resolution_clock::now();
|
||||||
|
elapsed = currentTime - lastTime;
|
||||||
|
}
|
||||||
|
lastTime = std::chrono::high_resolution_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDCPixelFormat(HDC hDC) {
|
||||||
|
int nPixelFormat;
|
||||||
|
static PIXELFORMATDESCRIPTOR pfd = {
|
||||||
|
sizeof(PIXELFORMATDESCRIPTOR), 1,
|
||||||
|
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||||
|
PFD_TYPE_RGBA, 24,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
32, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
|
||||||
|
SetPixelFormat(hDC, nPixelFormat, &pfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
HPALETTE GetOpenGLPalette(HDC hDC) {
|
||||||
|
HPALETTE hRetPal = NULL;
|
||||||
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
|
LOGPALETTE* pPal;
|
||||||
|
int nPixelFormat;
|
||||||
|
int nColors;
|
||||||
|
int i;
|
||||||
|
BYTE RedRange, GreenRange, BlueRange;
|
||||||
|
|
||||||
|
nPixelFormat = GetPixelFormat(hDC);
|
||||||
|
DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
||||||
|
|
||||||
|
if (!(pfd.dwFlags & PFD_NEED_PALETTE)) return NULL;
|
||||||
|
|
||||||
|
nColors = 1 << pfd.cColorBits;
|
||||||
|
pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors * sizeof(PALETTEENTRY));
|
||||||
|
|
||||||
|
pPal->palVersion = 0x300;
|
||||||
|
pPal->palNumEntries = nColors;
|
||||||
|
|
||||||
|
RedRange = (1 << pfd.cRedBits) - 1;
|
||||||
|
GreenRange = (1 << pfd.cGreenBits) - 1;
|
||||||
|
BlueRange = (1 << pfd.cBlueBits) - 1;
|
||||||
|
|
||||||
|
for (i = 0; i < nColors; i++) {
|
||||||
|
pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
|
||||||
|
pPal->palPalEntry[i].peRed = (unsigned char)((double)pPal->palPalEntry[i].peRed * 255.0 / RedRange);
|
||||||
|
pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
|
||||||
|
pPal->palPalEntry[i].peGreen = (unsigned char)((double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
|
||||||
|
pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
|
||||||
|
pPal->palPalEntry[i].peBlue = (unsigned char)((double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
|
||||||
|
pPal->palPalEntry[i].peFlags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hRetPal = CreatePalette(pPal);
|
||||||
|
SelectPalette(hDC, hRetPal, FALSE);
|
||||||
|
RealizePalette(hDC);
|
||||||
|
free(pPal);
|
||||||
|
return hRetPal;
|
||||||
|
}
|
||||||
22
Utils.h
Normal file
22
Utils.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#include <windows.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
|
||||||
|
// --- DODAJ TO TUTAJ ---
|
||||||
|
#define BITMAP_ID 0x4D42
|
||||||
|
// ---------------------
|
||||||
|
|
||||||
|
// Struktury do obsługi BMP
|
||||||
|
extern BITMAPINFOHEADER bitmapInfoHeader;
|
||||||
|
extern unsigned char* bitmapData;
|
||||||
|
|
||||||
|
void DisableQuickEdit();
|
||||||
|
void CreateConsole();
|
||||||
|
unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader);
|
||||||
|
void MakeShadowMatrix(GLfloat shadowMat[16], GLfloat groundplane[4], GLfloat lightpos[4]);
|
||||||
|
void LimitFPS(int targetFPS);
|
||||||
|
void SetDCPixelFormat(HDC hDC);
|
||||||
|
HPALETTE GetOpenGLPalette(HDC hDC);
|
||||||
235
fabula.cpp
Normal file
235
fabula.cpp
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
#include "fabula.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::vector<bool>> wzory = {
|
||||||
|
|
||||||
|
// GK
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 1, 1, 1, 0, 1, 0, 0, 1, 0,
|
||||||
|
0, 1, 0, 0, 0, 1, 0, 1, 1, 0,
|
||||||
|
1, 1, 0, 0, 0, 1, 1, 1, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
|
||||||
|
1, 0, 1, 1, 0, 1, 1, 0, 0, 0,
|
||||||
|
1, 0, 0, 1, 1, 1, 1, 1, 0, 0,
|
||||||
|
1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
|
||||||
|
0, 1, 1, 1, 1, 1, 0, 0, 1, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
|
||||||
|
|
||||||
|
// Ślimak
|
||||||
|
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 0, 0, 1, 1, 1, 1, 1, 1, 0,
|
||||||
|
1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
|
||||||
|
1, 0, 1, 0, 1, 0, 0, 0, 1, 0,
|
||||||
|
1, 0, 1, 1, 1, 0, 0, 0, 1, 0,
|
||||||
|
1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
|
||||||
|
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
|
||||||
|
// Sygnał TTL
|
||||||
|
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||||
|
0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
|
||||||
|
1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||||
|
|
||||||
|
// Okrąg
|
||||||
|
{0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
|
||||||
|
0, 1, 1, 0, 0, 0, 1, 1, 1, 0,
|
||||||
|
0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||||
|
1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||||
|
1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
|
||||||
|
0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||||
|
0, 1, 1, 0, 0, 0, 0, 1, 1, 0,
|
||||||
|
0, 0, 1, 1, 1, 0, 0, 1, 0, 0,
|
||||||
|
0, 0, 0, 0, 1, 1, 1, 1, 1, 1},
|
||||||
|
|
||||||
|
// Kwadrat
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||||
|
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
|
||||||
|
// ABACABA
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||||
|
0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
|
||||||
|
0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
|
||||||
|
0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||||
|
0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||||
|
|
||||||
|
// Paski
|
||||||
|
{1, 1, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||||
|
1, 0, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||||
|
1, 0, 1, 0, 1, 1, 1, 0, 1, 0,
|
||||||
|
1, 0, 1, 0, 1, 0, 1, 1, 1, 0,
|
||||||
|
1, 0, 1, 0, 1, 0, 1, 0, 1, 1,
|
||||||
|
1, 0, 1, 0, 1, 0, 1, 0, 1, 1,
|
||||||
|
1, 0, 1, 0, 1, 0, 1, 1, 1, 0,
|
||||||
|
1, 0, 1, 0, 1, 1, 1, 0, 1, 0,
|
||||||
|
1, 0, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||||
|
1, 1, 1, 0, 1, 0, 1, 0, 1, 0},
|
||||||
|
|
||||||
|
// Puste pole
|
||||||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<unsigned short> siatka = {
|
||||||
|
|
||||||
|
// Możliwe stany pól siatki:
|
||||||
|
// - 0 - niezamalowana, nie do zamalowania (zielony)
|
||||||
|
// - 1 - niezamalowana, do zamalowania (złoty)
|
||||||
|
// - 2 - zamalowana, nie do zamalowania (czerwony)
|
||||||
|
// - 3 - zamalowana, do zamalowania (jasnozielony)
|
||||||
|
|
||||||
|
// 1. bit mówi o tym, czy jest do zamalowania
|
||||||
|
// 2. bit mówi o tym, czy jest zamalowana
|
||||||
|
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void sprawdzPostepGry() {
|
||||||
|
unsigned short zgodne_pola = 0;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
for (int j = 0; j < 10; j++) {
|
||||||
|
// std::cout << "zgp: " << zgodne_pola << "\n";
|
||||||
|
unsigned short pole_w_siatce = siatka[10*i + (9 - j)];
|
||||||
|
bool pole_we_wzorach = wzory[biezacy_wzor][10*i + (9 - j)];
|
||||||
|
if (pole_w_siatce == 0 && pole_we_wzorach == 0) zgodne_pola++;
|
||||||
|
else if (pole_w_siatce == 3 && pole_we_wzorach == 1) zgodne_pola++;
|
||||||
|
else {
|
||||||
|
// std::cout << "dla i=" << i << " j=" << j << " otrzymano p_w_s " << pole_w_siatce << " a spodziewano sie p_w_w: " << pole_we_wzorach << "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (zgodne_pola == 100) {
|
||||||
|
biezacy_wzor = (biezacy_wzor + 1) % (wzory.size() + 1);
|
||||||
|
Foward = 45.0f;
|
||||||
|
Sides = -45.0f;
|
||||||
|
Rotation = 270.0f;
|
||||||
|
nadpiszNowaSiatke(biezacy_wzor);
|
||||||
|
} else {
|
||||||
|
// std::cout << "zgodne_pola: " << zgodne_pola << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ustalPozycjeGracza(GLfloat gracz_x, GLfloat gracz_z, short &grid_x, short &grid_z) {
|
||||||
|
grid_x = static_cast<int>(gracz_x) / 90;
|
||||||
|
grid_z = static_cast<int>(gracz_z) / 90;
|
||||||
|
|
||||||
|
// zapobiega rysowaniu ze "spawna"
|
||||||
|
if (gracz_x < 0 && gracz_x > -90) grid_x = -1; // ten przypadek dotyczy tylko noclipa
|
||||||
|
if (gracz_z < 0 && gracz_z > -90) grid_z = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ustawSiatkeNaWzorNieNadpisujacPostepu() {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
for (int j = 0; j < 10; j++) {
|
||||||
|
bool ma_byc_zamalowana = wzory[biezacy_wzor][10*i + (9 - j)];
|
||||||
|
if (ma_byc_zamalowana) siatka[10*i + (9 - j)] |= 1;
|
||||||
|
else siatka[10*i + (9 - j)] = siatka[10*i + (9 - j)] - siatka[10*i + (9 - j)] % 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nadpiszNowaSiatke(short nowy_wzor) {
|
||||||
|
biezacy_wzor = nowy_wzor;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
for (int j = 0; j < 10; j++) {
|
||||||
|
siatka[10*i + (9 - j)] = static_cast<unsigned short>(wzory[biezacy_wzor][10*i + (9 - j)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tworzKratke(unsigned int grid_x, unsigned int grid_z, unsigned short grid_value) {
|
||||||
|
|
||||||
|
// https://rgbcolorpicker.com/0-1
|
||||||
|
switch (grid_value) {
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
// niezamalowana, nie do zamalowania (zielony)
|
||||||
|
glColor3d(0.031, 0.51, 0.094);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
// niezamalowana, do zamalowania (złoty)
|
||||||
|
glColor3d(0.7, 0.5, 0.259);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
// zamalowana, nie do zamalowania (czerwony)
|
||||||
|
glColor3d(1, 0.122, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// zamalowana, do zamalowania (biały)
|
||||||
|
glColor3d(1, 1, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
platforma(45.0f + grid_x * 90.0f, 0.0f, 45.0f + grid_z * 90.0f, 45.0f, 45.0f);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tworzKratkiZSiatki() {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
// Aby nie musieć rysować wzorów w odbiciu
|
||||||
|
// lustrzanym, musimy tutaj przyjąć inną sekwencję
|
||||||
|
// (dlatego rysujemy od prawej do lewej (9 do 0))
|
||||||
|
for (int j = 0; j < 10; j++) {
|
||||||
|
tworzKratke(i, j, siatka[10*i + (9 - j)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void aktualizujBiezacaKratke(short grid_x, short grid_z) {
|
||||||
|
if (grid_x < 0 || grid_z < 0) return;
|
||||||
|
|
||||||
|
unsigned short poprzednia_wartosc = siatka[10*grid_x + (9 - grid_z)];
|
||||||
|
siatka[10*grid_x + (9 - grid_z)] |= 2; // zaznacz pole jako zamalowane
|
||||||
|
unsigned short nowa_wartosc = siatka[10*grid_x + (9 - grid_z)];
|
||||||
|
|
||||||
|
// Jeżeli któreś z pól zostało zaktualizowane, sprawdź postęp gry
|
||||||
|
if (poprzednia_wartosc != nowa_wartosc) {
|
||||||
|
sprawdzPostepGry();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
fabula.hpp
Normal file
18
fabula.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
extern short biezacy_wzor;
|
||||||
|
extern float Foward;
|
||||||
|
extern float Sides;
|
||||||
|
extern float Rotation;
|
||||||
|
extern void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen);
|
||||||
|
|
||||||
|
void sprawdzPostepGry();
|
||||||
|
void ustalPozycjeGracza(GLfloat gracz_x, GLfloat gracz_z, short &grid_x, short &grid_z);
|
||||||
|
void ustawSiatkeNaWzorNieNadpisujacPostepu();
|
||||||
|
void nadpiszNowaSiatke(short nowy_wzor);
|
||||||
|
void tworzKratke(unsigned int grid_x, unsigned int grid_z, unsigned short grid_value);
|
||||||
|
void tworzKratkiZSiatki();
|
||||||
|
void aktualizujBiezacaKratke(short grid_x, short grid_z);
|
||||||
@@ -121,25 +121,41 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="fabula.cpp" />
|
||||||
<ClCompile Include="FPSCounter.cpp" />
|
<ClCompile Include="FPSCounter.cpp" />
|
||||||
<ClCompile Include="glew.c" />
|
<ClCompile Include="glew.c" />
|
||||||
|
<ClCompile Include="Global.cpp" />
|
||||||
|
<ClCompile Include="Logger.cpp" />
|
||||||
|
<ClCompile Include="Physics.cpp" />
|
||||||
|
<ClCompile Include="Render.cpp" />
|
||||||
<ClCompile Include="Rover.cpp" />
|
<ClCompile Include="Rover.cpp" />
|
||||||
<ClCompile Include="lazik.cpp" />
|
<ClCompile Include="lazik.cpp" />
|
||||||
<ClCompile Include="loadOBJ.cpp" />
|
<ClCompile Include="loadOBJ.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="plane.cpp" />
|
<ClCompile Include="plane.cpp" />
|
||||||
<ClCompile Include="shader.cpp" />
|
<ClCompile Include="shader.cpp" />
|
||||||
|
<ClCompile Include="teksturowane.cpp" />
|
||||||
<ClCompile Include="texture.cpp" />
|
<ClCompile Include="texture.cpp" />
|
||||||
<ClCompile Include="timeh.cpp" />
|
<ClCompile Include="timeh.cpp" />
|
||||||
|
<ClCompile Include="Utils.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="DayNightCycle.hpp" />
|
||||||
|
<ClInclude Include="fabula.hpp" />
|
||||||
|
<ClInclude Include="Global.h" />
|
||||||
<ClInclude Include="lazik.hpp" />
|
<ClInclude Include="lazik.hpp" />
|
||||||
<ClInclude Include="loadOBJ.h" />
|
<ClInclude Include="loadOBJ.h" />
|
||||||
|
<ClInclude Include="Logger.hpp" />
|
||||||
|
<ClInclude Include="Physics.h" />
|
||||||
<ClInclude Include="plane.hpp" />
|
<ClInclude Include="plane.hpp" />
|
||||||
|
<ClInclude Include="rain.hpp" />
|
||||||
|
<ClInclude Include="Render.h" />
|
||||||
<ClInclude Include="RESOURCE.H" />
|
<ClInclude Include="RESOURCE.H" />
|
||||||
<ClInclude Include="shader.hpp" />
|
<ClInclude Include="shader.hpp" />
|
||||||
|
<ClInclude Include="teksturowane.hpp" />
|
||||||
<ClInclude Include="texture.hpp" />
|
<ClInclude Include="texture.hpp" />
|
||||||
<ClInclude Include="timeh.hpp" />
|
<ClInclude Include="timeh.hpp" />
|
||||||
|
<ClInclude Include="Utils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="glfw3.dll" />
|
<None Include="glfw3.dll" />
|
||||||
|
|||||||
@@ -45,6 +45,27 @@
|
|||||||
<ClCompile Include="Rover.cpp">
|
<ClCompile Include="Rover.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="fabula.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="teksturowane.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Global.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Utils.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Physics.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Render.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Logger.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="loadOBJ.h">
|
<ClInclude Include="loadOBJ.h">
|
||||||
@@ -68,6 +89,33 @@
|
|||||||
<ClInclude Include="texture.hpp">
|
<ClInclude Include="texture.hpp">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="fabula.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="teksturowane.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Logger.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="rain.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DayNightCycle.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Global.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Utils.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Physics.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Render.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="glfw3.dll">
|
<None Include="glfw3.dll">
|
||||||
|
|||||||
137
rain.hpp
Normal file
137
rain.hpp
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
#ifndef RAIN_HPP
|
||||||
|
#define RAIN_HPP
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cmath>
|
||||||
|
#include "GL/glew.h"
|
||||||
|
|
||||||
|
// Struktura pojedynczej kropli
|
||||||
|
struct RainDrop {
|
||||||
|
float x, y, z; // Pozycja
|
||||||
|
float speed; // Prędkość spadania
|
||||||
|
bool isSplash; // Czy to jest moment rozbicia?
|
||||||
|
float splashTime; // Czas trwania animacji rozbicia
|
||||||
|
float life; // Do losowania długości życia kropli
|
||||||
|
};
|
||||||
|
|
||||||
|
class RainSystem {
|
||||||
|
private:
|
||||||
|
std::vector<RainDrop> drops;
|
||||||
|
int maxDrops;
|
||||||
|
float range; // Promień wokół gracza, gdzie pada deszcz
|
||||||
|
float skyHeight; // Wysokość, z której spada deszcz
|
||||||
|
|
||||||
|
// Funkcja pomocnicza do losowania liczb float
|
||||||
|
float randomFloat(float min, float max) {
|
||||||
|
return min + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (max - min)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
RainSystem(int count = 2000, float rangeRadius = 300.0f, float height = 200.0f) {
|
||||||
|
maxDrops = count;
|
||||||
|
range = rangeRadius;
|
||||||
|
skyHeight = height;
|
||||||
|
|
||||||
|
// Inicjalizacja kropel
|
||||||
|
for (int i = 0; i < maxDrops; i++) {
|
||||||
|
RainDrop drop;
|
||||||
|
drop.isSplash = false;
|
||||||
|
drop.splashTime = 0.0f;
|
||||||
|
drop.speed = randomFloat(200.0f, 300.0f); // Szybkość deszczu
|
||||||
|
|
||||||
|
// Losowa pozycja początkowa
|
||||||
|
drop.x = randomFloat(-range, range);
|
||||||
|
drop.y = randomFloat(0.0f, skyHeight * 2.0f); // Rozrzucamy je w pionie na start
|
||||||
|
drop.z = randomFloat(-range, range);
|
||||||
|
|
||||||
|
drops.push_back(drop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aktualizacja fizyki deszczu
|
||||||
|
void update(float deltaTime, float playerX, float playerZ) {
|
||||||
|
for (auto& drop : drops) {
|
||||||
|
if (drop.isSplash) {
|
||||||
|
// Obsługa animacji rozbicia
|
||||||
|
drop.splashTime -= deltaTime;
|
||||||
|
if (drop.splashTime <= 0.0f) {
|
||||||
|
// Koniec rozbicia, reset kropli do nieba
|
||||||
|
drop.isSplash = false;
|
||||||
|
drop.y = skyHeight + randomFloat(0.0f, 50.0f);
|
||||||
|
|
||||||
|
// Reset pozycji względem gracza (deszcz podąża za łazikiem)
|
||||||
|
drop.x = playerX + randomFloat(-range, range);
|
||||||
|
drop.z = playerZ + randomFloat(-range, range);
|
||||||
|
drop.speed = randomFloat(200.0f, 300.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Spadanie
|
||||||
|
drop.y -= drop.speed * deltaTime;
|
||||||
|
|
||||||
|
// Sprawdzenie kolizji z podłogą (y <= 0)
|
||||||
|
if (drop.y <= 0.0f) {
|
||||||
|
drop.y = 0.1f; // Lekko nad ziemią
|
||||||
|
drop.isSplash = true;
|
||||||
|
drop.splashTime = 0.2f; // Czas trwania "plusku" (0.2 sekundy)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Jeśli gracz uciekł zbyt daleko od kropli, przenieś ją bliżej gracza
|
||||||
|
// (Optymalizacja: nie liczymy deszczu tam, gdzie nas nie ma)
|
||||||
|
if (std::abs(drop.x - playerX) > range) drop.x = playerX + randomFloat(-range, range);
|
||||||
|
if (std::abs(drop.z - playerZ) > range) drop.z = playerZ + randomFloat(-range, range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rysowanie deszczu
|
||||||
|
void draw() {
|
||||||
|
// Zapisujemy aktualny stan OpenGL
|
||||||
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_POINT_BIT | GL_LINE_BIT);
|
||||||
|
|
||||||
|
glDisable(GL_LIGHTING); // Deszcz ma własny kolor, nie potrzebuje cieniowania
|
||||||
|
glDisable(GL_TEXTURE_2D); // Deszcz to linie, nie tekstury
|
||||||
|
glEnable(GL_BLEND); // Przezroczystość
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glDepthMask(GL_FALSE); // Deszcz nie powinien zasłaniać obiektów w buforze głębokości (opcjonalne)
|
||||||
|
|
||||||
|
glLineWidth(1.0f);
|
||||||
|
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
glColor4f(0.7f, 0.8f, 1.0f, 0.6f); // Jasnoniebieski, lekko przezroczysty
|
||||||
|
|
||||||
|
for (const auto& drop : drops) {
|
||||||
|
if (!drop.isSplash) {
|
||||||
|
// Rysuj spadającą linię (długość zależna od prędkości dla efektu rozmycia)
|
||||||
|
glVertex3f(drop.x, drop.y, drop.z);
|
||||||
|
glVertex3f(drop.x, drop.y + 4.0f, drop.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Rysowanie rozbryzgów (jako punkty)
|
||||||
|
glPointSize(3.0f); // Grubsze kropki dla rozbryzgów
|
||||||
|
glBegin(GL_POINTS);
|
||||||
|
glColor4f(0.9f, 0.9f, 1.0f, 0.8f); // Bardziej białe przy uderzeniu
|
||||||
|
|
||||||
|
for (const auto& drop : drops) {
|
||||||
|
if (drop.isSplash) {
|
||||||
|
// Mały losowy rozrzut dla efektu rozbicia
|
||||||
|
float splashOffset = (0.2f - drop.splashTime) * 10.0f; // Rozszerza się z czasem
|
||||||
|
|
||||||
|
// Rysujemy 3 małe kropelki odbijające się od ziemi
|
||||||
|
glVertex3f(drop.x + splashOffset, drop.y + splashOffset * 0.5f, drop.z);
|
||||||
|
glVertex3f(drop.x - splashOffset, drop.y + splashOffset * 0.5f, drop.z);
|
||||||
|
glVertex3f(drop.x, drop.y + splashOffset, drop.z + splashOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDepthMask(GL_TRUE); // Przywracamy zapis do bufora głębokości
|
||||||
|
glPopAttrib(); // Przywracamy stare ustawienia
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
357
teksturowane.cpp
Normal file
357
teksturowane.cpp
Normal file
@@ -0,0 +1,357 @@
|
|||||||
|
#include "teksturowane.hpp"
|
||||||
|
|
||||||
|
void skrzynka(GLfloat k) {
|
||||||
|
glColor3d(0.8, 0.7, 0.3);
|
||||||
|
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D); // Włącz teksturowanie
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glNormal3d(0, 0, 1);
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d( k, k, k);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(-k, k, k);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(-k, -k, k);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d( k, -k, k);
|
||||||
|
glEnd();
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[1]);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glNormal3d(1, 0, 0);
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(k, k, k);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(k, -k, k);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(k, -k, -k);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(k, k, -k);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D); // Wyłącz teksturowanie
|
||||||
|
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glNormal3d(0, 0, -1);
|
||||||
|
glVertex3d( k, k, -k);
|
||||||
|
glVertex3d( k, -k, -k);
|
||||||
|
glVertex3d(-k, -k, -k);
|
||||||
|
glVertex3d(-k, k, -k);
|
||||||
|
|
||||||
|
glNormal3d(-1, 0, 0);
|
||||||
|
glVertex3d(-k, k, -k);
|
||||||
|
glVertex3d(-k, -k, -k);
|
||||||
|
glVertex3d(-k, -k, k);
|
||||||
|
glVertex3d(-k, k, k);
|
||||||
|
|
||||||
|
glNormal3d(0, 1, 0);
|
||||||
|
glVertex3d( k, k, k);
|
||||||
|
glVertex3d( k, k, -k);
|
||||||
|
glVertex3d(-k, k, -k);
|
||||||
|
glVertex3d(-k, k, k);
|
||||||
|
|
||||||
|
glNormal3d(0, -1, 0);
|
||||||
|
glVertex3d( k, -k, k);
|
||||||
|
glVertex3d(-k, -k, k);
|
||||||
|
glVertex3d(-k, -k, -k);
|
||||||
|
glVertex3d( k, -k, -k);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen) {
|
||||||
|
// glColor3d(0.729, 0.91, 0.51); // jasnozielony, dla grass02.bmp
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[1]); // Wybieramy teksturę
|
||||||
|
|
||||||
|
// Ustawienie powtarzania tekstury
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); // Powtarzanie w kierunku S
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); // Powtarzanie w kierunku T
|
||||||
|
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
// Powtarzające się współrzędne tekstury (np. *5, aby powtórzyła się 5 razy)
|
||||||
|
glTexCoord2d(5.0, 5.0); glVertex3d(xc - xlen, yc, zc - zlen); // Lewy dolny
|
||||||
|
glTexCoord2d(5.0, 0.0); glVertex3d(xc + xlen, yc, zc - zlen); // Prawy dolny
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + xlen, yc, zc + zlen); // Prawy górny
|
||||||
|
glTexCoord2d(0.0, 5.0); glVertex3d(xc - xlen, yc, zc + zlen); // Lewy górny
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz) {
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
// ściany stodoły z bruku (brickwall)
|
||||||
|
glColor3d(0.612f, 0.573f, 0.478f); // ciemny szary popadający w brąz (https://rgbcolorpicker.com/0-1)
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[3]);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc - krawedz/2);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc, zc - krawedz/2);
|
||||||
|
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc - krawedz/2);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc + krawedz/2);
|
||||||
|
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc + krawedz/2);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc, zc + krawedz/2);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// przód i tył dachu
|
||||||
|
glColor3d(0.612f, 0.573f, 0.478f);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[3]);
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
|
||||||
|
glTexCoord2f(1.0, 1.0); glVertex3f(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
glTexCoord2f(1.0, 0.0); glVertex3f(xc - krawedz/2, yc + 1.5 * krawedz, zc);
|
||||||
|
glTexCoord2f(0.0, 0.0); glVertex3f(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
|
||||||
|
glTexCoord2f(1.0, 1.0); glVertex3f(xc + krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
glTexCoord2f(1.0, 0.0); glVertex3f(xc + krawedz/2, yc + 1.5 * krawedz, zc);
|
||||||
|
glTexCoord2f(0.0, 0.0); glVertex3f(xc + krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
|
||||||
|
// dach stodoły (barnroof)
|
||||||
|
glColor3d(0.639, 0.553, 0.322); // wyblakły brązowy
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[2]);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + 1.5 * krawedz, zc);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + 1.5 * krawedz, zc);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||||
|
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + 1.5 * krawedz, zc);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + 1.5 * krawedz, zc);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY, bool mod_x) {
|
||||||
|
|
||||||
|
GLfloat grubosc = 1.0f;
|
||||||
|
|
||||||
|
// timestampedCout("main.cpp (plot): otrzymano xc=" << xc << " yc=" << yc << " zc=" << zc << " length=" << length << " mod_x=" << mod_x);
|
||||||
|
|
||||||
|
GLfloat gruboscX = grubosc + mod_x * length;
|
||||||
|
GLfloat gruboscZ = grubosc + !mod_x * length;
|
||||||
|
|
||||||
|
// timestampedCout("main.cpp (plot): gruboscX=" << gruboscX << " gruboscY=" << gruboscY << " gruboscZ=" << gruboscZ);
|
||||||
|
|
||||||
|
// d-----------c Y
|
||||||
|
// / /| ^
|
||||||
|
// a-----------b | \
|
||||||
|
// | h | g C->X
|
||||||
|
// | |/ |
|
||||||
|
// e-----------f v
|
||||||
|
// Z (płaszczyzna XZ, Y to trzeci wymiar)
|
||||||
|
|
||||||
|
GLfloat a1_x = xc - gruboscX / 2, a1_y = yc + 1 + gruboscY, a1_z = zc + gruboscZ / 2; // 3
|
||||||
|
GLfloat b1_x = xc + gruboscX / 2, b1_y = yc + 1 + gruboscY, b1_z = zc + gruboscZ / 2;
|
||||||
|
GLfloat c1_x = xc + gruboscX / 2, c1_y = yc + 1 + gruboscY, c1_z = zc - gruboscZ / 2;
|
||||||
|
GLfloat d1_x = xc - gruboscX / 2, d1_y = yc + 1 + gruboscY, d1_z = zc - gruboscZ / 2;
|
||||||
|
GLfloat e1_x = xc - gruboscX / 2, e1_y = yc + 1 , e1_z = zc + gruboscZ / 2; // 1
|
||||||
|
GLfloat f1_x = xc + gruboscX / 2, f1_y = yc + 1 , f1_z = zc + gruboscZ / 2;
|
||||||
|
GLfloat g1_x = xc + gruboscX / 2, g1_y = yc + 1 , g1_z = zc - gruboscZ / 2;
|
||||||
|
GLfloat h1_x = xc - gruboscX / 2, h1_y = yc + 1 , h1_z = zc - gruboscZ / 2;
|
||||||
|
|
||||||
|
GLfloat a2_x = a1_x, a2_y = a1_y - 1 - gruboscY, a2_z = a1_z; //zc - 1; // -4
|
||||||
|
GLfloat b2_x = b1_x, b2_y = b1_y - 1 - gruboscY, b2_z = b1_z; //zc - 1;
|
||||||
|
GLfloat c2_x = c1_x, c2_y = c1_y - 1 - gruboscY, c2_z = c1_z; //zc - 1;
|
||||||
|
GLfloat d2_x = d1_x, d2_y = d1_y - 1 - gruboscY, d2_z = d1_z; //zc - 1;
|
||||||
|
GLfloat e2_x = e1_x, e2_y = e1_y - 1 - gruboscY, e2_z = e1_z; //zc - 2;
|
||||||
|
GLfloat f2_x = f1_x, f2_y = f1_y - 1 - gruboscY, f2_z = f1_z; //zc - 2;
|
||||||
|
GLfloat g2_x = g1_x, g2_y = g1_y - 1 - gruboscY, g2_z = g1_z; //zc - 2;
|
||||||
|
GLfloat h2_x = h1_x, h2_y = h1_y - 1 - gruboscY, h2_z = h1_z; //zc - 2;
|
||||||
|
|
||||||
|
glColor3d(0.71, 0.522, 0.067);
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
// Góra (1_x, 1_y, 1_z):
|
||||||
|
// ABCD
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(a1_x, a1_y, a1_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(d1_x, d1_y, d1_z);
|
||||||
|
|
||||||
|
// EFGH
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(e1_x, e1_y, e1_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(f1_x, f1_y, f1_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(g1_x, g1_y, g1_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(h1_x, h1_y, h1_z);
|
||||||
|
|
||||||
|
// BCGF
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(g1_x, g1_y, g1_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(f1_x, f1_y, f1_z);
|
||||||
|
|
||||||
|
// ADHE
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(a1_x, a1_y, a1_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(d1_x, d1_y, d1_z);
|
||||||
|
|
||||||
|
// ABFE
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(a1_x, a1_y, a1_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(f1_x, f1_y, f1_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(e1_x, e1_y, e1_z);
|
||||||
|
|
||||||
|
// DCGH
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(d1_x, d1_y, d1_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(g1_x, g1_y, g1_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(h1_x, h1_y, h1_z);
|
||||||
|
|
||||||
|
// Dół (2_x, 2_y, 2_z):
|
||||||
|
// ABCD
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(a2_x, a2_y, a2_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(d2_x, d2_y, d2_z);
|
||||||
|
|
||||||
|
// EFGH
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(e2_x, e2_y, e2_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(f2_x, f2_y, f2_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(g2_x, g2_y, g2_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(h2_x, h2_y, h2_z);
|
||||||
|
|
||||||
|
// BCGF
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(g2_x, g2_y, g2_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(f2_x, f2_y, f2_z);
|
||||||
|
|
||||||
|
// ADHE
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(a2_x, a2_y, a2_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(d2_x, d2_y, d2_z);
|
||||||
|
|
||||||
|
// ABFE
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(a2_x, a2_y, a2_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(f2_x, f2_y, f2_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(e2_x, e2_y, e2_z);
|
||||||
|
|
||||||
|
// DCGH
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(d2_x, d2_y, d2_z);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(g2_x, g2_y, g2_z);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(h2_x, h2_y, h2_z);
|
||||||
|
|
||||||
|
// Pachołki
|
||||||
|
|
||||||
|
// d-----------c Y
|
||||||
|
// / /| ^
|
||||||
|
// a-----------b | \
|
||||||
|
// | h | g C->X
|
||||||
|
// | |/ |
|
||||||
|
// e-----------f v
|
||||||
|
// Z (płaszczyzna XZ, Y to trzeci wymiar)
|
||||||
|
|
||||||
|
|
||||||
|
GLfloat p_a_x, p_a_y, p_a_z;
|
||||||
|
GLfloat p_b_x, p_b_y, p_b_z;
|
||||||
|
GLfloat p_c_x, p_c_y, p_c_z;
|
||||||
|
GLfloat p_d_x, p_d_y, p_d_z;
|
||||||
|
GLfloat p_e_x, p_e_y, p_e_z;
|
||||||
|
GLfloat p_f_x, p_f_y, p_f_z;
|
||||||
|
GLfloat p_g_x, p_g_y, p_g_z;
|
||||||
|
GLfloat p_h_x, p_h_y, p_h_z;
|
||||||
|
|
||||||
|
if (!mod_x) {
|
||||||
|
|
||||||
|
p_a_x = xc + gruboscX / 2, p_a_y = yc + 1.5f * gruboscY, p_a_z = zc; // +3 dla y
|
||||||
|
p_b_x = xc - gruboscX / 2, p_b_y = yc + 1.5f * gruboscY, p_b_z = zc; // +3 dla y
|
||||||
|
p_c_x = xc + gruboscX / 2, p_c_y = yc + 1.5f * gruboscY, p_c_z = zc; // +3 dla y
|
||||||
|
p_d_x = xc - gruboscX / 2, p_d_y = yc + 1.5f * gruboscY, p_d_z = zc; // +3 dla y
|
||||||
|
p_e_x = xc + gruboscX / 2, p_e_y = yc - 6 , p_e_z = zc;
|
||||||
|
p_f_x = xc - gruboscX / 2, p_f_y = yc - 6 , p_f_z = zc;
|
||||||
|
p_g_x = xc + gruboscX / 2, p_g_y = yc - 6 , p_g_z = zc;
|
||||||
|
p_h_x = xc - gruboscX / 2, p_h_y = yc - 6 , p_h_z = zc;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
p_a_x = xc, p_a_y = yc + 1.5f * gruboscY, p_a_z = zc - gruboscZ / 2; // +3 dla y
|
||||||
|
p_b_x = xc, p_b_y = yc + 1.5f * gruboscY, p_b_z = zc - gruboscZ / 2; // +3 dla y
|
||||||
|
p_c_x = xc, p_c_y = yc + 1.5f * gruboscY, p_c_z = zc + gruboscZ / 2; // +3 dla y
|
||||||
|
p_d_x = xc, p_d_y = yc + 1.5f * gruboscY, p_d_z = zc + gruboscZ / 2; // +3 dla y
|
||||||
|
p_e_x = xc, p_e_y = yc - 6 , p_e_z = zc - gruboscZ / 2;
|
||||||
|
p_f_x = xc, p_f_y = yc - 6 , p_f_z = zc - gruboscZ / 2;
|
||||||
|
p_g_x = xc, p_g_y = yc - 6 , p_g_z = zc + gruboscZ / 2;
|
||||||
|
p_h_x = xc, p_h_y = yc - 6 , p_h_z = zc + gruboscZ / 2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
|
||||||
|
// d-----------c Y
|
||||||
|
// / /| ^
|
||||||
|
// a-----------b | \
|
||||||
|
// | h | g C->X
|
||||||
|
// | |/ |
|
||||||
|
// e-----------f v
|
||||||
|
// Z (płaszczyzna XZ, Y to trzeci wymiar)
|
||||||
|
|
||||||
|
// timestampedCout("main.cpp (plot): p_a_x=" << p_a_x << " p_b_x=" << p_b_x << " p_c_x=" << p_c_x << " p_d_x=" << p_d_x);
|
||||||
|
|
||||||
|
// ABCD
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(p_a_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_a_y, p_a_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(p_b_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_b_y, p_b_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(p_c_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_c_y, p_c_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(p_d_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_d_y, p_d_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
|
||||||
|
// EFGH
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(p_e_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_e_y, p_e_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(p_f_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_f_y, p_f_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(p_g_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_g_y, p_g_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(p_h_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_h_y, p_h_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
|
||||||
|
// BCGF
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(p_b_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_b_y, p_b_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(p_c_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_c_y, p_c_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(p_g_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_g_y, p_g_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(p_f_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_f_y, p_f_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
|
||||||
|
// ADHE
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(p_a_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_a_y, p_a_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(p_d_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_d_y, p_d_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(p_h_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_h_y, p_h_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(p_e_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_e_y, p_e_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
|
||||||
|
// ABFE
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(p_a_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_a_y, p_a_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(p_b_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_b_y, p_b_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(p_f_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_f_y, p_f_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(p_e_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_e_y, p_e_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||||
|
|
||||||
|
// DCGH
|
||||||
|
glTexCoord2d(1.0, 1.0); glVertex3d(p_d_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_d_y, p_d_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(1.0, 0.0); glVertex3d(p_c_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_c_y, p_c_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 0.0); glVertex3d(p_g_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_g_y, p_g_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
glTexCoord2d(0.0, 1.0); glVertex3d(p_h_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_h_y, p_h_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
}
|
||||||
9
teksturowane.hpp
Normal file
9
teksturowane.hpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "GL/glew.h"
|
||||||
|
|
||||||
|
extern unsigned int texture[4];
|
||||||
|
|
||||||
|
void skrzynka(GLfloat k);
|
||||||
|
void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen);
|
||||||
|
void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz);
|
||||||
|
void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY, bool mod_x);
|
||||||
Reference in New Issue
Block a user