Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameServer

This commit is contained in:
dean11 2014-02-18 13:12:33 +01:00
commit c89ec7bbcd
12 changed files with 440 additions and 19 deletions

View File

@ -201,7 +201,9 @@
<ClCompile Include="DanBiasGame_Impl.cpp" />
<ClCompile Include="GameClientState\Camera_Basic.cpp" />
<ClCompile Include="GameClientState\Camera.cpp" />
<ClCompile Include="GameClientState\Camera_BasicV2.cpp" />
<ClCompile Include="GameClientState\Camera_FPS.cpp" />
<ClCompile Include="GameClientState\Camera_FPSV2.cpp" />
<ClCompile Include="GameClientState\C_obj\C_DynamicObj.cpp" />
<ClCompile Include="GameClientState\C_obj\C_Player.cpp" />
<ClCompile Include="GameClientState\C_obj\C_StaticObj.cpp" />
@ -226,7 +228,9 @@
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
<ClInclude Include="GameClientState\Camera.h" />
<ClInclude Include="GameClientState\Camera_BasicV2.h" />
<ClInclude Include="GameClientState\Camera_FPS.h" />
<ClInclude Include="GameClientState\Camera_FPSV2.h" />
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
<ClInclude Include="GameClientState\C_obj\C_Player.h" />
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />

View File

@ -0,0 +1,117 @@
#include "Camera_BasicV2.h"
using namespace ::Oyster::Math3D;
Camera_BasicV2::Camera_BasicV2()
{
this->translation = Float3::null;
this->rotation = Quaternion::identity;
this->projection = Float4x4::identity;
}
Camera_BasicV2::Camera_BasicV2( const Float3 &position, const Quaternion &rotation, const Float4x4 &projection )
{
this->translation = position;
this->rotation = rotation;
this->projection = projection;
}
Camera_BasicV2::~Camera_BasicV2() {}
Camera_BasicV2 & Camera_BasicV2::operator = ( const Camera_BasicV2 &camera )
{
this->translation = camera.translation;
this->rotation = camera.rotation;
this->projection = camera.projection;
return *this;
}
void Camera_BasicV2::SetPosition( const Float3 &translation )
{
this->translation = translation;
}
void Camera_BasicV2::SetRotation( const Quaternion &rotation )
{
this->rotation = rotation;
}
void Camera_BasicV2::SetAngular( const Float3 &axis )
{
this->rotation = Rotation( axis );
}
void Camera_BasicV2::SetProjection( const Float4x4 &matrix )
{
this->projection = matrix;
}
void Camera_BasicV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip )
{
ProjectionMatrix_Orthographic( width, height, nearClip, farClip, this->projection );
}
void Camera_BasicV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip )
{
ProjectionMatrix_Perspective( verticalFoV, aspectRatio, nearClip, farClip, this->projection );
}
void Camera_BasicV2::Move( const Float3 &deltaPosition )
{
this->translation += deltaPosition;
}
void Camera_BasicV2::Rotate( const Quaternion &deltaRotation )
{
this->rotation *= deltaRotation;
}
void Camera_BasicV2::Rotate( const Float3 &deltaAngularAxis )
{
this->rotation *= Rotation( deltaAngularAxis );
}
const Float3 & Camera_BasicV2::GetPosition() const
{
return this->translation;
}
Float3 & Camera_BasicV2::GetAngularAxis( Float3 &targetMem ) const
{
return targetMem = AngularAxis( this->rotation );
}
Float3 Camera_BasicV2::GetNormalOf( const Float3 &axis ) const
{
return WorldAxisOf( this->rotation, axis );
}
const Quaternion & Camera_BasicV2::GetRotation() const
{
return this->rotation;
}
Float3x3 & Camera_BasicV2::GetRotationMatrix( Float3x3 &targetMem ) const
{
return RotationMatrix( this->rotation, targetMem );
}
Float4x4 & Camera_BasicV2::GetRotationMatrix( Float4x4 &targetMem ) const
{
return RotationMatrix( this->rotation, targetMem );
}
Float4x4 & Camera_BasicV2::GetViewMatrix( Float4x4 &targetMem ) const
{
return ViewMatrix( this->rotation, this->translation, targetMem );
}
const Float4x4 & Camera_BasicV2::GetProjectionMatrix() const
{
return this->projection;
}
Float4x4 & Camera_BasicV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
{
return TransformMatrix( this->projection, this->GetViewMatrix(), targetMem );
}

View File

@ -0,0 +1,42 @@
#ifndef CAMERA_BASIC_V2_H
#define CAMERA_BASIC_V2_H
#include "OysterMath.h"
class Camera_BasicV2
{
public:
Camera_BasicV2();
Camera_BasicV2( const ::Oyster::Math::Float3 &position, const ::Oyster::Math::Quaternion &rotation, const ::Oyster::Math::Float4x4 &projection );
virtual ~Camera_BasicV2();
Camera_BasicV2 & operator = ( const Camera_BasicV2 &camera );
void SetPosition( const ::Oyster::Math::Float3 &translation );
void SetRotation( const ::Oyster::Math::Quaternion &rotation );
void SetAngular( const ::Oyster::Math::Float3 &axis );
void SetProjection( const ::Oyster::Math::Float4x4 &matrix );
void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
void Move( const ::Oyster::Math::Float3 &deltaPosition );
void Rotate( const ::Oyster::Math::Quaternion &deltaRotation );
void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis );
const ::Oyster::Math::Float3 & GetPosition() const;
::Oyster::Math::Float3 & GetAngularAxis( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const;
const ::Oyster::Math::Quaternion & GetRotation() const;
::Oyster::Math::Float3x3 & GetRotationMatrix( ::Oyster::Math::Float3x3 &targetMem ) const;
::Oyster::Math::Float4x4 & GetRotationMatrix( ::Oyster::Math::Float4x4 &targetMem ) const;
::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const;
::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
private:
::Oyster::Math::Float3 translation;
mutable ::Oyster::Math::Quaternion rotation;
::Oyster::Math::Float4x4 projection;
};
#endif

View File

@ -0,0 +1,182 @@
#include "Camera_FPSV2.h"
#include "Utilities.h"
using namespace ::Oyster::Math3D;
using namespace ::Utility::Value;
Camera_FPSV2::Camera_FPSV2()
{ // this->head is default set to identity uniformprojection at origo
this->pitchUp = 0.0f;
this->headOffset =
this->body.translation = Float3::null;
this->body.rotation = Quaternion::identity;
}
Camera_FPSV2::~Camera_FPSV2() {}
Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera )
{
this->head = camera.head;
this->pitchUp = camera.pitchUp;
this->headOffset = camera.headOffset;
this->body.translation = camera.body.translation;
this->body.rotation = camera.body.rotation;
return *this;
}
void Camera_FPSV2::SetHeadOffset( const Float3 &translation )
{
this->head.Move( translation - this->headOffset );
this->headOffset = translation;
}
void Camera_FPSV2::SetPosition( const Float3 &translation )
{
this->head.Move( translation - this->body.translation );
this->body.translation = translation;
}
void Camera_FPSV2::SetAngular( const Float3 &axis )
{
this->body.rotation = Rotation( axis );
this->head.SetRotation( this->body.rotation );
this->pitchUp = 0.0f;
}
void Camera_FPSV2::SetProjection( const Float4x4 &matrix )
{
this->head.SetProjection( matrix );
}
void Camera_FPSV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip )
{
this->head.SetOrthographicProjection( width, height, nearClip, farClip );
}
void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip )
{
this->head.SetPerspectiveProjection( verticalFoV, aspectRatio, nearClip, farClip );
}
void Camera_FPSV2::UpdateOrientation()
{
Float4x4 orientation;
OrientationMatrix( this->body.rotation, this->body.translation, orientation );
this->head.SetPosition( (orientation * Float4(this->headOffset, 1.0f)).xyz );
}
void Camera_FPSV2::SnapUpToNormal( const Float3 &normal )
{
this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) );
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) );
}
void Camera_FPSV2::Move( const Float3 &deltaPosition )
{
this->head.Move( deltaPosition );
this->body.translation += deltaPosition;
}
void Camera_FPSV2::Rotate( const Quaternion &deltaRotation )
{
this->head.Rotate( deltaRotation );
this->body.rotation *= deltaRotation;
}
void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis )
{
this->Rotate( Rotation(deltaAngularAxis) );
}
void Camera_FPSV2::MoveForward( Float distance )
{
this->MoveBackward( -distance );
}
void Camera_FPSV2::MoveBackward( Float distance )
{
this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_z) );
}
void Camera_FPSV2::StrafeRight( Float distance )
{
this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_x) );
}
void Camera_FPSV2::StrafeLeft( Float distance )
{
this->StrafeRight( -distance );
}
void Camera_FPSV2::PitchUp( Float radian )
{
this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi );
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) );
}
void Camera_FPSV2::PitchDown( Float radian )
{
this->PitchUp( -radian );
}
void Camera_FPSV2::YawRight( Float radian )
{
this->YawLeft( -radian );
}
void Camera_FPSV2::YawLeft( Float radian )
{
Quaternion deltaRotation = Rotation( radian, WorldAxisOf(this->body.rotation, Float3::standard_unit_y) );
this->Rotate( deltaRotation );
}
const Float3 & Camera_FPSV2::GetHeadOffset() const
{
return this->headOffset;
}
const Float3 & Camera_FPSV2::GetPosition() const
{
return this->body.translation;
}
Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const
{
return this->head.GetViewMatrix( targetMem );
}
const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const
{
return this->head.GetProjectionMatrix();
}
Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
{
return this->head.GetViewsProjMatrix( targetMem );
}
Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const
{
return this->head.GetNormalOf( axis );
}
Float3 Camera_FPSV2::GetRight() const
{
return WorldAxisOf( this->body.rotation, Float3::standard_unit_x );
}
Float3 Camera_FPSV2::GetUp() const
{
return WorldAxisOf( this->body.rotation, Float3::standard_unit_y );
}
Float3 Camera_FPSV2::GetLook() const
{
return this->head.GetNormalOf( -Float3::standard_unit_z );
}
Float3 Camera_FPSV2::GetForward() const
{
return WorldAxisOf( this->body.rotation, -Float3::standard_unit_z );
}

View File

@ -0,0 +1,62 @@
#ifndef CAMERA_FPSV2_H
#define CAMERA_FPSV2_H
#include "OysterMath.h"
#include "Camera_BasicV2.h"
class Camera_FPSV2
{
public:
Camera_FPSV2();
virtual ~Camera_FPSV2();
Camera_FPSV2 & operator = ( const Camera_FPSV2 &camera );
void SetHeadOffset( const ::Oyster::Math::Float3 &translation );
void SetPosition( const ::Oyster::Math::Float3 &translation );
void SetAngular( const ::Oyster::Math::Float3 &axis );
void SetProjection( const ::Oyster::Math::Float4x4 &matrix );
void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip );
void UpdateOrientation();
void SnapUpToNormal( const ::Oyster::Math::Float3 &normal );
void Move( const ::Oyster::Math::Float3 &deltaPosition );
void Rotate( const ::Oyster::Math::Quaternion &deltaRotation );
void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis );
void MoveForward( ::Oyster::Math::Float distance );
void MoveBackward( ::Oyster::Math::Float distance );
void StrafeRight( ::Oyster::Math::Float distance );
void StrafeLeft( ::Oyster::Math::Float distance );
void PitchUp( ::Oyster::Math::Float radian );
void PitchDown( ::Oyster::Math::Float radian );
void YawRight( ::Oyster::Math::Float radian );
void YawLeft( ::Oyster::Math::Float radian );
const ::Oyster::Math::Float3 & GetHeadOffset() const;
const ::Oyster::Math::Float3 & GetPosition() const;
::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const;
::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const;
::Oyster::Math::Float3 GetRight() const;
::Oyster::Math::Float3 GetUp() const;
::Oyster::Math::Float3 GetLook() const;
::Oyster::Math::Float3 GetForward() const;
private:
Camera_BasicV2 head;
::Oyster::Math::Float pitchUp;
::Oyster::Math::Float3 headOffset;
struct
{
::Oyster::Math::Float3 translation;
::Oyster::Math::Quaternion rotation;
} body;
};
#endif

View File

@ -36,6 +36,8 @@ struct GameState::MyData
bool key_Shoot;
bool key_Jump;
bool key_Reload_Shaders;
C_Player player;
Camera_FPS camera;
@ -83,11 +85,7 @@ bool GameState::Init( SharedStateContent &shared )
Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() );
//tell server ready
//this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
// Debugg hack
this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true );
// end debug hack
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
return true;
}
@ -109,7 +107,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
this->privData->myId = id;
this->privData->camera.SetPosition( this->privData->player.getPos() );
Float3 offset = Float3( 0.0f );
offset.y = this->privData->player.getScale().y + 0.5f; // debug hack +0.5f
offset.y = this->privData->player.getScale().y * 0.9f;
this->privData->camera.SetHeadOffset( offset );
this->privData->camera.UpdateOrientation();
}
@ -230,6 +228,20 @@ void GameState::ReadKeyInput()
else
this->privData->key_strafeRight = false;
if( this->privData->input->IsKeyPressed(DIK_R) )
{
if( !this->privData->key_Reload_Shaders )
{
//this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
#ifdef _DEBUG
Graphics::API::ReloadShaders();
#endif
this->privData->key_Reload_Shaders = true;
}
}
else
this->privData->key_Reload_Shaders = false;
//send delta mouse movement
{

View File

@ -54,11 +54,8 @@ bool NetLoadState::Init( SharedStateContent &shared )
// we may assume that nwClient is properly connected to the server
// signals querry to server for loading instructions
//this->privData->nwClient->Send( Protocol_QuerryGameType() );
this->privData->nwClient->Send( Protocol_QuerryGameType() );
// debugg
this->LoadGame( "..//Content//Worlds//2ofAll_updated.bias");
this->ChangeState( ClientState_Game );
return true;
}

View File

@ -36,6 +36,7 @@ namespace LinearAlgebra
const ScalarType & operator [] ( int i ) const;
Quaternion<ScalarType> & operator = ( const Quaternion<ScalarType> &quaternion );
Quaternion<ScalarType> & operator *= ( const Quaternion<ScalarType> &quaternion );
Quaternion<ScalarType> & operator *= ( const ScalarType &scalar );
Quaternion<ScalarType> & operator /= ( const ScalarType &scalar );
Quaternion<ScalarType> & operator += ( const Quaternion<ScalarType> &quaternion );
@ -112,6 +113,12 @@ namespace LinearAlgebra
return *this;
}
template<typename ScalarType>
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const Quaternion<ScalarType> &quaternion )
{
return *this = *this * quaternion;
}
template<typename ScalarType>
Quaternion<ScalarType> & Quaternion<ScalarType>::operator *= ( const ScalarType &scalar )
{

View File

@ -160,7 +160,7 @@ namespace Oyster
D3D11_RASTERIZER_DESC rdesc;
rdesc.CullMode = D3D11_CULL_BACK;
rdesc.FillMode = D3D11_FILL_SOLID;
rdesc.FrontCounterClockwise = false;
rdesc.FrontCounterClockwise = true;
rdesc.DepthBias = 0;
rdesc.DepthBiasClamp = 0;
rdesc.DepthClipEnable = true;

View File

@ -27,7 +27,7 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
blurCol +=Weights[i + blurRadius] * gCache[k];
}
outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);
outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask);
//outTex[ThreadID.xy + Start] = inTex[ThreadID.xy + Start];
}

View File

@ -14,7 +14,7 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
int y = min(ThreadID.y +blurRadius, Stop.y-1);
gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start];
}
gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)];
gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)];
GroupMemoryBarrierWithGroupSync();
@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
blurCol +=Weights[i + blurRadius] * gCache[k];
}
outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);;
outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask);;
//outTex[ThreadID.xy + Start] = inTex[ThreadID.xy+ Start];
}

View File

@ -18,7 +18,7 @@ float4 SuperSample(float4 Glow, uint3 DTid)
index += float2(0,Output.Length.y/2);
index = index / Output.Length;
Glow = Ambient.SampleLevel(S1, index,1);
Glow = Glow * Glow.w*10;
Glow = Glow;
return Glow;
}
@ -28,11 +28,8 @@ void main( uint3 DTid : SV_DispatchThreadID )
{
float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]);
float4 Amb = float4(Ambient[DTid.xy/2].xyz /* * Ambient[DTid.xy/2].w*/, 0);
//float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)];
float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)];
Glow = SuperSample(Glow,DTid);
float4 GUI;
uint2 index = DTid.xy/2 + uint2((uint)Output.Length.x/(uint)2,0);
float3 PostLight = Amb.xyz * AmbFactor;
@ -42,4 +39,5 @@ void main( uint3 DTid : SV_DispatchThreadID )
Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1);
//Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(0,Output.Length.y*0.5f)].xyz,1);
//Output[DTid.xy] = Ambient[DTid.xy];
}