OpenGTA/tools/blockview.cpp

235 lines
5.3 KiB
C++
Raw Permalink Normal View History

2015-12-03 00:37:02 +00:00
#include <iostream>
#include <SDL_opengl.h>
#include "opengta.h"
2015-12-03 00:38:22 +00:00
#include "dataholder.h"
#include "gl_screen.h"
#include "gl_camera.h"
#include "log.h"
2015-12-03 00:37:02 +00:00
2015-12-03 00:38:22 +00:00
Uint32 arg_screen_w = 0;
Uint32 arg_screen_h = 0;
std::string map_file("NYC.CMP");
Vector3D e(3, 3, 3);
Vector3D c(0.5f, 0.5f, 0.5f);
Vector3D u(0, 1, 0);
uint8_t which = 0;
float r = 0;
bool wireframe = true;
extern int global_EC;
extern int global_Done;
2015-12-03 00:37:02 +00:00
2015-12-03 00:38:22 +00:00
const size_t numBlockTypes = 53;
const size_t numFaces = 5;
float slope_raw_data[numBlockTypes][numFaces][4][3] = {
#include "slope2_data.h"
};
#define SLOPE_RAW_DATA slope_raw_data
2015-12-03 00:37:02 +00:00
void on_exit() {
SDL_Quit();
PHYSFS_deinit();
if (global_EC)
std::cerr << "Exiting after fatal problem - please see output above" << std::endl;
else
std::cout << "Goodbye" << std::endl;
}
2015-12-03 00:38:22 +00:00
void print_usage(const char*) {
}
void parse_args(int argc, char* argv[]) {
}
2015-12-03 00:37:02 +00:00
void handleKeyPress( SDL_keysym *keysym ) {
switch ( keysym->sym ) {
case SDLK_ESCAPE:
global_Done = 1;
break;
case SDLK_LEFT:
2015-12-03 00:38:22 +00:00
r -= 10;
2015-12-03 00:37:02 +00:00
break;
case SDLK_RIGHT:
2015-12-03 00:38:22 +00:00
r += 10;
break;
case SDLK_SPACE:
wireframe = (wireframe) ? false : true;
2015-12-03 00:37:02 +00:00
break;
case SDLK_UP:
2015-12-03 00:38:22 +00:00
which++;
if (which >= numBlockTypes)
which = numBlockTypes - 1;
INFO << "slope-type: " << int(which) << std::endl;
2015-12-03 00:37:02 +00:00
break;
case SDLK_DOWN:
2015-12-03 00:38:22 +00:00
if (which > 0)
which--;
INFO << "slope-type: " << int(which) << std::endl;
2015-12-03 00:37:02 +00:00
break;
2015-12-03 00:38:22 +00:00
2015-12-03 00:37:02 +00:00
default:
break;
}
}
2015-12-03 00:38:22 +00:00
void drawScene() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
OpenGL::ScreenHolder::Instance().set3DProjection();
OpenGL::CameraHolder::Instance().update(1);
glRotatef(r, 0, 1, 0);
glColor3f(0.5f, 1, 0.2f);
// lid
if (wireframe)
glBegin(GL_LINE_STRIP);
else
2015-12-03 00:37:02 +00:00
glBegin(GL_QUADS);
2015-12-03 00:38:22 +00:00
for (int j=0; j < 4; j++) {
glVertex3f(SLOPE_RAW_DATA[which][0][j][0],
SLOPE_RAW_DATA[which][0][j][1],
SLOPE_RAW_DATA[which][0][j][2]);
2015-12-03 00:37:02 +00:00
}
2015-12-03 00:38:22 +00:00
if (wireframe)
glVertex3f(SLOPE_RAW_DATA[which][0][0][0],
SLOPE_RAW_DATA[which][0][0][1],
SLOPE_RAW_DATA[which][0][0][2]);
glEnd();
glColor3f(0.1f, 0.5f, 1);
// top
if (which != 42 && which != 45) {
if (wireframe)
glBegin(GL_LINE_STRIP);
else
glBegin(GL_QUADS);
for (int j=0; j < 4; j++) {
glVertex3f(SLOPE_RAW_DATA[which][2][j][0],
SLOPE_RAW_DATA[which][2][j][1],
SLOPE_RAW_DATA[which][2][j][2]);
2015-12-03 00:37:02 +00:00
}
2015-12-03 00:38:22 +00:00
if (wireframe)
glVertex3f(SLOPE_RAW_DATA[which][2][0][0],
SLOPE_RAW_DATA[which][2][0][1],
SLOPE_RAW_DATA[which][2][0][2]);
2015-12-03 00:37:02 +00:00
glEnd();
}
2015-12-03 00:38:22 +00:00
glColor3f(1, 0.2f, 0.5f);
// bottom
if (which != 41 && which != 46) {
if (wireframe)
glBegin(GL_LINE_STRIP);
else
glBegin(GL_QUADS);
for (int j=0; j < 4; j++) {
glVertex3f(SLOPE_RAW_DATA[which][1][j][0],
SLOPE_RAW_DATA[which][1][j][1],
SLOPE_RAW_DATA[which][1][j][2]);
2015-12-03 00:37:02 +00:00
}
2015-12-03 00:38:22 +00:00
if (wireframe)
glVertex3f(SLOPE_RAW_DATA[which][1][0][0],
SLOPE_RAW_DATA[which][1][0][1],
SLOPE_RAW_DATA[which][1][0][2]);
2015-12-03 00:37:02 +00:00
glEnd();
}
2015-12-03 00:38:22 +00:00
glColor3f(0.4f, 0.1f, 0.6f);
// left
if (which != 44 && which != 48) {
if (wireframe)
glBegin(GL_LINE_STRIP);
else
glBegin(GL_QUADS);
for (int j=0; j < 4; j++) {
glVertex3f(SLOPE_RAW_DATA[which][3][j][0],
SLOPE_RAW_DATA[which][3][j][1],
SLOPE_RAW_DATA[which][3][j][2]);
2015-12-03 00:37:02 +00:00
}
2015-12-03 00:38:22 +00:00
if (wireframe)
glVertex3f(SLOPE_RAW_DATA[which][3][0][0],
SLOPE_RAW_DATA[which][3][0][1],
SLOPE_RAW_DATA[which][3][0][2]);
2015-12-03 00:37:02 +00:00
glEnd();
}
2015-12-03 00:38:22 +00:00
glColor3f(0.8f, 0.6f, 0.2f);
// right
if (which != 43 && which != 47) {
if (wireframe)
glBegin(GL_LINE_STRIP);
else
glBegin(GL_QUADS);
for (int j=0; j < 4; j++) {
glVertex3f(SLOPE_RAW_DATA[which][4][j][0],
SLOPE_RAW_DATA[which][4][j][1],
SLOPE_RAW_DATA[which][4][j][2]);
}
if (wireframe)
glVertex3f(SLOPE_RAW_DATA[which][4][0][0],
SLOPE_RAW_DATA[which][4][0][1],
SLOPE_RAW_DATA[which][4][0][2]);
2015-12-03 00:37:02 +00:00
glEnd();
}
2015-12-03 00:38:22 +00:00
SDL_GL_SwapBuffers();
2015-12-03 00:37:02 +00:00
}
2015-12-03 00:38:22 +00:00
void run_init(const char* prg) {
PHYSFS_init("blockview");
PHYSFS_addToSearchPath("gtadata.zip", 1);
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
OpenGL::Screen & screen = OpenGL::ScreenHolder::Instance();
screen.activate(arg_screen_w, arg_screen_h);
SDL_EnableKeyRepeat( 100, SDL_DEFAULT_REPEAT_INTERVAL );
2015-12-03 00:37:02 +00:00
2015-12-03 00:38:22 +00:00
OpenGTA::MainMsgHolder::Instance().load("ENGLISH.FXT");
OpenGTA::MapHolder::Instance().load(map_file);
OpenGL::CameraHolder::Instance().setVectors(e, c, u);
}
2015-12-03 00:37:02 +00:00
void run_main() {
SDL_Event event;
int paused = 0;
2015-12-03 00:38:22 +00:00
PHYSFS_init("blockview");
2015-12-03 00:37:02 +00:00
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
2015-12-03 00:38:22 +00:00
glPolygonMode(GL_FRONT, GL_FILL);
2015-12-03 00:37:02 +00:00
glEnable(GL_CULL_FACE);
2015-12-03 00:38:22 +00:00
2015-12-03 00:37:02 +00:00
while(!global_Done && !global_EC) {
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_ACTIVEEVENT:
if (event.active.gain == 0)
paused = 1;
else
paused = 0;
break;
case SDL_KEYDOWN:
handleKeyPress(&event.key.keysym);
break;
case SDL_VIDEORESIZE:
break;
case SDL_QUIT:
global_Done = 1;
break;
case SDL_MOUSEMOTION:
break;
default:
break;
}
}
if (!paused)
drawScene();
}
}