Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/Scene3DLegacy.cpp
1163 views
1
#include "v3/Scene3DLegacyv3.cpp"
2
#include "v4/Scene3DLegacyv4.cpp"
3
4
int32 RSDK::Legacy::vertexCount = 0;
5
int32 RSDK::Legacy::faceCount = 0;
6
7
RSDK::Legacy::Matrix RSDK::Legacy::matFinal;
8
RSDK::Legacy::Matrix RSDK::Legacy::matWorld;
9
RSDK::Legacy::Matrix RSDK::Legacy::matView;
10
RSDK::Legacy::Matrix RSDK::Legacy::matTemp;
11
12
int32 RSDK::Legacy::projectionX = 136;
13
int32 RSDK::Legacy::projectionY = 160;
14
15
int32 RSDK::Legacy::faceLineStart[SCREEN_YSIZE];
16
int32 RSDK::Legacy::faceLineEnd[SCREEN_YSIZE];
17
int32 RSDK::Legacy::faceLineStartU[SCREEN_YSIZE];
18
int32 RSDK::Legacy::faceLineEndU[SCREEN_YSIZE];
19
int32 RSDK::Legacy::faceLineStartV[SCREEN_YSIZE];
20
int32 RSDK::Legacy::faceLineEndV[SCREEN_YSIZE];
21
22
void RSDK::Legacy::ProcessScanEdge(Vertex *vertA, Vertex *vertB)
23
{
24
int32 bottom, top;
25
26
if (vertA->y == vertB->y)
27
return;
28
if (vertA->y >= vertB->y) {
29
top = vertB->y;
30
bottom = vertA->y + 1;
31
}
32
else {
33
top = vertA->y;
34
bottom = vertB->y + 1;
35
}
36
if (top > SCREEN_YSIZE - 1 || bottom < 0)
37
return;
38
if (bottom > SCREEN_YSIZE)
39
bottom = SCREEN_YSIZE;
40
int32 fullX = vertA->x << 16;
41
int32 deltaX = ((vertB->x - vertA->x) << 16) / (vertB->y - vertA->y);
42
if (top < 0) {
43
fullX -= top * deltaX;
44
top = 0;
45
}
46
for (int32 i = top; i < bottom; ++i) {
47
int32 trueX = fullX >> 16;
48
if (trueX < faceLineStart[i])
49
faceLineStart[i] = trueX;
50
if (trueX > faceLineEnd[i])
51
faceLineEnd[i] = trueX;
52
fullX += deltaX;
53
}
54
}
55
void RSDK::Legacy::ProcessScanEdgeUV(Vertex *vertA, Vertex *vertB)
56
{
57
int32 bottom, top;
58
59
if (vertA->y == vertB->y)
60
return;
61
if (vertA->y >= vertB->y) {
62
top = vertB->y;
63
bottom = vertA->y + 1;
64
}
65
else {
66
top = vertA->y;
67
bottom = vertB->y + 1;
68
}
69
if (top > SCREEN_YSIZE - 1 || bottom < 0)
70
return;
71
if (bottom > SCREEN_YSIZE)
72
bottom = SCREEN_YSIZE;
73
74
int32 fullX = vertA->x << 16;
75
int32 fullU = vertA->u << 16;
76
int32 fullV = vertA->v << 16;
77
int32 deltaX = ((vertB->x - vertA->x) << 16) / (vertB->y - vertA->y);
78
79
int32 deltaU = 0;
80
if (vertA->u != vertB->u)
81
deltaU = ((vertB->u - vertA->u) << 16) / (vertB->y - vertA->y);
82
83
int32 deltaV = 0;
84
if (vertA->v != vertB->v) {
85
deltaV = ((vertB->v - vertA->v) << 16) / (vertB->y - vertA->y);
86
}
87
88
if (top < 0) {
89
fullX -= top * deltaX;
90
fullU -= top * deltaU;
91
fullV -= top * deltaV;
92
top = 0;
93
}
94
for (int32 i = top; i < bottom; ++i) {
95
int32 trueX = fullX >> 16;
96
if (trueX < faceLineStart[i]) {
97
faceLineStart[i] = trueX;
98
faceLineStartU[i] = fullU;
99
faceLineStartV[i] = fullV;
100
}
101
if (trueX > faceLineEnd[i]) {
102
faceLineEnd[i] = trueX;
103
faceLineEndU[i] = fullU;
104
faceLineEndV[i] = fullV;
105
}
106
fullX += deltaX;
107
fullU += deltaU;
108
fullV += deltaV;
109
}
110
}
111