diff --git a/CHANGELOG.md b/CHANGELOG.md index 02cb93e..2be9813 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ ### Changed * only try to load png or jpg textures--skip others when cycling * cycle backwards correctly +* fix some of the header creep (remove unecessary includes in h files) +* improve initial camera position and angle (see top of characters since + camera is higher; z-forward characters face camera at an angle) +* Clarify relationship between camera start position in m_Engine and + m_View's rotation (m_Pitch and m_Yaw). Now, `setNewCameraPosition` + operates on view correctly (relatively) no matter where camera starts. ## [git] - 2019-03-07 (poikilos) diff --git a/Debug.h b/Debug.h index 4bfb900..2d7c2d8 100644 --- a/Debug.h +++ b/Debug.h @@ -2,8 +2,6 @@ #define DEBUG_H #include -#include - std::ostream & debug(); diff --git a/Engine.cpp b/Engine.cpp index 0db3fe9..3975730 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -1,5 +1,9 @@ #include "Engine.h" +#include "UserInterface.h" +#include "View.h" +#include "Utils.h" + using std::cout; using std::wcerr; using std::endl; @@ -27,8 +31,11 @@ void Engine::setupScene() m_Scene->setAmbientLight( SColorf( 0.2f, 0.2f, 0.2f )); // Setup Camera - ICameraSceneNode *camera = m_Scene->addCameraSceneNode( nullptr, vector3df( 0, 0, -10 ), vector3df() ); - camera->setAspectRatio(( f32 ) m_Driver->getScreenSize().Width / m_Driver->getScreenSize().Height ); + // (so z-forward characters face camera partially (formerly vector3df( 0, 0, -10 ), vector3df()) + tmpPosVec3f = vector3df( 4.5, 3, 9 ); + tmpTargetVec3f = vector3df(0, 3, 0); + ICameraSceneNode *camera = m_Scene->addCameraSceneNode(nullptr, tmpPosVec3f, tmpTargetVec3f); // this will be overridden by View m_Yaw and m_Pitch--see "calculate m_Yaw" further down + camera->setAspectRatio((f32)m_Driver->getScreenSize().Width / m_Driver->getScreenSize().Height); } IGUIEnvironment * Engine::getGUIEnvironment() const @@ -175,6 +182,9 @@ Engine::Engine() m_WindowSize = new dimension2d(); m_WindowSize->Width = m_Driver->getScreenSize().Width; m_WindowSize->Height = m_Driver->getScreenSize().Height; + + // (do not calculate m_Yaw and m_Pitch, here, but in View constructor) + this->playAnimation(); } diff --git a/Engine.h b/Engine.h index 4844c5c..a317728 100644 --- a/Engine.h +++ b/Engine.h @@ -11,11 +11,7 @@ class View; #include #include - #include "EventHandler.h" -#include "UserInterface.h" -#include "View.h" - #include "extlib/CGUITTFont.h" enum SceneItemID @@ -58,6 +54,14 @@ private: irr::u32 worldFPS; irr::u32 prevFPS; std::vector textureExtensions; + // Making materials in contructor or setupScene causes segfault at + // `m_Driver->setMaterial( *lineX );` in + // `Engine::drawAxisLines` for unknown reason: +// irr::video::SMaterial *lineX; +// irr::video::SMaterial *lineY; +// irr::video::SMaterial *lineZ; + irr::core::vector3df tmpPosVec3f; + irr::core::vector3df tmpTargetVec3f; public: std::wstring m_PreviousPath; diff --git a/EventHandler.h b/EventHandler.h index 86518d1..bc3c6c1 100644 --- a/EventHandler.h +++ b/EventHandler.h @@ -6,7 +6,6 @@ #include #include - #include "Debug.h" using std::cout; diff --git a/README.md b/README.md index 919c6cb..bd8ca28 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ only applies to Visual Studio users.) such as from ) **"Feel free to use however you like, commercial etc, credits are Appreciated..."** -Psionic +* icon (b3view.xcf, p3view.png) Creative Commons Attribution Share-Alike + 4.0 [poikilos](https://poikilos.org) * All files not mentioned above, and not described in text files in the same folder as media (such as "build" folder) are licensed under the **GPL v3** as per diff --git a/UserInterface.cpp b/UserInterface.cpp index 51de216..11b3c24 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -8,6 +8,10 @@ // #include // requires C++17 #include // requires C++14 such as gcc 8.2.1 +#include "Debug.h" +#include "Engine.h" +#include "Utils.h" + using namespace irr; using namespace irr::core; using namespace irr::gui; diff --git a/UserInterface.h b/UserInterface.h index e52e2f7..1456a22 100644 --- a/UserInterface.h +++ b/UserInterface.h @@ -1,18 +1,12 @@ #ifndef USERINTERFACE_H #define USERINTERFACE_H +#include +#include "extlib/CGUITTFont.h" + // Forward declaration of class Engine class Engine; -#include -#include -#include - -#include "Debug.h" -#include "Engine.h" - -#include "extlib/CGUITTFont.h" - enum UserInterfaceElements { UIE_PLAYBACKWINDOW = 1000, diff --git a/Utils.cpp b/Utils.cpp index 2651c03..a7fd9c3 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -1,12 +1,14 @@ +#include "Utils.h" #include #include #include #include #include +#include #include // #include #include -#include "Utils.h" +#include "Debug.h" using namespace irr::core; using namespace irr::scene; diff --git a/Utils.h b/Utils.h index 47a2ed5..696ea3c 100644 --- a/Utils.h +++ b/Utils.h @@ -1,9 +1,9 @@ #ifndef UTILS_H #define UTILS_H -#include +#include + #include -#include "Debug.h" class Utility { diff --git a/View.cpp b/View.cpp index 7111431..abd3ecc 100644 --- a/View.cpp +++ b/View.cpp @@ -1,4 +1,5 @@ #include "View.h" +#include "Engine.h" using namespace irr; using namespace irr::core; @@ -8,7 +9,10 @@ void View::setNewCameraPosition() { vector3d newCameraPosition; ICameraSceneNode *camera = m_Engine->m_Scene->getActiveCamera(); - + vector3df oldCamPos = camera->getPosition(); + // vector3df oldCamRot = camera->getRotation(); + // NOTE: rotationToDirection converts a rotation to a vec3 direction. + // vector3df oldCamRot = m_Engine->tmpPosVec3f.?(m_Engine->tmpTargetVec3f); newCameraPosition.X = 0; newCameraPosition.Y = m_CameraDistance * sin( m_Pitch ); newCameraPosition.Z = m_CameraDistance * cos( m_Pitch ); @@ -17,7 +21,11 @@ void View::setNewCameraPosition() yawMatrix.setRotationRadians( vector3df( 0, m_Yaw, 0 )); yawMatrix.transformVect( newCameraPosition ); - camera->setPosition( newCameraPosition ); + newCameraPosition.Y = oldCamPos.Y; + camera->setPosition( newCameraPosition ); + // vector3df newRotation(); + // camera->setRotation(); + // camera->setTarget(m_Engine->tmpTargetVec3f); // Set Light direction setNewLightDirection( newCameraPosition ); @@ -44,8 +52,29 @@ View::View( Engine *engine ) // Set Camera Distance m_CameraDistance = 10; - debug() << "Yaw: " << m_Yaw << endl; - debug() << "Pitch: " << m_Pitch << endl; + // vectors for angle are opposite, since camera revolves around center + vector3df offsetVec3( + engine->tmpPosVec3f.X-engine->tmpTargetVec3f.X, + engine->tmpPosVec3f.Y-engine->tmpTargetVec3f.Y, + engine->tmpPosVec3f.Z-engine->tmpTargetVec3f.Z + ); + // m_CameraDistance = sqrtf() + m_CameraDistance = offsetVec3.getLength(); + // NOTE: rotationToDirection converts a rotation to a vec3 direction + // vector3df rotationVec3 = engine->tmpPosVec3f.?(engine->tmpTargetVec3f); + // vector3df rotationVec3 = engine->tmpTargetVec3f.?(engine->tmpPosVec3f); + + // see rogerborg on + // const f32 dot = engine->tmpTargetVec3f.dotProduct(engine->tmpPosVec3f); // to...(from) // angle only + + m_Yaw = atan2(offsetVec3.X, offsetVec3.Z); + m_Pitch = asin(-offsetVec3.Y); + + // m_Yaw = rotationVec3.Y; + // m_Pitch = rotationVec3.X; + + debug() << "Yaw: " << radToDeg(m_Yaw) << endl; + debug() << "Pitch: " << radToDeg(m_Pitch) << endl; } View::~View() diff --git a/View.h b/View.h index 7614bca..6666431 100644 --- a/View.h +++ b/View.h @@ -3,11 +3,7 @@ #include -#include "Debug.h" -#include "Engine.h" -#include "Utils.h" - - +class Engine; class View : public irr::IEventReceiver { diff --git a/b3view.xcf b/etc/b3view.xcf similarity index 100% rename from b3view.xcf rename to etc/b3view.xcf diff --git a/extlib/CGUITTFont.h b/extlib/CGUITTFont.h index 51b538b..776589f 100644 --- a/extlib/CGUITTFont.h +++ b/extlib/CGUITTFont.h @@ -1,9 +1,9 @@ #ifndef __C_GUI_TTFONT_H_INCLUDED__ #define __C_GUI_TTFONT_H_INCLUDED__ -#include #include #include FT_FREETYPE_H +#include namespace irr { diff --git a/main.cpp b/main.cpp index 5e79ac9..e39e24b 100644 --- a/main.cpp +++ b/main.cpp @@ -44,8 +44,8 @@ int main( int argc, char **argv ) engine->loadMesh( wstring( initialFileName )); free( initialFileName ); } - else - engine->loadMesh( L"test.b3d" ); +// else +// engine->loadMesh( L"test.b3d" ); engine->run(); diff --git a/screenshot.jpg b/screenshot.jpg new file mode 100644 index 0000000..9425970 Binary files /dev/null and b/screenshot.jpg differ