summaryrefslogtreecommitdiff
path: root/tools/im2d/tristrip.cpp
blob: 41f2d3a1fa2b52c7451332bd02d9cec9fed557f0 (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
#include <rw.h>
#include <skeleton.h>

#include "im2d.h"

float TriStripData[18][4] = {
	{ 0.000f,  1.000f,  0.500f,  1.000f},
	{ 0.000f,  0.500f,  0.500f,  0.750f},

	{ 0.707f,  0.707f,  0.853f,  0.853f},
	{ 0.354f,  0.354f,  0.677f,  0.677f},

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

	{ 0.707f, -0.707f,  0.853f,  0.147f},
	{ 0.354f, -0.354f,  0.677f,  0.323f},

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

	{-0.707f, -0.707f,  0.147f,  0.147f},
	{-0.354f, -0.354f,  0.323f,  0.323f},

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

	{-0.707f,  0.707f,  0.147f,  0.853f},
	{-0.354f,  0.354f,  0.323f,  0.677f},

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

float IndexedTriStripData[16][4] = {
	{ 0.000f,  1.000f,  0.500f,  1.000f},
	{ 0.707f,  0.707f,  0.853f,  0.853f},
	{ 1.000f,  0.000f,  1.000f,  0.500f},
	{ 0.707f, -0.707f,  0.853f,  0.147f},
	{ 0.000f, -1.000f,  0.500f,  0.000f},
	{-0.707f, -0.707f,  0.147f,  0.147f},
	{-1.000f,  0.000f,  0.000f,  0.500f},
	{-0.707f,  0.707f,  0.147f,  0.853f},

	{ 0.000f,  0.500f,  0.500f,  0.750f},
	{ 0.354f,  0.354f,  0.677f,  0.677f},
	{ 0.500f,  0.000f,  0.750f,  0.500f},
	{ 0.354f, -0.354f,  0.677f,  0.323f},
	{ 0.000f, -0.500f,  0.500f,  0.250f},
	{-0.354f, -0.354f,  0.323f,  0.323f},
	{-0.500f,  0.000f,  0.250f,  0.500f},
	{-0.354f,  0.354f,  0.323f,  0.677f}
};

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

rw::RWDEVICE::Im2DVertex TriStrip[18];
rw::RWDEVICE::Im2DVertex IndexedTriStrip[16];


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

void
TriStripSetColor(bool white)
{
	rw::RGBA SolidColor1 = SolidPurple;

	if(white)
		SolidColor1 = SolidWhite;

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

void
TriStripRender(void)
{
	rw::im2d::RenderPrimitive(rw::PRIMTYPETRISTRIP, TriStrip, 18);
}


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

void
IndexedTriStripSetColor(bool white)
{
	rw::RGBA SolidColor1 = SolidCyan;

	if(white)
		SolidColor1 = SolidWhite;

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

void
IndexedTriStripRender(void)
{
	rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRISTRIP,
		IndexedTriStrip, 16, IndexedTriStripIndices, 18);
}