summaryrefslogtreecommitdiff
path: root/tools/im2d/linelist.cpp
blob: 6d76fb25b8eeb902e1ca1feeb311c12d9904b015 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <rw.h>
#include <skeleton.h>

#include "im2d.h"

float LineListData[32][4] = {
	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.000f,  1.000f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.383f,  0.924f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.707f,  0.707f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.924f,  0.383f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 1.000f,  0.000f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.924f, -0.383f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.707f, -0.707f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.383f, -0.924f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{ 0.000f, -1.000f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-0.383f, -0.924f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-0.707f, -0.707f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-0.924f, -0.383f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-1.000f,  0.000f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-0.924f,  0.383f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-0.707f,  0.707f,  1.000f,  1.000f},

	{ 0.000f,  0.000f,  0.000f,  0.000f},
	{-0.383f,  0.924f,  1.000f,  1.000f}
};

float IndexedLineListData[16][4] = {
	{-1.000f,  1.000f,  0.000f,  1.000f},
	{-0.500f,  1.000f,  0.250f,  1.000f},
	{ 0.000f,  1.000f,  0.500f,  1.000f},
	{ 0.500f,  1.000f,  0.750f,  1.000f},
	{ 1.000f,  1.000f,  1.000f,  1.000f},

	{-1.000f,  0.500f,  0.000f,  0.750f},
	{-1.000f,  0.000f,  0.000f,  0.500f},
	{-1.000f, -0.500f,  0.000f,  0.250f},

	{ 1.000f,  0.500f,  1.000f,  0.750f},
	{ 1.000f,  0.000f,  1.000f,  0.500f},
	{ 1.000f, -0.500f,  1.000f,  0.250f},

	{-1.000f, -1.000f,  0.000f,  0.000f},
	{-0.500f, -1.000f,  0.250f,  0.000f},
	{ 0.000f, -1.000f,  0.500f,  0.000f},
	{ 0.500f, -1.000f,  0.750f,  0.000f},
	{ 1.000f, -1.000f,  1.000f,  0.000f}
};

rw::uint16 IndexedLineListIndices[20] = {
	0, 11, 1, 12, 2, 13, 3, 14, 4, 15, 
	0, 4, 5, 8, 6, 9, 7, 10, 11, 15
};

rw::RWDEVICE::Im2DVertex LineList[32];
rw::RWDEVICE::Im2DVertex IndexedLineList[16];


void
LineListCreate(rw::Camera *camera)
{
	float recipZ = 1.0f/camera->nearPlane;
	for(int i = 0; i < 32; i++){
		LineList[i].setScreenX(ScreenSize.x/2.0f + LineListData[i][0]*Scale);
		LineList[i].setScreenY(ScreenSize.y/2.0f - LineListData[i][1]*Scale);
		LineList[i].setScreenZ(rw::im2d::GetNearZ());
		LineList[i].setRecipCameraZ(recipZ);
		LineList[i].setU(LineListData[i][2], recipZ);
		LineList[i].setV(LineListData[i][3], recipZ);
	}
}

void
LineListSetColor(bool white)
{
	rw::RGBA SolidColor1 = SolidRed;
	rw::RGBA SolidColor2 = SolidWhite;

	if(white){
		SolidColor1 = SolidWhite;
		SolidColor2 = SolidWhite;
	}

	for(int i = 0; i < 32; i += 2){
		LineList[i].setColor(SolidColor1.red, SolidColor1.green,
			SolidColor1.blue, SolidColor1.alpha);
		LineList[i+1].setColor(SolidColor2.red, SolidColor2.green,
			SolidColor2.blue, SolidColor2.alpha);
	}
}

void
LineListRender(void)
{
	rw::im2d::RenderPrimitive(rw::PRIMTYPELINELIST, LineList, 32);
}


void
IndexedLineListCreate(rw::Camera *camera)
{
	float recipZ = 1.0f/camera->nearPlane;
	for(int i = 0; i < 16; i++){
		IndexedLineList[i].setScreenX(ScreenSize.x/2.0f + IndexedLineListData[i][0]*Scale);
		IndexedLineList[i].setScreenY(ScreenSize.y/2.0f - IndexedLineListData[i][1]*Scale);
		IndexedLineList[i].setScreenZ(rw::im2d::GetNearZ());
		IndexedLineList[i].setRecipCameraZ(recipZ);
		IndexedLineList[i].setU(IndexedLineListData[i][2], recipZ);
		IndexedLineList[i].setV(IndexedLineListData[i][3], recipZ);
	}
}

void
IndexedLineListSetColor(bool white)
{
	rw::RGBA SolidColor1 = SolidRed;

	if(white)
		SolidColor1 = SolidWhite;

	for(int i = 0; i < 16; i++)
		IndexedLineList[i].setColor(SolidColor1.red, SolidColor1.green,
			SolidColor1.blue, SolidColor1.alpha);
}

void
IndexedLineListRender(void)
{
	rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPELINELIST,
		IndexedLineList, 16, IndexedLineListIndices, 20);
}