diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index b4f18d34..67146770 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -138,9 +138,9 @@ bool C_Object::InitRB(RBInitData RBInit) } void C_Object::updateRBWorld() { - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); - Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->RBposition); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->RBrotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->RBscale); RBworld = translation * rot * scale; } Oyster::Math::Float4x4 C_Object::getRBWorld() const diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 4313b563..b4aee882 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -89,7 +89,9 @@ bool GameState::Init( SharedStateContent &shared ) Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); - gfxOp.AmbientValue = 1.0f; + gfxOp.AmbientValue = 0.5f; + gfxOp.GlobalGlowTint = Math::Float3(2,1,1); + gfxOp.GlobalTint = Math::Float3(1,1,1); Graphics::API::SetOptions(gfxOp); //tell server ready @@ -140,8 +142,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.SetPosition( this->privData->player.getPos() ); Float3 offset = Float3( 0.0f ); // DEBUG position of camera so we can see the player model - offset.y = this->privData->player.getScale().y * 5.0f; - offset.z = this->privData->player.getScale().z * -5.0f; + //offset.y = this->privData->player.getScale().y * 5.0f; + //offset.z = this->privData->player.getScale().z * -5.0f; // !DEBUG this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 848c528a..5b855785 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -79,99 +79,133 @@ void Player::BeginFrame() Oyster::Math::Float maxSpeed = 30; + // Rotate player accordingly + this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); + Oyster::Math::Quaternion firstUp = this->rigidBody->GetState().quaternion; + this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); + Oyster::Math::Quaternion secondTurn = this->rigidBody->GetState().quaternion; + + this->rigidBody->SetRotation(secondTurn*firstUp); + + // Direction data Oyster::Math::Float4x4 xform; xform = this->rigidBody->GetState().GetOrientation(); - /* Handle turning */ - /*if (left) - m_turnAngle -= dt * m_turnVelocity; - if (right) - m_turnAngle += dt * m_turnVelocity; - - xform.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), m_turnAngle));*/ - - Oyster::Math::Float3 linearVelocity = this->rigidBody->GetLinearVelocity(); - Oyster::Math::Float speed = this->rigidBody->GetLinearVelocity().GetLength(); - Oyster::Math::Float3 forwardDir = xform.v[2]; + Oyster::Math::Float3 upDir = xform.v[1]; Oyster::Math::Float3 rightDir = xform.v[0]; forwardDir.Normalize(); + upDir.Normalize(); rightDir.Normalize(); + + // Previous velocities data + Oyster::Math::Float3 linearVelocity = this->rigidBody->GetLinearVelocity(); + Oyster::Math::Float3 forwardVelocity = linearVelocity*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); + Oyster::Math::Float forwardSpeed = (linearVelocity*forwardDir).GetLength(); + Oyster::Math::Float3 rightVelocity = linearVelocity*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); + Oyster::Math::Float rightSpeed = (linearVelocity*rightDir).GetLength(); + Oyster::Math::Float3 upVelocity = linearVelocity*Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); + + // Walking data Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); Oyster::Math::Float walkSpeed = this->moveSpeed*0.2f; - if (key_forward > 0.001) + // Check for input + if(key_forward > 0.001) { key_forward -= gameInstance->GetFrameTime(); walkDirection += forwardDir; - walkDirection.Normalize(); } - if (key_backward > 0.001) + if(key_backward > 0.001) { key_backward -= gameInstance->GetFrameTime(); walkDirection -= forwardDir; - walkDirection.Normalize(); } - if (key_strafeRight > 0.001) + if(key_strafeRight > 0.001) { key_strafeRight -= gameInstance->GetFrameTime(); - walkDirection -= rightDir; - walkDirection.Normalize(); + walkDirection += rightDir; } - if (key_strafeLeft > 0.001) + if(key_strafeLeft > 0.001) { key_strafeLeft -= gameInstance->GetFrameTime(); - walkDirection += rightDir; - walkDirection.Normalize(); - maxSpeed = 40; + walkDirection -= rightDir; } - - if (key_forward <= 0.001 && key_backward <= 0.001 && key_strafeRight <= 0.001 && key_strafeLeft <= 0.001 && key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.7f) + // Dampen velocity if certain keys are not pressed + if(key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.9f) { - /* Dampen when on the ground and not being moved by the player */ - linearVelocity *= 0.2f; - this->rigidBody->SetLinearVelocity (linearVelocity); - } - else - { - if (speed < maxSpeed && this->rigidBody->GetLambda() < 1.0f) + if(key_forward <= 0.001 && key_backward <= 0.001) { - Oyster::Math::Float3 velocity = linearVelocity + walkDirection * walkSpeed; - this->rigidBody->SetLinearVelocity(velocity); + forwardVelocity *= Oyster::Math::Float3(0.2f*fabs(forwardDir.x), 0.2f*fabs(forwardDir.y), 0.2f*fabs(forwardDir.z)); } - else if(speed < maxSpeed) + if(key_strafeRight <= 0.001 && key_strafeLeft <= 0.001) { - Oyster::Math::Float3 velocity = linearVelocity + (walkDirection * walkSpeed)*0.2f; - this->rigidBody->SetLinearVelocity(velocity); + rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); + } + } + + // Walk if walkdirection is something + if(walkDirection != Oyster::Math::Float3::null) + { + walkDirection.Normalize(); + + // If on the ground, accelerate normally + if(this->rigidBody->GetLambda() < 0.9f) + { + if(forwardSpeed < maxSpeed) + { + forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed; + } + if(rightSpeed < maxSpeed) + { + rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), abs(rightDir.y), fabs(rightDir.z)) * walkSpeed; + } + } + // If in the air, accelerate slower + if(this->rigidBody->GetLambda() >= 0.9f) + { + if(forwardSpeed < maxSpeed) + { + forwardVelocity += walkDirection*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)) * walkSpeed*0.2f; + } + if(rightSpeed < maxSpeed) + { + rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; + } } } - if (key_jump > 0.001) + // Adjust velocities so no squaring occurs + forwardVelocity *= Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); + rightVelocity *= Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); + upVelocity *= Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); + + this->rigidBody->SetLinearVelocity(forwardVelocity+rightVelocity+upVelocity); + + //Jump + if(key_jump > 0.001) { this->key_jump -= this->gameInstance->GetFrameTime(); - if(this->rigidBody->GetLambda() < 1.0f) + if(this->rigidBody->GetLambda() < 0.9f) { - Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized(); + Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass*20); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } - Oyster::Math::Float3 pos = this->rigidBody->GetState().centerPos; - if(pos == Oyster::Math::Float3(0,0,0)) - int i =0; + + + //this->weapon->Update(0.01f); } void Player::EndFrame() { - // snap to axis - Oyster::Math::Float4 rotation; - - this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); //Object::EndFrame(); + } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -235,13 +269,10 @@ void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D: // this is the camera right vector this->lookDir = lookDir; - //Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; - //this->rigidBody->SetUpAndRight(up, right); } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { this->rotationUp += deltaRadians; - this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); } void Player::Jump() diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index c9b42c00..f6a6431c 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -62,6 +62,9 @@ namespace Oyster struct PostData { float Amb; + Math::Float3 Tint; + Math::Float3 GlowTint; + float PAD; }; struct Text2D diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 41063265..8f01bea4 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -123,6 +123,8 @@ namespace Oyster Definitions::PostData pd; pd.Amb = option.AmbientValue; + pd.Tint = option.GlobalTint; + pd.GlowTint = option.GlobalGlowTint; void* data = Render::Resources::Post::Data.Map(); memcpy(data,&pd,sizeof(Definitions::PostData)); diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 827f639f..795f649a 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -30,6 +30,9 @@ namespace Oyster //between 0-1 float AmbientValue; + Math::Float3 GlobalTint; + Math::Float3 GlobalGlowTint; + Math::Float2 Resolution; //Bytes on the GPU diff --git a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index af095acf..11447238 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -41,8 +41,8 @@ PixelOut main(VertexOut input) { PixelOut output; float4 DiffGlow = Diffuse.Sample(S1, input.UV); - float3 tint = Color*(1-DiffGlow) + GlowColor * DiffGlow; - tint = tint / 2; + float3 tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; + tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; output.DiffuseGlow = DiffGlow * float4(tint,1); //NORMALIZE diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl index 96b8ab69..89ed06d3 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl @@ -47,7 +47,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) DepthBase = DepthBase /4; Ambient[DTid.xy/2] = float4(DiffBase.xyz, AmbValue); Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy]; - Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffBase.xyz * DiffBase.w * 10 /* * (2-DepthBase) */,1); + Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffBase.xyz * DiffBase.w /* * (2-DepthBase) */,DiffBase.w); Ambient[DTid.xy/2 + Pixels/2] = float4(NormalSpec[DTid.xy].xyz * float3(1,1,-1),1); } diff --git a/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli b/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli index f2258905..c71cb4d5 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli @@ -1,7 +1,7 @@ #include "Defines.hlsli" #include "PosManipulation.hlsli" -static float Radius = 10; +static float Radius = 1; float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) { diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 258d0f25..f7721d38 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -9,6 +9,8 @@ SamplerState S1 : register(s0); cbuffer Size : register(b0) { float AmbFactor; + float3 Color; + float3 GlowColor; } [numthreads(16, 16, 1)] @@ -26,9 +28,10 @@ void main( uint3 DTid : SV_DispatchThreadID ) SSAO = SSAO / 16; float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); - float3 Amb = Ambient[DTid.xy/2].xyz * SSAO; + float3 Amb = Ambient[DTid.xy/2].xyz * SSAO * Color; - float3 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)].xyz; + float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; + Glow = float4(Glow.xyz * GlowColor, 1); float4 GUI; uint2 index = DTid.xy/2 + uint2((uint)Output.Length.x/(uint)2,0); diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index ef003d7f..018c3be0 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -168,9 +168,15 @@ void SimpleRigidBody::SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxi return; } + float s = sin(angularAxis.w/2); + float x = angularAxis.x * s; + float y = angularAxis.y * s; + float z = angularAxis.z * s; + float w = cos(angularAxis.w/2); + btTransform trans; btVector3 vector(angularAxis.x, angularAxis.y, angularAxis.z); - btQuaternion quaternion(vector, angularAxis.w); + btQuaternion quaternion(x,y,z,w); trans = this->rigidBody->getWorldTransform(); trans.setRotation(quaternion); @@ -263,22 +269,11 @@ Float4x4 SimpleRigidBody::GetRotation() const Float4 SimpleRigidBody::GetRotationAsAngularAxis() { Float4 axis = Float4::null; - Float s = sqrtf(1 - this->state.quaternion.real*this->state.quaternion.real); + btTransform trans; - axis.w = 2*acos(this->state.quaternion.real*this->state.quaternion.real); - - if(1 - this->state.quaternion.real > 0.001f) - { - axis.x = this->state.quaternion.imaginary.x/s; - axis.y = this->state.quaternion.imaginary.y/s; - axis.z = this->state.quaternion.imaginary.z/s; - } - else - { - axis.x = this->state.quaternion.imaginary.x; - axis.y = this->state.quaternion.imaginary.y; - axis.z = this->state.quaternion.imaginary.z; - } + trans = this->rigidBody->getWorldTransform(); + axis.xyz = trans.getRotation().getAxis(); + axis.w = trans.getRotation().getAngle(); return axis; } @@ -353,7 +348,8 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) { btTransform xform; xform = this->rigidBody->getWorldTransform (); - btVector3 down = -xform.getBasis()[1]; + Float3 normalDown = -this->state.centerPos.GetNormalized(); + btVector3 down(normalDown.x, normalDown.y, normalDown.z); btVector3 forward = xform.getBasis()[2]; down.normalize (); forward.normalize(); @@ -361,12 +357,17 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) this->raySource[0] = xform.getOrigin(); this->raySource[1] = xform.getOrigin(); + if(this->state.reach.y < 1.0f) + + Float angle = acos(Float3(0, 1, 0).Dot(this->state.centerPos.GetNormalized())); - down.setZ(-down.z()); - down.setX(-down.x()); + //down.setZ(-down.z()); btVector3 targetPlus = down * this->state.reach.y * btScalar(1.1); - + if(this->state.mass == 40) + { + const char* breakpoint = "STOP"; + } this->rayTarget[0] = this->raySource[0] + targetPlus; this->rayTarget[1] = this->raySource[1] + forward * this->state.reach.y * btScalar(1.1); @@ -383,7 +384,6 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) { if (rayResult.m_collisionObject == m_me) return 1.0; - return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace); } protected: