Fixing Salmon Engine bugs

This commit is contained in:
Vladislav Khorev 2013-01-23 20:58:15 +00:00
parent 5720f8322b
commit 24427045ba
13 changed files with 500 additions and 451 deletions

View File

@ -137,6 +137,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG</PreprocessorDefinitions> <PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4503</DisableSpecificWarnings>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -148,6 +149,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG;NOSOUND</PreprocessorDefinitions> <PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG;NOSOUND</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories>
<DisableSpecificWarnings>/wd 4503</DisableSpecificWarnings>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -162,6 +164,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;NDEBUG</PreprocessorDefinitions> <PreprocessorDefinitions>TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;NDEBUG</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510</AdditionalIncludeDirectories>
<DisableSpecificWarnings>/wd 4503</DisableSpecificWarnings>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>

View File

@ -55,6 +55,8 @@ public:
void Draw(); void Draw();
TDataTriangleList& GetDataTriangleList();
friend class TFlexModelManager; friend class TFlexModelManager;
}; };

View File

@ -14,31 +14,154 @@
namespace SE namespace SE
{ {
class TSalmonRendererInterface : public TRendererInterface struct TCameraInterface
{
vec3 CamVec;
vec3 CamShift;
TCameraInterface();
virtual ~TCameraInterface()
{
}
};
struct TPanoramicCamera : public TCameraInterface
{ {
protected:
float CamAlpha; float CamAlpha;
float CamPhi; float CamPhi;
float CamDist; float CamDist;
vec3 CamShift;
vec3 CamPos; //Do not change - call CalcCamPosVec instead TPanoramicCamera();
vec3 CamVec; //Do not change - call CalcCamPosVec instead
void MoveAlpha(float dAlpha);
void MovePhi(float dPhi);
void MoveDist(float dDist);
void SetAlpha(float alpha);
void MoveForward();
void MoveBackward();
void MoveLeft();
void MoveRight();
void CalcCamVec();
void SetCamView();
};
struct TPitCamera : public TCameraInterface
{
vec4 CameraQuat;
void SetCamView();
void CalcCamVec();
void RotateByQuat(vec4 quat);
};
typedef boost::variant<TPanoramicCamera, TPitCamera> TCamera;
struct TSetCameraViewVisitor : public boost::static_visitor<void>
{
void operator()(TPanoramicCamera& panoramicCamera)
{
panoramicCamera.SetCamView();
}
void operator()(TPitCamera& pitCamera)
{
pitCamera.SetCamView();
}
};
struct TCalcCamVecVisitor : public boost::static_visitor<void>
{
void operator()(TPanoramicCamera& panoramicCamera)
{
panoramicCamera.CalcCamVec();
}
void operator()(TPitCamera& pitCamera)
{
pitCamera.CalcCamVec();
}
};
struct TGetCamVecVisitor : public boost::static_visitor<vec3&>
{
vec3& operator()(TPanoramicCamera& panoramicCamera) const
{
return panoramicCamera.CamVec;
}
vec3& operator()(TPitCamera& pitCamera) const
{
return pitCamera.CamVec;
}
};
struct TGetCamShiftVisitor : public boost::static_visitor<vec3&>
{
vec3& operator()(TPanoramicCamera& panoramicCamera) const
{
return panoramicCamera.CamShift;
}
vec3& operator()(TPitCamera& pitCamera) const
{
return pitCamera.CamShift;
}
};
class TSalmonRendererInterface : public TRendererInterface
{
protected:
/*
float CamAlpha;
float CamPhi;
float CamDist;
vec3 CamShift;*/
mat4 CamModelViewMatrix; mat4 CamModelViewMatrix;
mat4 CamInversedModelViewMatrix; mat4 CamInversedModelViewMatrix;
float GlobalShadowAreaHalfSize; float GlobalShadowAreaHalfSize;
void CalcCamPosVec();
virtual void DrawQuad(const T2DQuad& quad) = 0; virtual void DrawQuad(const T2DQuad& quad) = 0;
public: public:
TCamera CameraMover;
//vec3 CamShift;
vec3 CamPos; //Do not change - call CalcCamPosVec instead
//vec3 CamVec; //Do not change - call CalcCamPosVec instead
vec3 GetCamShift()
{
return boost::apply_visitor(TGetCamShiftVisitor(), CameraMover);
}
vec3 GetCamVec()
{
return boost::apply_visitor(TGetCamVecVisitor(), CameraMover);
}
TSalmonRendererInterface(); TSalmonRendererInterface();
virtual void InitOpenGL(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight); virtual void InitOpenGL(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight);
void CalcCamPosVec();
virtual void SetUniforms(); virtual void SetUniforms();
void SetPerspectiveFullScreenViewport(); void SetPerspectiveFullScreenViewport();
@ -59,18 +182,8 @@ public:
void SetGlNegZView(); void SetGlNegZView();
void MoveAlpha(float dAlpha);
void MovePhi(float dPhi);
void MoveDist(float dDist);
void SetAlpha(float alpha);
vec3 GetCamPos(); vec3 GetCamPos();
void MoveForward();
void MoveBackward();
void MoveLeft();
void MoveRight();
virtual void SwitchToScreen(); virtual void SwitchToScreen();
virtual void SwitchToFrameBuffer(const std::string& frameName); virtual void SwitchToFrameBuffer(const std::string& frameName);
void SwitchToCubemapBuffer(const std::string& frameName,cardinal cubeSide); void SwitchToCubemapBuffer(const std::string& frameName,cardinal cubeSide);

View File

@ -111,16 +111,19 @@ public:
virtual void UpdateQuick() { } virtual void UpdateQuick() { }
//To process input - this method is called more frequently than Update() //To process input - this method is called more frequently than Update()
virtual void OuterOnTapDown(vec2 p);
virtual void OuterOnTapUp(vec2 p);
virtual void OuterOnMove(vec2 shift); virtual void OuterOnMove(vec2 shift);
virtual void InnerOnTapDown(vec2 p) { }
virtual void InnerOnTapUp(vec2 p) { }
virtual void InnerOnMove(vec2 shift) { } virtual void InnerOnMove(vec2 shift) { }
//To do on mouse move (with or without pressed buttons)
virtual void OnMouseDown(TMouseState& mouseState) { } virtual void OnMouseMove(TMouseState& mouseState) { } //Windows only
//To do on mouse up (with or without pressed buttons)
virtual void OnMouseUp(TMouseState& mouseState) { }
//To do on mouse down (with or without pressed buttons)
//Be careful - even when user "upped" button, in mouseState this button appears as pressed
virtual void OnMouseWheel(short int delta) { } virtual void OnMouseWheel(short int delta) { }
//To do on mouse wheel move //To do on mouse wheel move

View File

@ -51,15 +51,6 @@ public:
virtual void UpdateQuick() { }; virtual void UpdateQuick() { };
//To process input - this method is called more frequently than Update() //To process input - this method is called more frequently than Update()
virtual void OnMouseMove(TMouseState& mouseState) { }
//To do on mouse move (with or without pressed buttons)
virtual void OnMouseDown(TMouseState& mouseState) { }
//To do on mouse up (with or without pressed buttons)
virtual void OnMouseUp(TMouseState& mouseState) { }
//To do on mouse down (with or without pressed buttons)
//Be careful - even when user "upped" button, in mouseState this button appears as pressed
virtual void OnMouseWheel(short int delta) { } virtual void OnMouseWheel(short int delta) { }
//To do on mouse wheel move //To do on mouse wheel move

View File

@ -3,11 +3,10 @@
#include "include/Utils/Utils.h" #include "include/Utils/Utils.h"
#pragma warning(disable: 4503) //ololo, DisctionariesMap expands into looong boolshit
namespace SE namespace SE
{ {
typedef boost::variant< typedef boost::variant<
std::shared_ptr<TBindableVar<int>>, std::shared_ptr<TBindableVar<int>>,
std::shared_ptr<TBindableVar<float>>, std::shared_ptr<TBindableVar<float>>,

View File

@ -74,6 +74,8 @@ mat4 MultMatrixMatrix(const mat4& m1, const mat4& m2);
bool IsFloatEqual(float a, float b); bool IsFloatEqual(float a, float b);
bool LineCouldCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr); //overall test
int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr); int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr);
int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr, vec3& CrossPoint); int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr, vec3& CrossPoint);

View File

@ -34,7 +34,7 @@ public:
tvec2<TYPENAME> operator+(const tvec2<TYPENAME>& a) const; tvec2<TYPENAME> operator+(const tvec2<TYPENAME>& a) const;
tvec2<TYPENAME>& operator-=(const tvec2<TYPENAME>& vc); tvec2<TYPENAME>& operator-=(const tvec2<TYPENAME>& vc);
tvec2<TYPENAME> operator-(const tvec2<TYPENAME>& a) const; tvec2<TYPENAME> operator-(const tvec2<TYPENAME>& a) const;
tvec2<TYPENAME>& operator-(); tvec2<TYPENAME> operator-();
tvec2<TYPENAME>& operator*=(TYPENAME c); tvec2<TYPENAME>& operator*=(TYPENAME c);
}; };
@ -70,7 +70,7 @@ public:
tvec3<TYPENAME1>& operator-=(const tvec3<TYPENAME1>& vc); tvec3<TYPENAME1>& operator-=(const tvec3<TYPENAME1>& vc);
tvec3<TYPENAME1> operator+(const tvec3<TYPENAME1>& a) const; tvec3<TYPENAME1> operator+(const tvec3<TYPENAME1>& a) const;
tvec3<TYPENAME1> operator-(const tvec3<TYPENAME1>& a) const; tvec3<TYPENAME1> operator-(const tvec3<TYPENAME1>& a) const;
tvec3<TYPENAME1>& operator-(); tvec3<TYPENAME1> operator-();
tvec3<TYPENAME1>& operator*=(TYPENAME1 c); tvec3<TYPENAME1>& operator*=(TYPENAME1 c);
tvec3<TYPENAME1> operator*(const tmat3<TYPENAME1>& mt) const; //MultRowMatrix() tvec3<TYPENAME1> operator*(const tmat3<TYPENAME1>& mt) const; //MultRowMatrix()
}; };
@ -114,6 +114,7 @@ typedef tvec4<float> vec4;
vec4 InverseQuat(const vec4& q); vec4 InverseQuat(const vec4& q);
vec4 NormalizeQuat(const vec4& q);
template<typename TYPENAME1> template<typename TYPENAME1>
@ -279,12 +280,14 @@ inline tvec2<TYPENAME> tvec2<TYPENAME>::operator-(const tvec2<TYPENAME>& a) cons
} }
template<typename TYPENAME> template<typename TYPENAME>
inline tvec2<TYPENAME>& tvec2<TYPENAME>::operator-() inline tvec2<TYPENAME> tvec2<TYPENAME>::operator-()
{ {
v[0] = -v[0]; tvec2<TYPENAME> r = *this;
v[1] = -v[1];
return *this; r.v[0] = -v[0];
r.v[1] = -v[1];
return r;
} }
template<typename TYPENAME> template<typename TYPENAME>
@ -440,13 +443,15 @@ inline tvec3<TYPENAME1> tvec3<TYPENAME1>::operator-(const tvec3<TYPENAME1>& a) c
} }
template<typename TYPENAME1> template<typename TYPENAME1>
inline tvec3<TYPENAME1>& tvec3<TYPENAME1>::operator-() inline tvec3<TYPENAME1> tvec3<TYPENAME1>::operator-()
{ {
v[0] = -v[0]; tvec3<TYPENAME1> r = *this;
v[1] = -v[1];
v[2] = -v[2];
return *this; r.v[0] = -v[0];
r.v[1] = -v[1];
r.v[2] = -v[2];
return r;
} }
template<typename TYPENAME1> template<typename TYPENAME1>
@ -732,14 +737,14 @@ inline vec4 InverseQuat(const vec4& q)
{ {
float n; float n;
vec4 r; vec4 r;
n = (q.v[0]*q.v[0]+q.v[1]*q.v[1]+q.v[2]*q.v[2]); n = (q.v[0]*q.v[0]+q.v[1]*q.v[1]+q.v[2]*q.v[2]+q.v[3]*q.v[3]);
if (n!=0.0f) if (n!=0.0f)
{ {
r.v[0] = -q.v[0] / n; r.v[0] = -q.v[0] / n;
r.v[1] = -q.v[1] / n; r.v[1] = -q.v[1] / n;
r.v[2] = -q.v[2] / n; r.v[2] = -q.v[2] / n;
r.v[3] = q.v[3]; r.v[3] = q.v[3] / n;
} }
else else
{ {
@ -751,6 +756,26 @@ inline vec4 InverseQuat(const vec4& q)
return r; return r;
}
inline vec4 NormalizeQuat(const vec4& q)
{
float n;
vec4 r;
n = (q.v[0]*q.v[0]+q.v[1]*q.v[1]+q.v[2]*q.v[2]+q.v[3]*q.v[3]);
if (n!=0.0f)
{
r.v[0] = q.v[0] / n;
r.v[1] = q.v[1] / n;
r.v[2] = q.v[2] / n;
r.v[3] = q.v[3] / n;
}
return r;
} }
//========== mat2 =========== //========== mat2 ===========

View File

@ -109,6 +109,11 @@ void TFlexModel::Draw()
Renderer->DrawTriangleList(RenderPair.second); Renderer->DrawTriangleList(RenderPair.second);
} }
TDataTriangleList& TFlexModel::GetDataTriangleList()
{
return RenderPair.second.Data;
}
void TFlexModelManager::LoadModelFromXml(std::string xmlFileName) void TFlexModelManager::LoadModelFromXml(std::string xmlFileName)
{ {

View File

@ -6,13 +6,226 @@
namespace SE namespace SE
{ {
TCameraInterface::TCameraInterface()
: CamShift(ZeroVec3)
, CamVec(ZeroVec3)
{
}
TSalmonRendererInterface::TSalmonRendererInterface() TPanoramicCamera::TPanoramicCamera()
: CamAlpha(0.0f) : CamAlpha(0.0f)
, CamPhi(0.0f) , CamPhi(0.0f)
, CamDist(0.0f) , CamDist(0.0f)
, CamShift(ZeroVec3) {
, GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE) }
void TPanoramicCamera::MoveAlpha(float dAlpha)
{
if (dAlpha == 0.0f)
return;
CamAlpha += dAlpha;
while (CamAlpha >= 2*pi)
{
CamAlpha -= 2*pi;
}
while (CamAlpha<0.0f)
{
CamAlpha += 2*pi;
}
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::MovePhi(float dPhi)
{
if (dPhi == 0.0f)
return;
//float oldCamPhi = CamPhi;
CamPhi += dPhi;
if (CamPhi > CONST_MAX_CAM_PHI)
{
CamPhi = CONST_MAX_CAM_PHI;
}
if (CamPhi < CONST_MIN_CAM_PHI)
{
CamPhi = CONST_MIN_CAM_PHI;
}
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::MoveDist(float dDist)
{
CamDist += dDist;
if (CamDist<CONST_MIN_CAM_DIST)
{
CamDist = CONST_MIN_CAM_DIST;
}
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::SetAlpha(float alpha)
{
if (alpha == CamAlpha)
return;
CamAlpha = alpha;
while (CamAlpha >= 2*pi)
{
CamAlpha -= 2*pi;
}
while (CamAlpha<0.0f)
{
CamAlpha += 2*pi;
}
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::MoveForward()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = sina;
mov.v[1] = 0;
mov.v[2] = - cosa;
CamShift = CamShift + mov;
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::MoveBackward()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = - sina;
mov.v[1] = 0;
mov.v[2] = cosa;
CamShift = CamShift + mov;
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::MoveLeft()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = - cosa;
mov.v[1] = 0;
mov.v[2] = - sina;
CamShift = CamShift + mov;
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::MoveRight()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = cosa;
mov.v[1] = 0;
mov.v[2] = sina;
CamShift = CamShift + mov;
//Possibly refactor???
Renderer->CalcCamPosVec();
}
void TPanoramicCamera::CalcCamVec()
{
vec3 camPos;
vec3 camVec;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
float sinp = sinf(CamPhi);
float cosp = cosf(CamPhi);
CamVec.v[0] = CamDist * cosp * sina;
CamVec.v[1] = - CamDist * sinp;
CamVec.v[2] = - CamDist * cosp * cosa;
}
void TPanoramicCamera::SetCamView()
{
Renderer->LoadIdentity();
Renderer->TranslateMatrix(vec3(0.0f, 0.0f, -CamDist));
Renderer->RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f)));
Renderer->RotateMatrix(vec4(0.f, 1.f * sin(CamAlpha/2.f), 0.f, 1.f * cos(CamAlpha/2.f)));
Renderer->TranslateMatrix(-CamShift);
}
void TPitCamera::SetCamView()
{
Renderer->LoadIdentity();
Renderer->RotateMatrix(InverseQuat(CameraQuat));
Renderer->TranslateMatrix(-CamShift);
}
void TPitCamera::CalcCamVec()
{
vec3 r = vec3(0,0,-1);
CamVec = Normalize(CameraQuat * vec4(r) * InverseQuat(CameraQuat));
}
void TPitCamera::RotateByQuat(vec4 quat)
{
CameraQuat = quat * CameraQuat;
//float len = Length(CameraQuat);
}
//============================================
//============================================
//============================================
TSalmonRendererInterface::TSalmonRendererInterface()
: GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE)
{ {
ProjectionMatrixStack.push(IdentityMatrix4); ProjectionMatrixStack.push(IdentityMatrix4);
@ -101,16 +314,11 @@ void TSalmonRendererInterface::InitOpenGL(int screenWidth, int screenHeight, flo
void TSalmonRendererInterface::CalcCamPosVec() void TSalmonRendererInterface::CalcCamPosVec()
{ {
float sina = sinf(CamAlpha); TCalcCamVecVisitor v;
float cosa = cosf(CamAlpha);
float sinp = sinf(CamPhi);
float cosp = cosf(CamPhi);
CamVec.v[0] = CamDist * cosp * sina; boost::apply_visitor(v, CameraMover);
CamVec.v[1] = - CamDist * sinp;
CamVec.v[2] = - CamDist * cosp * cosa;
CamPos = CamShift - CamVec; CamPos = GetCamShift() - GetCamVec();
RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,(float*)&CamPos); RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,(float*)&CamPos);
} }
@ -175,26 +383,8 @@ void TSalmonRendererInterface::PushPerspectiveProjectionMatrix(float angle, floa
void TSalmonRendererInterface::SetGLCamView() void TSalmonRendererInterface::SetGLCamView()
{ {
/* TSetCameraViewVisitor v;
glLoadIdentity(); boost::apply_visitor(v, CameraMover);
glTranslatef(0.0f, 0.0f, -CamDist);
glRotatef(CamPhi*180.0f/pi, 1.0f, 0.0f, 0.0f);
glRotatef(CamAlpha*180.0f/pi, 0.0f, 1.0f, 0.0f);
//TODO
glTranslatef(-CamShift.v[0], -CamShift.v[1], -CamShift.v[2]);
glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m);
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,CamPos.v);*/
LoadIdentity();
TranslateMatrix(vec3(0.0f, 0.0f, -CamDist));
RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f)));
RotateMatrix(vec4(0.f, 1.f * sin(CamAlpha/2.f), 0.f, 1.f * cos(CamAlpha/2.f)));
TranslateMatrix(-CamShift);
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -238,7 +428,7 @@ void TSalmonRendererInterface::SetGlPosXView()
RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f)));
RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-GetCamShift());
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -264,7 +454,7 @@ void TSalmonRendererInterface::SetGlNegXView()
RotateMatrix(vec4(0.f, -1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(0.f, -1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f)));
RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-GetCamShift());
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -286,7 +476,7 @@ void TSalmonRendererInterface::SetGlPosYView()
LoadIdentity(); LoadIdentity();
RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-GetCamShift());
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -309,7 +499,7 @@ void TSalmonRendererInterface::SetGlNegYView()
LoadIdentity(); LoadIdentity();
RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-GetCamShift());
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -335,7 +525,7 @@ void TSalmonRendererInterface::SetGlPosZView()
RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f)));
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-GetCamShift());
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -358,7 +548,7 @@ void TSalmonRendererInterface::SetGlNegZView()
RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f)));
TranslateMatrix(-CamShift); TranslateMatrix(-GetCamShift());
CamModelViewMatrix = ModelviewMatrixStack.top(); CamModelViewMatrix = ModelviewMatrixStack.top();
CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);
@ -374,368 +564,6 @@ vec3 TSalmonRendererInterface::GetCamPos()
} }
void TSalmonRendererInterface::MoveAlpha(float dAlpha)
{
if (dAlpha == 0.0f)
return;
CamAlpha += dAlpha;
while (CamAlpha >= 2*pi)
{
CamAlpha -= 2*pi;
}
while (CamAlpha<0.0f)
{
CamAlpha += 2*pi;
}
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
*/
}
void TSalmonRendererInterface::MovePhi(float dPhi)
{
if (dPhi == 0.0f)
return;
//float oldCamPhi = CamPhi;
CamPhi += dPhi;
if (CamPhi > CONST_MAX_CAM_PHI)
{
CamPhi = CONST_MAX_CAM_PHI;
}
if (CamPhi < CONST_MIN_CAM_PHI)
{
CamPhi = CONST_MIN_CAM_PHI;
}
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}*/
}
void TSalmonRendererInterface::MoveDist(float dDist)
{
CamDist += dDist; /*
if (CamDist>CONST_MAX_CAM_DIST)
{
CamDist = CONST_MAX_CAM_DIST;
}*/
if (CamDist<CONST_MIN_CAM_DIST)
{
CamDist = CONST_MIN_CAM_DIST;
}
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}*/
}
void TSalmonRendererInterface::SetAlpha(float alpha)
{
if (alpha == CamAlpha)
return;
CamAlpha = alpha;
while (CamAlpha >= 2*pi)
{
CamAlpha -= 2*pi;
}
while (CamAlpha<0.0f)
{
CamAlpha += 2*pi;
}
//Possibly refactor???
CalcCamPosVec();
}
void TSalmonRendererInterface::MoveForward()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = sina;
mov.v[1] = 0;
mov.v[2] = - cosa;
CamShift = CamShift + mov;
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}*/
}
void TSalmonRendererInterface::MoveBackward()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = - sina;
mov.v[1] = 0;
mov.v[2] = cosa;
CamShift = CamShift + mov;
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}*/
}
void TSalmonRendererInterface::MoveLeft()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = - cosa;
mov.v[1] = 0;
mov.v[2] = - sina;
CamShift = CamShift + mov;
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
*/
}
void TSalmonRendererInterface::MoveRight()
{
vec3 mov;
float sina = sinf(CamAlpha);
float cosa = cosf(CamAlpha);
mov.v[0] = cosa;
mov.v[1] = 0;
mov.v[2] = sina;
CamShift = CamShift + mov;
//Possibly refactor???
CalcCamPosVec();
/*
if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos))
{
CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi = CONST_MIN_CAM_PHI;
CalcCamPosVec();
h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos);
while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1])
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}
else
{
CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP;
CalcCamPosVec();
}
}*/
}
void TSalmonRendererInterface::SwitchToScreen() void TSalmonRendererInterface::SwitchToScreen()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);

View File

@ -64,10 +64,23 @@ void TApplicationAncestor::OuterUpdate(cardinal timer)
CheckGlError(); CheckGlError();
} }
void TApplicationAncestor::OuterOnTapDown(vec2 p)
{
//ResourceManager->GUIManager.OnMouseDown(p);
InnerOnTapDown(p);
}
void TApplicationAncestor::OuterOnTapUp(vec2 p)
{
//ResourceManager->GUIManager.OnMouseUp(p);
InnerOnTapUp(p);
}
void TApplicationAncestor::OuterOnMove(vec2 shift) void TApplicationAncestor::OuterOnMove(vec2 shift)
{ {
//ResourceManager->GUIManager.OnMove(shift);
InnerOnMove(shift); InnerOnMove(shift);
} }
} //namespace SE } //namespace SE

View File

@ -30,7 +30,10 @@ cardinal LastTickCount;
//User application //User application
TApplication* App = NULL; TApplication* App = NULL;
vec2 MouseButtonPos;
vec2 MouseTotalShift;
bool MouseButtonPressed = false;
bool MouseMoved = false;
void TApplication::OnKeyPress(cardinal key) void TApplication::OnKeyPress(cardinal key)
{ {
@ -183,7 +186,7 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}*/ }*/
break; break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
mouseState.X = (lParam << 16) >> 16; mouseState.X = (lParam << 16) >> 16;
mouseState.Y = lParam >> 16; mouseState.Y = lParam >> 16;
mouseState.LeftButtonPressed = (wParam & MK_LBUTTON); mouseState.LeftButtonPressed = (wParam & MK_LBUTTON);
@ -191,6 +194,24 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
mouseState.RightButtonPressed = (wParam & MK_RBUTTON); mouseState.RightButtonPressed = (wParam & MK_RBUTTON);
App->OnMouseMove(mouseState); App->OnMouseMove(mouseState);
if (MouseButtonPressed)
{
vec2 currentMousePos(static_cast<float>(mouseState.X), static_cast<float>(App->Height - mouseState.Y));
vec2 shift = (MouseButtonPos - currentMousePos);
//shift.v[1] = - shift.v[1];
App->OuterOnMove(shift);
//App->OuterOnMove(currentMousePos - MouseButtonPos);
MouseButtonPos = currentMousePos;
MouseTotalShift += shift;
if (fabs(MouseTotalShift.v[0]) > 10.f || fabs(MouseTotalShift.v[1]) > 10.f)
{
MouseMoved = true;
}
}
break; break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
@ -201,7 +222,22 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON);
mouseState.RightButtonPressed = (wParam & MK_RBUTTON); mouseState.RightButtonPressed = (wParam & MK_RBUTTON);
App->OnMouseDown(mouseState); MouseButtonPos = vec2(static_cast<float>(mouseState.X), static_cast<float>(App->Height - mouseState.Y));
if (mouseState.LeftButtonPressed)
{
App->OuterOnTapDown(MouseButtonPos);
}
MouseButtonPressed = true;
MouseMoved = false;
MouseTotalShift = vec2(0,0);
break; break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
case WM_RBUTTONUP: case WM_RBUTTONUP:
@ -211,7 +247,13 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON);
mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON);
App->OnMouseUp(mouseState); if (!MouseMoved)
{
App->OuterOnTapUp(vec2(static_cast<float>(mouseState.X), static_cast<float>(App->Height - mouseState.Y)));
}
MouseButtonPressed = false;
break; break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:

View File

@ -151,6 +151,29 @@ bool IsFloatEqual(float a, float b)
return (fabs(b-a) <= CONST_EPSILON) ? true : false; return (fabs(b-a) <= CONST_EPSILON) ? true : false;
} }
bool LineCouldCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr)
{
for (int i=0; i<3; i++)
{
float min_tr = min(min(tr.p[0].v[i], tr.p[1].v[i]), tr.p[2].v[i]);
if (max(a.v[i], b.v[i]) < min_tr)
{
return false;
}
float max_tr = max(max(tr.p[0].v[i], tr.p[1].v[i]), tr.p[2].v[i]);
if (min(a.v[i], b.v[i]) > max_tr)
{
return false;
}
}
return true;
}
int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr) int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr)
{ {