-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.h
65 lines (52 loc) · 1.49 KB
/
line.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef LINE_H
#define LINE_H
#include <QPixmap>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QString>
#include "game.h"
struct Line
{
float x,y,z; //3d center of line
float X,Y,W; //screen coord
float curve,spriteX,clip,scale;
QString fileToPixmap;
QPixmap pixmap;
Line()
: x(0), y(0), z(0), curve(0), spriteX(0)
{}
void project(int camX,int camY,int camZ)
{
scale = Game::camD/(z-camZ);
X = (1 + scale*(x - camX)) * Game::RESOLUTION.width()/2;
Y = (1 - scale*(y - camY)) * Game::RESOLUTION.height()/2;
W = scale * Game::roadW * Game::RESOLUTION.width()/2;
}
void drawSprite(QGraphicsScene *_scene)
{
QPixmap s = pixmap;
int w = s.rect().width();
int h = s.rect().height();
float destX = X + scale * spriteX * Game::RESOLUTION.width()/2;
float destY = Y + 4;
float destW = w * W / 266;
float destH = h * W / 266;
destX += destW * spriteX; //offsetX
destY += destH * (-1); //offsetY
float clipH = destY+destH-clip;
if (clipH < 0)
{
clipH=0;
}
if (clipH>=destH)
{
return;
}
QPixmap pixmap = s.copy(0,0,w ,h-h*clipH/destH);
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(destX, destY);
pixmapItem->setScale(destW/w);
_scene->addItem(pixmapItem);
}
};
#endif // LINE_H