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

#include "im2d.h"

float PolyLineData[16][4] = {
	{ 0.000f,  1.000f,  0.500f,  1.000f},
	{ 0.672f,  0.672f,  0.836f,  0.836f},
	{ 0.900f,  0.000f,  0.950f,  0.500f},
	{ 0.601f, -0.601f,  0.800f,  0.200f},
	{ 0.000f, -0.800f,  0.500f,  0.100f},
	{-0.530f, -0.530f,  0.245f,  0.245f},
	{-0.700f,  0.000f,  0.150f,  0.500f},
	{-0.460f,  0.460f,  0.270f,  0.770f},
	{ 0.000f,  0.600f,  0.500f,  0.800f},
	{ 0.389f,  0.389f,  0.695f,  0.695f},
	{ 0.500f,  0.000f,  0.750f,  0.500f},
	{ 0.318f, -0.318f,  0.659f,  0.341f},
	{ 0.000f, -0.400f,  0.500f,  0.300f},
	{-0.247f, -0.247f,  0.376f,  0.376f},
	{-0.300f,  0.000f,  0.350f,  0.500f},
	{-0.177f,  0.177f,  0.411f,  0.589f}
};

float IndexedPolyLineData[21][4] = {
	{ 0.000f,  1.000f,  0.500f,  1.000f},

	{-0.200f,  0.600f,  0.400f,  0.800f},
	{ 0.200f,  0.600f,  0.600f,  0.800f},
    
	{-0.400f,  0.200f,  0.300f,  0.600f},
	{ 0.000f,  0.200f,  0.500f,  0.600f},
	{ 0.400f,  0.200f,  0.700f,  0.600f},

	{-0.600f, -0.200f,  0.200f,  0.400f},
	{-0.200f, -0.200f,  0.400f,  0.400f},
	{ 0.200f, -0.200f,  0.600f,  0.400f},
	{ 0.600f, -0.200f,  0.800f,  0.400f},

	{-0.800f, -0.600f,  0.100f,  0.200f},
	{-0.400f, -0.600f,  0.300f,  0.200f},
	{ 0.000f, -0.600f,  0.500f,  0.200f},
	{ 0.400f, -0.600f,  0.700f,  0.200f},
	{ 0.800f, -0.600f,  0.900f,  0.200f},

	{-1.000f, -1.000f,  0.000f,  0.000f},
	{-0.600f, -1.000f,  0.200f,  0.000f},
	{-0.200f, -1.000f,  0.400f,  0.000f},
	{ 0.200f, -1.000f,  0.600f,  0.000f},
	{ 0.600f, -1.000f,  0.800f,  0.000f},
	{ 1.000f, -1.000f,  1.000f,  0.000f}
};

rw::uint16 IndexedPolyLineIndices[46] = {
	 0,  2,  5,  4,  8,  5,  9,  8, 13,  9,
	14, 13, 19, 14, 20, 19, 18, 13, 12,  8,
	 7, 12, 18, 17, 12, 11, 17, 16, 15, 10,
	16, 11, 10,  6, 11,  7,  6,  3,  7,  4,
	 3, 1, 4, 2, 1, 0
};

rw::RWDEVICE::Im2DVertex PolyLine[16];
rw::RWDEVICE::Im2DVertex IndexedPolyLine[21];


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

void
PolyLineSetColor(bool white)
{
	rw::RGBA SolidColor1 = SolidBlue;

	if(white)
		SolidColor1 = SolidWhite;

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

void
PolyLineRender(void)
{
	rw::im2d::RenderPrimitive(rw::PRIMTYPEPOLYLINE, PolyLine, 16);
}


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

void
IndexedPolyLineSetColor(bool white)
{
	rw::RGBA SolidColor1 = SolidBlue;

	if(white)
		SolidColor1 = SolidWhite;

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

void
IndexedPolyLineRender(void)
{
	rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPEPOLYLINE,
		IndexedPolyLine, 21, IndexedPolyLineIndices, 46);
}