clarify license, improve camera, remove most header creep

master
poikilos 2019-03-09 15:42:40 -05:00
parent 5fe008c9a7
commit 7a4e795779
16 changed files with 77 additions and 33 deletions

View File

@ -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)

View File

@ -2,8 +2,6 @@
#define DEBUG_H
#include <iostream>
#include <cassert>
std::ostream & debug();

View File

@ -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<u32>();
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();
}

View File

@ -11,11 +11,7 @@ class View;
#include <vector>
#include <irrlicht/irrlicht.h>
#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<std::wstring> 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;

View File

@ -6,7 +6,6 @@
#include <utility>
#include <irrlicht/irrlicht.h>
#include "Debug.h"
using std::cout;

View File

@ -133,6 +133,8 @@ only applies to Visual Studio users.)
such as from <https://sledjhamr.org/source/media/Irrlicht/>)
**"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 <https://code.google.com/archive/p/b3view/>

View File

@ -8,6 +8,10 @@
// #include <filesystem> // requires C++17
#include <experimental/filesystem> // 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;

View File

@ -1,18 +1,12 @@
#ifndef USERINTERFACE_H
#define USERINTERFACE_H
#include <irrlicht/irrlicht.h>
#include "extlib/CGUITTFont.h"
// Forward declaration of class Engine
class Engine;
#include <sstream>
#include <string>
#include <irrlicht/irrlicht.h>
#include "Debug.h"
#include "Engine.h"
#include "extlib/CGUITTFont.h"
enum UserInterfaceElements
{
UIE_PLAYBACKWINDOW = 1000,

View File

@ -1,12 +1,14 @@
#include "Utils.h"
#include <string>
#include <iostream>
#include <clocale>
#include <locale>
#include <vector>
#include <cmath>
#include <cwctype> // #include <cwtype>
#include <algorithm>
#include "Utils.h"
#include "Debug.h"
using namespace irr::core;
using namespace irr::scene;

View File

@ -1,9 +1,9 @@
#ifndef UTILS_H
#define UTILS_H
#include <cmath>
#include <string>
#include <irrlicht/irrlicht.h>
#include "Debug.h"
class Utility
{

View File

@ -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<f32> 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 <http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=30477>
// 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()

6
View.h
View File

@ -3,11 +3,7 @@
#include <irrlicht/irrlicht.h>
#include "Debug.h"
#include "Engine.h"
#include "Utils.h"
class Engine;
class View : public irr::IEventReceiver
{

View File

@ -1,9 +1,9 @@
#ifndef __C_GUI_TTFONT_H_INCLUDED__
#define __C_GUI_TTFONT_H_INCLUDED__
#include <irrlicht/irrlicht.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <irrlicht/irrlicht.h>
namespace irr
{

View File

@ -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();

BIN
screenshot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB