added im2d example

This commit is contained in:
aap 2021-03-09 23:52:11 +01:00
parent 70d222deeb
commit 136101bf10
10 changed files with 1169 additions and 0 deletions

View File

@ -225,6 +225,14 @@ project "camera"
removeplatforms { "*null" } removeplatforms { "*null" }
removeplatforms { "ps2" } removeplatforms { "ps2" }
project "im2d"
kind "WindowedApp"
characterset ("MBCS")
skeltool("im2d")
flags { "WinMain" }
removeplatforms { "*null" }
removeplatforms { "ps2" }
project "ska2anm" project "ska2anm"
kind "ConsoleApp" kind "ConsoleApp"
characterset ("MBCS") characterset ("MBCS")

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

134
tools/im2d/im2d.cpp Normal file
View File

@ -0,0 +1,134 @@
#include <rw.h>
#include <skeleton.h>
#include "im2d.h"
bool Im2DColored = true;
bool Im2DTextured;
rw::int32 Im2DPrimType;
rw::V2d ScreenSize;
float Scale;
rw::RGBA SolidWhite = {255, 255, 255, 255};
rw::RGBA SolidBlack = {0, 0, 0, 255};
rw::RGBA SolidRed = {200, 64, 64, 255};
rw::RGBA SolidGreen = {64, 200, 64, 255};
rw::RGBA SolidBlue = {64, 64, 200, 255};
rw::RGBA SolidYellow = {200, 200, 64, 255};
rw::RGBA SolidPurple = {200, 64, 200, 255};
rw::RGBA SolidCyan = {64, 200, 200, 255};
rw::Texture *Im2DTexture;
void
Im2DInitialize(rw::Camera *camera)
{
ScreenSize.x = camera->frameBuffer->width;
ScreenSize.y = camera->frameBuffer->height;
Scale = ScreenSize.y / 3.0f;
rw::Image::setSearchPath("files/");
Im2DTexture = rw::Texture::read("whiteash", nil);
LineListCreate(camera);
LineListSetColor(!Im2DColored);
IndexedLineListCreate(camera);
IndexedLineListSetColor(!Im2DColored);
PolyLineCreate(camera);
PolyLineSetColor(!Im2DColored);
IndexedPolyLineCreate(camera);
IndexedPolyLineSetColor(!Im2DColored);
TriListCreate(camera);
TriListSetColor(!Im2DColored);
IndexedTriListCreate(camera);
IndexedTriListSetColor(!Im2DColored);
TriStripCreate(camera);
TriStripSetColor(!Im2DColored);
IndexedTriStripCreate(camera);
IndexedTriStripSetColor(!Im2DColored);
TriFanCreate(camera);
TriFanSetColor(!Im2DColored);
IndexedTriFanCreate(camera);
IndexedTriFanSetColor(!Im2DColored);
}
void
Im2DTerminate(void)
{
if(Im2DTexture){
Im2DTexture->destroy();
Im2DTexture = nil;
}
}
void
Im2DRender(void)
{
rw::SetRenderState(rw::ZTESTENABLE, 0);
rw::SetRenderState(rw::ZWRITEENABLE, 0);
rw::SetRenderState(rw::SRCBLEND, rw::BLENDSRCALPHA);
rw::SetRenderState(rw::DESTBLEND, rw::BLENDINVSRCALPHA);
rw::SetRenderState(rw::TEXTUREFILTER, rw::Texture::FilterMode::LINEAR);
if(Im2DTextured)
rw::SetRenderStatePtr(rw::TEXTURERASTER, Im2DTexture->raster);
else
rw::SetRenderStatePtr(rw::TEXTURERASTER, nil);
switch(Im2DPrimType){
case 0: LineListRender(); break;
case 1: IndexedLineListRender(); break;
case 2: PolyLineRender(); break;
case 3: IndexedPolyLineRender(); break;
case 4: TriListRender(); break;
case 5: IndexedTriListRender(); break;
case 6: TriStripRender(); break;
case 7: IndexedTriStripRender(); break;
case 8: TriFanRender(); break;
case 9: IndexedTriFanRender(); break;
}
}
void
Im2DSize(rw::Camera *camera, rw::int32 w, rw::int32 h)
{
ScreenSize.x = w;
ScreenSize.y = h;
if(ScreenSize.x > ScreenSize.y)
Scale = ScreenSize.y / 3.0f;
else
Scale = ScreenSize.x / 3.0f;
LineListCreate(camera);
IndexedLineListCreate(camera);
PolyLineCreate(camera);
IndexedPolyLineCreate(camera);
TriListCreate(camera);
IndexedTriListCreate(camera);
TriStripCreate(camera);
IndexedTriStripCreate(camera);
TriFanCreate(camera);
IndexedTriFanCreate(camera);
}

62
tools/im2d/im2d.h Normal file
View File

@ -0,0 +1,62 @@
extern bool Im2DColored;
extern bool Im2DTextured;
extern rw::int32 Im2DPrimType;
extern rw::V2d ScreenSize;
extern float Scale;
extern rw::RGBA SolidWhite;
extern rw::RGBA SolidBlack;
extern rw::RGBA SolidRed;
extern rw::RGBA SolidGreen;
extern rw::RGBA SolidBlue;
extern rw::RGBA SolidYellow;
extern rw::RGBA SolidPurple;
extern rw::RGBA SolidCyan;
void Im2DInitialize(rw::Camera *camera);
void Im2DTerminate(void);
void Im2DRender(void);
void Im2DSize(rw::Camera *camera, rw::int32 w, rw::int32 h);
void LineListCreate(rw::Camera *camera);
void LineListSetColor(bool white);
void LineListRender(void);
void IndexedLineListCreate(rw::Camera *camera);
void IndexedLineListSetColor(bool white);
void IndexedLineListRender(void);
void PolyLineCreate(rw::Camera *camera);
void PolyLineSetColor(bool white);
void PolyLineRender(void);
void IndexedPolyLineCreate(rw::Camera *camera);
void IndexedPolyLineSetColor(bool white);
void IndexedPolyLineRender(void);
void TriListCreate(rw::Camera *camera);
void TriListSetColor(bool white);
void TriListRender(void);
void IndexedTriListCreate(rw::Camera *camera);
void IndexedTriListSetColor(bool white);
void IndexedTriListRender(void);
void TriStripCreate(rw::Camera *camera);
void TriStripSetColor(bool white);
void TriStripRender(void);
void IndexedTriStripCreate(rw::Camera *camera);
void IndexedTriStripSetColor(bool white);
void IndexedTriStripRender(void);
void TriFanCreate(rw::Camera *camera);
void TriFanSetColor(bool white);
void TriFanRender(void);
void IndexedTriFanCreate(rw::Camera *camera);
void IndexedTriFanSetColor(bool white);
void IndexedTriFanRender(void);

159
tools/im2d/linelist.cpp Normal file
View File

@ -0,0 +1,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);
}

259
tools/im2d/main.cpp Normal file
View File

@ -0,0 +1,259 @@
#include <rw.h>
#include <skeleton.h>
#include <assert.h>
#include "im2d.h"
rw::V3d zero = { 0.0f, 0.0f, 0.0f };
rw::EngineOpenParams engineOpenParams;
float FOV = 70.0f;
rw::RGBA ForegroundColor = { 200, 200, 200, 255 };
rw::RGBA BackgroundColor = { 64, 64, 64, 0 };
rw::Camera *Camera;
rw::Charset *Charset;
float TimeDelta;
rw::Camera*
CreateCamera(void)
{
Camera = sk::CameraCreate(sk::globals.width, sk::globals.height, 1);
assert(Camera);
Camera->setNearPlane(0.1f);
Camera->setFarPlane(10.0f);
return Camera;
}
void
Initialize(void)
{
sk::globals.windowtitle = "Im2D example";
sk::globals.width = 1280;
sk::globals.height = 800;
sk::globals.quit = 0;
}
bool
Initialize3D(void)
{
if(!sk::InitRW())
return false;
Charset = rw::Charset::create(&ForegroundColor, &BackgroundColor);
Camera = CreateCamera();
//UpdateSubRasters(Camera, sk::globals.width, sk::globals.height);
Im2DInitialize(Camera);
// rw::SetRenderState(rw::CULLMODE, rw::CULLBACK);
// rw::SetRenderState(rw::ZTESTENABLE, 1);
// rw::SetRenderState(rw::ZWRITEENABLE, 1);
ImGui_ImplRW_Init();
ImGui::StyleColorsClassic();
return true;
}
void
Terminate3D(void)
{
Im2DTerminate();
if(Camera){
Camera->destroy();
Camera = nil;
}
if(Charset){
Charset->destroy();
Charset = nil;
}
sk::TerminateRW();
}
bool
attachPlugins(void)
{
rw::ps2::registerPDSPlugin(40);
rw::ps2::registerPluginPDSPipes();
rw::registerMeshPlugin();
rw::registerNativeDataPlugin();
rw::registerAtomicRightsPlugin();
rw::registerMaterialRightsPlugin();
rw::xbox::registerVertexFormatPlugin();
rw::registerSkinPlugin();
rw::registerUserDataPlugin();
rw::registerHAnimPlugin();
rw::registerMatFXPlugin();
rw::registerUVAnimPlugin();
rw::ps2::registerADCPlugin();
return true;
}
void
DisplayOnScreenInfo(void)
{
}
void
Gui(void)
{
static bool showWindow = true;
ImGui::Begin("Im2D", &showWindow);
ImGui::RadioButton("Line-list", &Im2DPrimType, 0);
ImGui::RadioButton("Line-list indexed", &Im2DPrimType, 1);
ImGui::RadioButton("Poly-line", &Im2DPrimType, 2);
ImGui::RadioButton("Poly-line indexed", &Im2DPrimType, 3);
ImGui::RadioButton("Tri-list", &Im2DPrimType, 4);
ImGui::RadioButton("Tri-list indexed", &Im2DPrimType, 5);
ImGui::RadioButton("Tri-strip", &Im2DPrimType, 6);
ImGui::RadioButton("Tri-strip indexed", &Im2DPrimType, 7);
ImGui::RadioButton("Tri-fan", &Im2DPrimType, 8);
ImGui::RadioButton("Tri-fan indexed", &Im2DPrimType, 9);
ImGui::NewLine();
ImGui::Checkbox("Textured", &Im2DTextured);
if(ImGui::Checkbox("Colored", &Im2DColored)){
LineListSetColor(!Im2DColored);
IndexedLineListSetColor(!Im2DColored);
PolyLineSetColor(!Im2DColored);
IndexedPolyLineSetColor(!Im2DColored);
TriListSetColor(!Im2DColored);
IndexedTriListSetColor(!Im2DColored);
TriStripSetColor(!Im2DColored);
IndexedTriStripSetColor(!Im2DColored);
TriFanSetColor(!Im2DColored);
IndexedTriFanSetColor(!Im2DColored);
}
ImGui::End();
}
void
Render(void)
{
Camera->clear(&BackgroundColor, rw::Camera::CLEARIMAGE|rw::Camera::CLEARZ);
Camera->beginUpdate();
ImGui_ImplRW_NewFrame(TimeDelta);
Im2DRender();
DisplayOnScreenInfo();
Gui();
ImGui::EndFrame();
ImGui::Render();
Camera->endUpdate();
Camera->showRaster(0);
}
void
Idle(float timeDelta)
{
TimeDelta = timeDelta;
Render();
}
int MouseX, MouseY;
int MouseDeltaX, MouseDeltaY;
int MouseButtons;
void
KeyUp(int key)
{
}
void
KeyDown(int key)
{
switch(key){
case sk::KEY_ESC:
sk::globals.quit = 1;
break;
}
}
void
MouseBtn(sk::MouseState *mouse)
{
MouseButtons = mouse->buttons;
}
void
MouseMove(sk::MouseState *mouse)
{
MouseDeltaX = mouse->posx - MouseX;
MouseDeltaY = mouse->posy - MouseY;
MouseX = mouse->posx;
MouseY = mouse->posy;
}
sk::EventStatus
AppEventHandler(sk::Event e, void *param)
{
using namespace sk;
Rect *r;
MouseState *ms;
ImGuiEventHandler(e, param);
ImGuiIO &io = ImGui::GetIO();
switch(e){
case INITIALIZE:
Initialize();
return EVENTPROCESSED;
case RWINITIALIZE:
return Initialize3D() ? EVENTPROCESSED : EVENTERROR;
case RWTERMINATE:
Terminate3D();
return EVENTPROCESSED;
case PLUGINATTACH:
return attachPlugins() ? EVENTPROCESSED : EVENTERROR;
case KEYDOWN:
KeyDown(*(int*)param);
return EVENTPROCESSED;
case KEYUP:
KeyUp(*(int*)param);
return EVENTPROCESSED;
case MOUSEBTN:
if(!io.WantCaptureMouse){
ms = (MouseState*)param;
MouseBtn(ms);
}else
MouseButtons = 0;
return EVENTPROCESSED;
case MOUSEMOVE:
MouseMove((MouseState*)param);
return EVENTPROCESSED;
case RESIZE:
r = (Rect*)param;
// TODO: register when we're minimized
if(r->w == 0) r->w = 1;
if(r->h == 0) r->h = 1;
sk::globals.width = r->w;
sk::globals.height = r->h;
if(::Camera){
sk::CameraSize(::Camera, r, 0.5f, 4.0f/3.0f);
Im2DSize(::Camera, r->w, r->h);
}
break;
case IDLE:
Idle(*(float*)param);
return EVENTPROCESSED;
}
return sk::EVENTNOTPROCESSED;
}

132
tools/im2d/polyline.cpp Normal file
View File

@ -0,0 +1,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);
}

119
tools/im2d/trifan.cpp Normal file
View File

@ -0,0 +1,119 @@
#include <rw.h>
#include <skeleton.h>
#include "im2d.h"
float TriFanData[17][4] = {
{ 0.000f, 1.000f, 0.500f, 1.000f},
{-0.383f, 0.924f, 0.308f, 0.962f},
{-0.707f, 0.707f, 0.146f, 0.854f},
{-0.924f, 0.383f, 0.038f, 0.692f},
{-1.000f, 0.000f, 0.000f, 0.500f},
{-0.924f, -0.383f, 0.038f, 0.308f},
{-0.707f, -0.707f, 0.146f, 0.146f},
{-0.383f, -0.924f, 0.308f, 0.038f},
{ 0.000f, -1.000f, 0.500f, 0.000f},
{ 0.383f, -0.924f, 0.692f, 0.038f},
{ 0.707f, -0.707f, 0.854f, 0.146f},
{ 0.924f, -0.383f, 0.962f, 0.308f},
{ 1.000f, 0.000f, 1.000f, 0.500f},
{ 0.924f, 0.383f, 0.962f, 0.692f},
{ 0.707f, 0.707f, 0.854f, 0.854f},
{ 0.383f, 0.924f, 0.692f, 0.962f},
{ 0.000f, 1.000f, 0.500f, 1.000f}
};
float IndexedTriFanData[16][4] = {
{ 0.000f, 1.000f, 0.500f, 1.000f},
{-0.383f, 0.924f, 0.308f, 0.962f},
{-0.707f, 0.707f, 0.146f, 0.854f},
{-0.924f, 0.383f, 0.038f, 0.692f},
{-1.000f, 0.000f, 0.000f, 0.500f},
{-0.924f, -0.383f, 0.038f, 0.308f},
{-0.707f, -0.707f, 0.146f, 0.146f},
{-0.383f, -0.924f, 0.308f, 0.038f},
{ 0.000f, -1.000f, 0.500f, 0.000f},
{ 0.383f, -0.924f, 0.692f, 0.038f},
{ 0.707f, -0.707f, 0.854f, 0.146f},
{ 0.924f, -0.383f, 0.962f, 0.308f},
{ 1.000f, 0.000f, 1.000f, 0.500f},
{ 0.924f, 0.383f, 0.962f, 0.692f},
{ 0.707f, 0.707f, 0.854f, 0.854f},
{ 0.383f, 0.924f, 0.692f, 0.962f}
};
rw::uint16 IndexedTriFanIndices[17] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0
};
rw::RWDEVICE::Im2DVertex TriFan[17];
rw::RWDEVICE::Im2DVertex IndexedTriFan[16];
void
TriFanCreate(rw::Camera *camera)
{
float recipZ = 1.0f/camera->nearPlane;
for(int i = 0; i < 17; i++){
TriFan[i].setScreenX(ScreenSize.x/2.0f + TriFanData[i][0]*Scale);
TriFan[i].setScreenY(ScreenSize.y/2.0f - TriFanData[i][1]*Scale);
TriFan[i].setScreenZ(rw::im2d::GetNearZ());
TriFan[i].setRecipCameraZ(recipZ);
TriFan[i].setU(TriFanData[i][2], recipZ);
TriFan[i].setV(TriFanData[i][3], recipZ);
}
}
void
TriFanSetColor(bool white)
{
rw::RGBA SolidColor1 = SolidYellow;
if(white)
SolidColor1 = SolidWhite;
for(int i = 0; i < 17; i++)
TriFan[i].setColor(SolidColor1.red, SolidColor1.green,
SolidColor1.blue, SolidColor1.alpha);
}
void
TriFanRender(void)
{
rw::im2d::RenderPrimitive(rw::PRIMTYPETRIFAN, TriFan, 17);
}
void
IndexedTriFanCreate(rw::Camera *camera)
{
float recipZ = 1.0f/camera->nearPlane;
for(int i = 0; i < 16; i++){
IndexedTriFan[i].setScreenX(ScreenSize.x/2.0f + IndexedTriFanData[i][0]*Scale);
IndexedTriFan[i].setScreenY(ScreenSize.y/2.0f - IndexedTriFanData[i][1]*Scale);
IndexedTriFan[i].setScreenZ(rw::im2d::GetNearZ());
IndexedTriFan[i].setRecipCameraZ(recipZ);
IndexedTriFan[i].setU(IndexedTriFanData[i][2], recipZ);
IndexedTriFan[i].setV(IndexedTriFanData[i][3], recipZ);
}
}
void
IndexedTriFanSetColor(bool white)
{
rw::RGBA SolidColor1 = SolidGreen;
if(white)
SolidColor1 = SolidWhite;
for(int i = 0; i < 16; i++)
IndexedTriFan[i].setColor(SolidColor1.red, SolidColor1.green,
SolidColor1.blue, SolidColor1.alpha);
}
void
IndexedTriFanRender(void)
{
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRIFAN,
IndexedTriFan, 16, IndexedTriFanIndices, 17);
}

166
tools/im2d/trilist.cpp Normal file
View File

@ -0,0 +1,166 @@
#include <rw.h>
#include <skeleton.h>
#include "im2d.h"
float TriListData[18][4] = {
{ 0.000f, 1.000f, 0.500f, 1.000f},
{-0.500f, 0.500f, 0.250f, 0.750f},
{ 0.500f, 0.500f, 0.750f, 0.750f},
{-0.500f, 0.500f, 0.250f, 0.750f},
{ 0.500f, -0.500f, 0.750f, 0.250f},
{ 0.500f, 0.500f, 0.750f, 0.750f},
{ 0.500f, 0.500f, 0.750f, 0.750f},
{ 0.500f, -0.500f, 0.750f, 0.250f},
{ 1.000f, 0.000f, 1.000f, 0.500f},
{ 0.500f, -0.500f, 0.750f, 0.250f},
{-0.500f, -0.500f, 0.250f, 0.250f},
{ 0.000f, -1.000f, 0.500f, 0.000f},
{ 0.500f, -0.500f, 0.750f, 1.250f},
{-0.500f, 0.500f, 0.250f, 1.750f},
{-0.500f, -0.500f, 0.250f, 1.250f},
{-0.500f, -0.500f, 0.250f, 0.250f},
{-0.500f, 0.500f, 0.250f, 0.750f},
{-1.000f, 0.000f, 0.000f, 0.500f}
};
float IndexedTriListData[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.300f, 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 IndexedTriListIndices[45] = {
0, 1, 2,
1, 3, 4, 2, 4, 5,
3, 6, 7, 4, 7, 8, 5, 8, 9,
6, 10, 11, 7, 11, 12, 8, 12, 13, 9, 13, 14,
10, 15, 16, 11, 16, 17, 12, 17, 18, 13, 18, 19, 14, 19, 20
};
rw::RWDEVICE::Im2DVertex TriList[18];
rw::RWDEVICE::Im2DVertex IndexedTriList[21];
void
TriListCreate(rw::Camera *camera)
{
float recipZ = 1.0f/camera->nearPlane;
for(int i = 0; i < 18; i++){
TriList[i].setScreenX(ScreenSize.x/2.0f + TriListData[i][0]*Scale);
TriList[i].setScreenY(ScreenSize.y/2.0f - TriListData[i][1]*Scale);
TriList[i].setScreenZ(rw::im2d::GetNearZ());
TriList[i].setRecipCameraZ(recipZ);
TriList[i].setU(TriListData[i][2], recipZ);
TriList[i].setV(TriListData[i][3], recipZ);
}
}
void
TriListSetColor(bool white)
{
int i;
rw::RGBA SolidColor1 = SolidBlue;
rw::RGBA SolidColor2 = SolidRed;
rw::RGBA SolidColor3 = SolidGreen;
rw::RGBA SolidColor4 = SolidYellow;
rw::RGBA SolidColor5 = SolidPurple;
rw::RGBA SolidColor6 = SolidCyan;
if(white){
SolidColor1 = SolidWhite;
SolidColor2 = SolidWhite;
SolidColor3 = SolidWhite;
SolidColor4 = SolidWhite;
SolidColor5 = SolidWhite;
SolidColor6 = SolidWhite;
}
for(i = 0; i < 3; i++)
TriList[i].setColor(SolidColor1.red, SolidColor1.green,
SolidColor1.blue, SolidColor1.alpha);
for(; i < 6; i++)
TriList[i].setColor(SolidColor2.red, SolidColor2.green,
SolidColor2.blue, SolidColor2.alpha);
for(; i < 9; i++)
TriList[i].setColor(SolidColor3.red, SolidColor3.green,
SolidColor3.blue, SolidColor3.alpha);
for(; i < 12; i++)
TriList[i].setColor(SolidColor4.red, SolidColor4.green,
SolidColor4.blue, SolidColor4.alpha);
for(; i < 15; i++)
TriList[i].setColor(SolidColor5.red, SolidColor5.green,
SolidColor5.blue, SolidColor5.alpha);
for(; i < 18; i++)
TriList[i].setColor(SolidColor6.red, SolidColor6.green,
SolidColor6.blue, SolidColor6.alpha);
}
void
TriListRender(void)
{
rw::im2d::RenderPrimitive(rw::PRIMTYPETRILIST, TriList, 18);
}
void
IndexedTriListCreate(rw::Camera *camera)
{
float recipZ = 1.0f/camera->nearPlane;
for(int i = 0; i < 21; i++){
IndexedTriList[i].setScreenX(ScreenSize.x/2.0f + IndexedTriListData[i][0]*Scale);
IndexedTriList[i].setScreenY(ScreenSize.y/2.0f - IndexedTriListData[i][1]*Scale);
IndexedTriList[i].setScreenZ(rw::im2d::GetNearZ());
IndexedTriList[i].setRecipCameraZ(recipZ);
IndexedTriList[i].setU(IndexedTriListData[i][2], recipZ);
IndexedTriList[i].setV(IndexedTriListData[i][3], recipZ);
}
}
void
IndexedTriListSetColor(bool white)
{
rw::RGBA SolidColor1 = SolidBlue;
if(white)
SolidColor1 = SolidWhite;
for(int i = 0; i < 21; i++)
IndexedTriList[i].setColor(SolidColor1.red, SolidColor1.green,
SolidColor1.blue, SolidColor1.alpha);
}
void
IndexedTriListRender(void)
{
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
IndexedTriList, 21, IndexedTriListIndices, 45);
}

130
tools/im2d/tristrip.cpp Normal file
View File

@ -0,0 +1,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);
}