From 19913cb665e4040f078a2e80280713fa7a129668 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 20 Apr 2018 18:55:55 -0700 Subject: [PATCH 01/10] Added base class for button listening Fixed a few memory leaks --- ButtonListener.cpp | 14 ++++++++++++++ ButtonListener.h | 18 ++++++++++++++++++ G3DTest.vcproj | 8 ++++++++ TextButtonInstance.cpp | 16 +++++++++++++++- TextButtonInstance.h | 7 +++++-- main.cpp | 11 ++++++++--- 6 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 ButtonListener.cpp create mode 100644 ButtonListener.h diff --git a/ButtonListener.cpp b/ButtonListener.cpp new file mode 100644 index 0000000..4e9ff6c --- /dev/null +++ b/ButtonListener.cpp @@ -0,0 +1,14 @@ +#include "ButtonListener.h" + +ButtonListener::ButtonListener(void) +{ +} + +ButtonListener::~ButtonListener(void) +{ +} + +void ButtonListener::onButton1MouseClick(TextButtonInstance* button) +{ +} + diff --git a/ButtonListener.h b/ButtonListener.h new file mode 100644 index 0000000..c12b8e3 --- /dev/null +++ b/ButtonListener.h @@ -0,0 +1,18 @@ +#pragma once +#include "TextButtonInstance.h" +class TextButtonInstance; +class ButtonListener +{ +public: + ButtonListener(void); + ~ButtonListener(void); + virtual void onButton1MouseClick(TextButtonInstance*); + //virtual void onMouseOver(); //TODO + //virtual void onMouseOut(); //TODO + //virtual void onButton1MouseDown(); //TODO + //virtual void onButton1MouseUp(); //TODO + //virtual void onButton2MouseClick(); //TODO + //virtual void onButton2MouseDown(); //TODO + //virtual void onButton2MouseUp(); //TODO + //What to do now... +}; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 74b0e2c..2dbac1f 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -230,6 +230,10 @@ Name="Source Files" Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > + + @@ -279,6 +283,10 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl" > + + diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index de70aff..e22b991 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -22,6 +22,7 @@ bool floatBottom; bool floatRight; bool floatCenter; bool visible; +ButtonListener* buttonListener; TextButtonInstance::TextButtonInstance(void) { @@ -40,11 +41,24 @@ TextButtonInstance::TextButtonInstance(void) floatCenter = false; visible = true; className = "TextButton"; - } TextButtonInstance::~TextButtonInstance(void) { + delete buttonListener; +} + +void TextButtonInstance::setButtonListener(ButtonListener* listener) +{ + buttonListener = listener; +} + +void TextButtonInstance::onClick() +{ + if(buttonListener != NULL) + { + buttonListener->onButton1MouseClick(this); + } } void TextButtonInstance::drawObj(RenderDevice* rd) diff --git a/TextButtonInstance.h b/TextButtonInstance.h index b574872..8dddb0c 100644 --- a/TextButtonInstance.h +++ b/TextButtonInstance.h @@ -1,6 +1,8 @@ #pragma once #include "instance.h" - +#pragma once +#include "ButtonListener.h" +class ButtonListener; class TextButtonInstance : public Instance { @@ -30,5 +32,6 @@ public: bool visible; int textSize; void drawObj(G3D::RenderDevice*); - + void setButtonListener(ButtonListener*); + void onClick(); }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 8ed0ec0..6ab22c5 100644 --- a/main.cpp +++ b/main.cpp @@ -340,7 +340,9 @@ void Demo::onInit() { void clearInstances() { for(size_t i = 0; i < instances.size(); i++) + { delete instances.at(i); + } delete dataModel; } void OnError(int err, std::string msg = "") @@ -354,10 +356,15 @@ void OnError(int err, std::string msg = "") void Demo::onCleanup() { clearInstances(); + go->~Texture(); + go_ovr->~Texture(); + go_dn->~Texture(); + app->sky->~Sky(); } + void Demo::onLogic() { // Add non-simulation game logic and AI code here } @@ -704,8 +711,6 @@ int main(int argc, char** argv) { settings.window.defaultIconFilename = GetFileInPath("/content/images/rico256c.png"); settings.window.resizable = true; settings.writeLicenseFile = false; - App app = App(settings); - //app.window()->setIcon(ExePath() + "/content/images/rico.png"); - app.run(); + App(settings).run(); return 0; } \ No newline at end of file From 49c117d5d7db382f544b6adfda0916b05923c0da Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 12:32:37 -0700 Subject: [PATCH 02/10] Removed MFC --- G3DTest.vcproj | 12 ------------ Work.cpp | 40 ---------------------------------------- Work.h | 23 ----------------------- main.cpp | 20 +++++++++++++++----- stdafx.h | 4 ---- 5 files changed, 15 insertions(+), 84 deletions(-) delete mode 100644 Work.cpp delete mode 100644 Work.h delete mode 100644 stdafx.h diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 2dbac1f..5b27a90 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -274,10 +274,6 @@ RelativePath=".\TextButtonInstance.cpp" > - - - - - - DestroyWindow(); - OnOK(); -} diff --git a/Work.h b/Work.h deleted file mode 100644 index 173ce9f..0000000 --- a/Work.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "resource.h" - -// Work dialog - -class Work : public CDialog -{ - DECLARE_DYNAMIC(Work) - -public: - Work(CWnd* pParent = NULL); // standard constructor - virtual ~Work(); - -// Dialog Data - enum { IDD = IDD_ABOUT_DIALOG }; - -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - - DECLARE_MESSAGE_MAP() -public: - afx_msg void OnBnClickedOk(); -}; diff --git a/main.cpp b/main.cpp index 6ab22c5..61af646 100644 --- a/main.cpp +++ b/main.cpp @@ -10,13 +10,12 @@ @author Morgan McGuire, matrix@graphics3d.com */ -//Compile for 95 and higher -#define WINVER 0x0400 #include #include "Instance.h" #include "PhysicalInstance.h" #include "TextButtonInstance.h" + #if G3D_VER < 61000 #error Requires G3D 6.10 #endif @@ -26,8 +25,8 @@ static const std::string VERSION = "PRE-ALPHA "; static std::vector instances; static std::vector instances_2D; static Instance* dataModel; -static GFontRef fntdominant = NULL; -static GFontRef fntlighttrek = NULL; +GFontRef fntdominant = NULL; +GFontRef fntlighttrek = NULL; static bool democ = true; static std::string message = ""; static G3D::RealTime messageTime = 0; @@ -250,6 +249,7 @@ void Demo::onInit() { initGUI(); + PhysicalInstance* test = makePart(); test->parent = dataModel; test->color = Color3(0.2F,0.3F,1); @@ -257,6 +257,7 @@ void Demo::onInit() { + test = makePart(); test->parent = dataModel; test->color = Color3(.5F,1,.5F); @@ -321,6 +322,7 @@ void Demo::onInit() { test->color = Color3::gray(); test->size = Vector3(4,1,2); test->position = Vector3(-2,7,0); + @@ -359,6 +361,12 @@ void Demo::onCleanup() { go->~Texture(); go_ovr->~Texture(); go_dn->~Texture(); + go_dn.~ReferenceCountedPointer(); + delete go_dn.pointer(); + go.~ReferenceCountedPointer(); + delete go.pointer(); + go_ovr.~ReferenceCountedPointer(); + delete go_ovr.pointer(); app->sky->~Sky(); } @@ -470,7 +478,7 @@ void Demo::onUserInput(UserInput* ui) { std::string ExePath() { char buffer[MAX_PATH]; - GetModuleFileNameA( NULL, buffer, MAX_PATH ); + GetModuleFileName( NULL, buffer, MAX_PATH ); std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" ); return std::string( buffer ).substr( 0, pos); } @@ -704,6 +712,8 @@ App::~App() { } int main(int argc, char** argv) { + //_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); + //_CrtSetBreakAlloc(1279); GAppSettings settings; if(getOSVersion() > 5.0) settings.window.defaultIconFilename = GetFileInPath("/content/images/rico.png"); diff --git a/stdafx.h b/stdafx.h deleted file mode 100644 index 94c7e16..0000000 --- a/stdafx.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#define _AFXDLL 1 -#include - From f0fffa71d4d99b0c6e50fc79440bd441320562d8 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 15:05:45 -0700 Subject: [PATCH 03/10] Tried something --- main.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/main.cpp b/main.cpp index 61af646..2e0eebf 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ #if G3D_VER < 61000 #error Requires G3D 6.10 #endif +HWND hwnd; static const float VNUM = 0.01F; static std::string title = ""; static const std::string VERSION = "PRE-ALPHA "; @@ -711,9 +712,65 @@ App::~App() { delete applet; } + +LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_CLOSE: + DestroyWindow(hwnd); + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hwnd, msg, wParam, lParam); + } + return 0; +} + int main(int argc, char** argv) { //_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); //_CrtSetBreakAlloc(1279); + + + //Create container window + char className[] = "classContainerHWND"; + WNDCLASSEX wc; + HINSTANCE hInstance = GetModuleHandle(NULL); + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = 0; + wc.lpfnWndProc = WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wc.lpszMenuName = NULL; + wc.lpszClassName = className; + wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); + + if (!RegisterClassEx (&wc)) + { + MessageBox(NULL, "Window registration failed! Please make sure your computer supports Win32 graphical components!", "Error! Cannot start Dynamica!", MB_ICONEXCLAMATION | MB_OK); + return -1; + } + + hwnd = CreateWindowEx( + WS_EX_CLIENTEDGE, + className, + "Container Window", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,NULL, NULL, hInstance, NULL); + if(hwnd == NULL) + { + MessageBox(NULL, "Window Creation Failed! Please make sure your computer supports Win32 graphical components!", "Error! Cannot start Dynamica!", MB_ICONEXCLAMATION | MB_OK); + return -2; + } + ShowWindow(hwnd, SW_SHOW); + UpdateWindow(hwnd); + GAppSettings settings; if(getOSVersion() > 5.0) settings.window.defaultIconFilename = GetFileInPath("/content/images/rico.png"); From 6cea4397f2bc6b2ccc5e4d17b9055c25763df5a4 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 19:51:14 -0700 Subject: [PATCH 04/10] Changed window to SDL, can now access bare HWND component --- main.cpp | 62 +++++++++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/main.cpp b/main.cpp index 2e0eebf..a6116e0 100644 --- a/main.cpp +++ b/main.cpp @@ -45,6 +45,7 @@ static int go_ovr_id = 0; static int go_dn_id = 0; static bool mouseButton1Down = false; static bool running = true; +static bool mouseMovedBeginMotion = false; /** This simple demo applet uses the debug mode as the regular rendering mode so you can fly around the scene. @@ -89,7 +90,7 @@ public: Demo* applet; - App(const GAppSettings& settings); + App(const GAppSettings& settings, GWindow* wnd); ~App(); }; @@ -416,16 +417,24 @@ void Demo::onUserInput(UserInput* ui) { endApplet = true; app->endProgram = true; } + if(mouseMovedBeginMotion) + { + mouseMovedBeginMotion = false; + app->debugController.setActive(true); + } if(ui->keyPressed(SDL_RIGHT_MOUSE_KEY)) { - app->debugController.setActive(true); + ui->window()->setMouseVisible(false); + app->window()->setRelativeMousePosition(app->window()->width()/2, app->window()->height()/2); + mouseMovedBeginMotion = true; + } else if(ui->keyReleased(SDL_RIGHT_MOUSE_KEY)) { + ui->window()->setMouseVisible(true); app->debugController.setActive(false); } - if(ui->keyPressed(SDLK_LSHIFT)) { app->debugController.setMoveRate(20); @@ -703,7 +712,7 @@ void App::main() { -App::App(const GAppSettings& settings) : GApp(settings) { +App::App(const GAppSettings& settings, GWindow* wnd) : GApp(settings, wnd) { applet = new Demo(this); } @@ -733,44 +742,6 @@ int main(int argc, char** argv) { //_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); //_CrtSetBreakAlloc(1279); - - //Create container window - char className[] = "classContainerHWND"; - WNDCLASSEX wc; - HINSTANCE hInstance = GetModuleHandle(NULL); - wc.cbSize = sizeof(WNDCLASSEX); - wc.style = 0; - wc.lpfnWndProc = WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wc.lpszMenuName = NULL; - wc.lpszClassName = className; - wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); - - if (!RegisterClassEx (&wc)) - { - MessageBox(NULL, "Window registration failed! Please make sure your computer supports Win32 graphical components!", "Error! Cannot start Dynamica!", MB_ICONEXCLAMATION | MB_OK); - return -1; - } - - hwnd = CreateWindowEx( - WS_EX_CLIENTEDGE, - className, - "Container Window", - WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,NULL, NULL, hInstance, NULL); - if(hwnd == NULL) - { - MessageBox(NULL, "Window Creation Failed! Please make sure your computer supports Win32 graphical components!", "Error! Cannot start Dynamica!", MB_ICONEXCLAMATION | MB_OK); - return -2; - } - ShowWindow(hwnd, SW_SHOW); - UpdateWindow(hwnd); - GAppSettings settings; if(getOSVersion() > 5.0) settings.window.defaultIconFilename = GetFileInPath("/content/images/rico.png"); @@ -778,6 +749,11 @@ int main(int argc, char** argv) { settings.window.defaultIconFilename = GetFileInPath("/content/images/rico256c.png"); settings.window.resizable = true; settings.writeLicenseFile = false; - App(settings).run(); + //Using the damned SDL window now + SDLWindow* wnd = new SDLWindow(settings.window); + App app = App(settings, wnd); + HWND hwnd = wnd->win32HWND(); + + app.run(); return 0; } \ No newline at end of file From 8a6d7d0d8d9bd06c530b3de7e548879257287e2f Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 19:57:12 -0700 Subject: [PATCH 05/10] added new line --- main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a6116e0..7555714 100644 --- a/main.cpp +++ b/main.cpp @@ -749,6 +749,7 @@ int main(int argc, char** argv) { settings.window.defaultIconFilename = GetFileInPath("/content/images/rico256c.png"); settings.window.resizable = true; settings.writeLicenseFile = false; + //Using the damned SDL window now SDLWindow* wnd = new SDLWindow(settings.window); App app = App(settings, wnd); @@ -756,4 +757,4 @@ int main(int argc, char** argv) { app.run(); return 0; -} \ No newline at end of file +} From c9e997c794b552f699bb0a21ba0a92789ebb244d Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 20:44:29 -0700 Subject: [PATCH 06/10] Added mouse cursors --- content/cursor.png | Bin 0 -> 599 bytes main.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 content/cursor.png diff --git a/content/cursor.png b/content/cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..229081cad9286cb90931826b6416fa0e856d92c5 GIT binary patch literal 599 zcmeAS@N?(olHy`uVBq!ia0vp^0U*r51|<6gKdl8)jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJtM=93Yk-ZrXKfnaSW-5dwbz_Uz3A~OW^!RpDWDfSM#@=kAx zVC`9UIKzsj#Eg^gJLhYyf1ksdtX9vQW2bzKTf+FJ@q-l~nU48vkeyPressed(SDL_RIGHT_MOUSE_KEY)) { - ui->window()->setMouseVisible(false); + showMouse = false; app->window()->setRelativeMousePosition(app->window()->width()/2, app->window()->height()/2); mouseMovedBeginMotion = true; } else if(ui->keyReleased(SDL_RIGHT_MOUSE_KEY)) { - ui->window()->setMouseVisible(true); + showMouse = true; app->debugController.setActive(false); } @@ -551,6 +554,21 @@ void drawButtons(RenderDevice* rd) } void Demo::onGraphics(RenderDevice* rd) { + Vector2 mousepos = Vector2(0,0); + G3D::uint8 num = 0; + rd->window()->getRelativeMouseState(mousepos, num); + bool mouseOnScreen = true; + if(mousepos.x < 5 || mousepos.y < 5 || mousepos.x > rd->getViewport().width()-5 || mousepos.y > rd->getViewport().height()-5) + { + mouseOnScreen = false; + rd->window()->setInputCaptureCount(0); + } + else + { + mouseOnScreen = true; + rd->window()->setInputCaptureCount(1); + } + LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); app->renderDevice->setProjectionAndCameraMatrix(app->debugCamera); @@ -683,10 +701,42 @@ void Demo::onGraphics(RenderDevice* rd) { glDisable( GL_TEXTURE_2D ); + + + + if(showMouse && mouseOnScreen) + { + glEnable( GL_TEXTURE_2D ); + glEnable(GL_BLEND);// you enable blending function + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + + glBindTexture( GL_TEXTURE_2D, cursorid); + + + glBegin( GL_QUADS ); + glTexCoord2d(0.0,0.0); + glVertex2f(mousepos.x-40, mousepos.y-40); + glTexCoord2d( 1.0,0.0 ); + glVertex2f(mousepos.x+40, mousepos.y-40); + glTexCoord2d(1.0,1.0 ); + glVertex2f(mousepos.x+40, mousepos.y+40 ); + glTexCoord2d( 0.0,1.0 ); + glVertex2f( mousepos.x-40, mousepos.y+40 ); + glEnd(); + + glDisable( GL_TEXTURE_2D ); + } + rd->afterPrimitive(); rd->popState(); + + + + + drawButtons(rd); app->renderDevice->pop2D(); @@ -701,12 +751,14 @@ void App::main() { go = Texture::fromFile(GetFileInPath("/content/images/Run.png")); go_ovr = Texture::fromFile(GetFileInPath("/content/images/Run_ovr.png")); go_dn = Texture::fromFile(GetFileInPath("/content/images/Run_dn.png")); + cursor = Texture::fromFile(GetFileInPath("/content/cursor.png")); go_id = go->getOpenGLID(); go_dn_id = go_dn->getOpenGLID(); go_ovr_id = go_ovr->getOpenGLID(); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt")); sky = Sky::create(NULL, ExePath() + "/content/sky/"); + cursorid = cursor->openGLID(); applet->run(); } @@ -752,6 +804,8 @@ int main(int argc, char** argv) { //Using the damned SDL window now SDLWindow* wnd = new SDLWindow(settings.window); + //wnd->setInputCaptureCount(200); + wnd->setMouseVisible(false); App app = App(settings, wnd); HWND hwnd = wnd->win32HWND(); From c62df67db27d6688dcb5ce76027f0bd92763a56a Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 21:09:43 -0700 Subject: [PATCH 07/10] Changed default DataModel name to "undefined" --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 44d5688..ef9c433 100644 --- a/main.cpp +++ b/main.cpp @@ -249,8 +249,8 @@ void Demo::onInit() { dataModel = new Instance(); - //dataModel->name = "undefined"; dataModel->parent = NULL; + dataModel->name = "undefined"; initGUI(); From 9d30c2aed70672c14800ee679e7b79d9b7fe10fd Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 22:52:50 -0700 Subject: [PATCH 08/10] Tried doing stuff with fonts --- main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index ef9c433..ff927a4 100644 --- a/main.cpp +++ b/main.cpp @@ -603,7 +603,10 @@ void Demo::onGraphics(RenderDevice* rd) { PhysicalInstance* part = (PhysicalInstance*)instance; Vector3 size = part->size; Vector3 pos = part->position; - Draw::box(Box(Vector3((pos.x-size.x/2)/2,(pos.y-size.y/2)/2,(pos.z-size.z/2)/2),Vector3((pos.x+size.x/2)/2,(pos.y+size.y/2)/2,(pos.z+size.z/2)/2)), app->renderDevice, part->color, Color4::clear()); + Vector3 pos2 = Vector3((pos.x-size.x/2)/2,(pos.y-size.y/2)/2,(pos.z-size.z/2)/2); + Vector3 pos3 = Vector3((pos.x+size.x/2)/2,(pos.y+size.y/2)/2,(pos.z+size.z/2)/2); + Draw::box(Box(pos2 ,pos3), app->renderDevice, part->color, Color4::clear()); + fntdominant->draw3D(rd, "Testing", G3D::CoordinateFrame((Matrix3)Vector3(rd->getCameraToWorldMatrix().lookVector().directionOrZero().x*3.14,rd->getCameraToWorldMatrix().lookVector().directionOrZero().y*3.14,rd->getCameraToWorldMatrix().lookVector().directionOrZero().z*3.14), pos2), 10); } } From e29ad28a064e915486a8024da77cdd0138c2ecd9 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 22 Apr 2018 23:32:36 -0700 Subject: [PATCH 09/10] Test of hover text --- main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index ff927a4..5bf8ce1 100644 --- a/main.cpp +++ b/main.cpp @@ -606,13 +606,23 @@ void Demo::onGraphics(RenderDevice* rd) { Vector3 pos2 = Vector3((pos.x-size.x/2)/2,(pos.y-size.y/2)/2,(pos.z-size.z/2)/2); Vector3 pos3 = Vector3((pos.x+size.x/2)/2,(pos.y+size.y/2)/2,(pos.z+size.z/2)/2); Draw::box(Box(pos2 ,pos3), app->renderDevice, part->color, Color4::clear()); - fntdominant->draw3D(rd, "Testing", G3D::CoordinateFrame((Matrix3)Vector3(rd->getCameraToWorldMatrix().lookVector().directionOrZero().x*3.14,rd->getCameraToWorldMatrix().lookVector().directionOrZero().y*3.14,rd->getCameraToWorldMatrix().lookVector().directionOrZero().z*3.14), pos2), 10); + } } + Vector3 gamepoint = Vector3(0, 5, 0); + Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; + float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); + if(distance < 50 && distance > -50) + + { + if(distance < 0) + distance = distance*-1; + fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); + } app->renderDevice->disableLighting(); if (app->sky.notNull()) { From 11788fa37ce5635e088f5525c6219935e07f8b83 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Mon, 23 Apr 2018 11:35:02 -0700 Subject: [PATCH 10/10] Changed the way controllerflags are rendered, they work now --- main.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 5bf8ce1..47d6be4 100644 --- a/main.cpp +++ b/main.cpp @@ -514,12 +514,27 @@ std::string GetFileInPath(std::string file) void makeFlag(Vector3 &vec, RenderDevice* &rd) { Vector3 up = Vector3(vec.x, vec.y+3, vec.z); - Draw::lineSegment(G3D::LineSegment::fromTwoPoints(vec, up), rd, Color3::blue()); - G3D::Array parray; - parray.push(Vector2(up.x, up.y)); - parray.push(Vector2(up.x-1, up.y-.5)); - parray.push(Vector2(up.x, up.y-1)); - Draw::poly2D(parray, rd, Color3::blue()); + //Draw::lineSegment(G3D::LineSegment::fromTwoPoints(vec, up), rd, Color3::blue(), 3); + rd->setColor(Color3::blue()); + rd->beforePrimitive(); + + glBegin(GL_LINES); + glVertex3f(vec.x, vec.y, vec.z); + glVertex3f(up.x, up.y, up.z); + glEnd(); + + glBegin( GL_TRIANGLES ); + glVertex3f(up.x, up.y-1, up.z); + glVertex3f(up.x, up.y-0.5, up.z-1); + glVertex3f(up.x, up.y, up.z); + + glVertex3f(up.x, up.y, up.z); + glVertex3f(up.x, up.y-0.5, up.z-1); + glVertex3f(up.x, up.y-1, up.z); + + glEnd(); + rd->afterPrimitive(); + rd->setColor(Color3::white()); //I know how i will approach this now } @@ -588,7 +603,7 @@ void Demo::onGraphics(RenderDevice* rd) { app->renderDevice->setAmbientLightColor(Color3(1,1,1)); Draw::axes(CoordinateFrame(Vector3(0, 0, 0)), app->renderDevice); - //makeFlag(Vector3(1, 0.5, 0.5), rd); + makeFlag(Vector3(-1, 3.5, 0), rd);