From 136101bf10846d0151fdcce621b0b8942c64965a Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 9 Mar 2021 23:52:11 +0100 Subject: [PATCH] added im2d example --- premake5.lua | 8 ++ tools/im2d/files/whiteash.png | Bin 0 -> 4313 bytes tools/im2d/im2d.cpp | 134 ++++++++++++++++++ tools/im2d/im2d.h | 62 ++++++++ tools/im2d/linelist.cpp | 159 +++++++++++++++++++++ tools/im2d/main.cpp | 259 ++++++++++++++++++++++++++++++++++ tools/im2d/polyline.cpp | 132 +++++++++++++++++ tools/im2d/trifan.cpp | 119 ++++++++++++++++ tools/im2d/trilist.cpp | 166 ++++++++++++++++++++++ tools/im2d/tristrip.cpp | 130 +++++++++++++++++ 10 files changed, 1169 insertions(+) create mode 100644 tools/im2d/files/whiteash.png create mode 100644 tools/im2d/im2d.cpp create mode 100644 tools/im2d/im2d.h create mode 100644 tools/im2d/linelist.cpp create mode 100644 tools/im2d/main.cpp create mode 100644 tools/im2d/polyline.cpp create mode 100644 tools/im2d/trifan.cpp create mode 100644 tools/im2d/trilist.cpp create mode 100644 tools/im2d/tristrip.cpp diff --git a/premake5.lua b/premake5.lua index e635c1b..fd10479 100755 --- a/premake5.lua +++ b/premake5.lua @@ -225,6 +225,14 @@ project "camera" removeplatforms { "*null" } removeplatforms { "ps2" } +project "im2d" + kind "WindowedApp" + characterset ("MBCS") + skeltool("im2d") + flags { "WinMain" } + removeplatforms { "*null" } + removeplatforms { "ps2" } + project "ska2anm" kind "ConsoleApp" characterset ("MBCS") diff --git a/tools/im2d/files/whiteash.png b/tools/im2d/files/whiteash.png new file mode 100644 index 0000000000000000000000000000000000000000..aa60569fc77cc36567c7259094ab2fcc07b6517d GIT binary patch literal 4313 zcmds4i91y97gv;Bsg#hSge1m3c2mTd&@{HOBx8x2C0EFVWRe&WW2pwAAu{-4>_bsg zmIh%g*$pCFS<3#q{TsjgocFw+d*Ab(^ZA_Tz0Y&+Q!9(Bf_!3p92^{iW~Nur&}{f` z@NhytqbhP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)q*vcq}h{ZD)P=P6O>N@6k%|_Al zeM+RNv=X#fUiQ#gIor9l{4(~tFM7Mzq9O5c<_<@K)1{8FG0t| zH2#{pv{%`kL1WcN14CVnni{c&*Cp|&l=17GY|5l?uL-J+b#2a+z|I@5bw26%H5l_K qO8Ir}F +#include + +#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); +} diff --git a/tools/im2d/im2d.h b/tools/im2d/im2d.h new file mode 100644 index 0000000..de82e03 --- /dev/null +++ b/tools/im2d/im2d.h @@ -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); diff --git a/tools/im2d/linelist.cpp b/tools/im2d/linelist.cpp new file mode 100644 index 0000000..6d76fb2 --- /dev/null +++ b/tools/im2d/linelist.cpp @@ -0,0 +1,159 @@ +#include +#include + +#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); +} diff --git a/tools/im2d/main.cpp b/tools/im2d/main.cpp new file mode 100644 index 0000000..f36da51 --- /dev/null +++ b/tools/im2d/main.cpp @@ -0,0 +1,259 @@ +#include +#include +#include + +#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; +} diff --git a/tools/im2d/polyline.cpp b/tools/im2d/polyline.cpp new file mode 100644 index 0000000..5379117 --- /dev/null +++ b/tools/im2d/polyline.cpp @@ -0,0 +1,132 @@ +#include +#include + +#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); +} diff --git a/tools/im2d/trifan.cpp b/tools/im2d/trifan.cpp new file mode 100644 index 0000000..b1a703f --- /dev/null +++ b/tools/im2d/trifan.cpp @@ -0,0 +1,119 @@ +#include +#include + +#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); +} diff --git a/tools/im2d/trilist.cpp b/tools/im2d/trilist.cpp new file mode 100644 index 0000000..64ee65f --- /dev/null +++ b/tools/im2d/trilist.cpp @@ -0,0 +1,166 @@ +#include +#include + +#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); +} diff --git a/tools/im2d/tristrip.cpp b/tools/im2d/tristrip.cpp new file mode 100644 index 0000000..41f2d3a --- /dev/null +++ b/tools/im2d/tristrip.cpp @@ -0,0 +1,130 @@ +#include +#include + +#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); +}