Commit 4640cccb authored by AL's avatar AL

some success in implementing 3d effects

parent 4f581e65
#include "CameraManager.h"
#include "Framework\ChiliMath.h"
#include "Skills0.h"
CameraManager::CameraManager():
baseTrans({0.0f,PI/2.0f,0.0f,1.0f,1.0f,1.0f})
......@@ -22,8 +23,8 @@ void CameraManager::Update(float dt)
case Scenario:: ThrowSand:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ 0.1f,0.15f,0.0f }, { 0.0f,0.0f,0.0f }, 0.5f));
cs.push(std::make_tuple<CamTilt, CamMove, float>({ -0.3f,-0.6f,0.0f }, { 0.0f,0.0f,0.0f }, 0.15f));
cs.push(std::tuple<CamTilt, CamMove, float>({ 0.1f,0.15f,0.0f }, { 0.0f,0.0f,0.0f }, DustThrow::step0));
cs.push(std::tuple<CamTilt, CamMove, float>({ -0.3f,-0.6f,0.0f }, { 0.0f,0.0f,0.0f }, DustThrow::step1));
scenarious.emplace_back(cs);
break;
}
......@@ -31,8 +32,8 @@ void CameraManager::Update(float dt)
case Scenario::UnsettleDust:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ 0.2f,0.0f,0.0f }, { 0.0f,-0.4f,0.0f }, 0.7f));
cs.push(std::make_tuple<CamTilt, CamMove, float>({ -0.1f,-0.0f,0.0f }, { 0.0f,0.0f,0.0f }, 0.5f));
cs.push(std::tuple<CamTilt, CamMove, float>({ 0.2f,0.0f,0.0f }, { 0.0f,-0.4f,0.0f }, SandStorm::step0));
cs.push(std::tuple<CamTilt, CamMove, float>({ -0.1f,-0.0f,0.0f }, { 0.0f,0.0f,0.0f }, SandStorm::step1));
scenarious.emplace_back(cs);
break;
}
......@@ -40,7 +41,8 @@ void CameraManager::Update(float dt)
case Scenario::Strike:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ -0.2f,-2.9f,0.0f }, { 0.0f, 0.0f, 0.0f }, 0.06f));
cs.push(std::tuple<CamTilt, CamMove, float>({ 0.0f,0.2f,0.0f }, { 0.0f, 0.0f, 0.0f }, Cut::step0));
cs.push(std::tuple<CamTilt, CamMove, float>({ -0.0f,-2.0f,0.0f }, { 0.0f, 0.0f, 0.0f }, Cut::step1));
scenarious.emplace_back(cs);
break;
}
......@@ -48,7 +50,7 @@ void CameraManager::Update(float dt)
case Scenario::Defend:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ 0.0f,0.2f,0.0f }, { -0.3f,0.0f,0.0f }, 0.7f));
cs.push(std::tuple<CamTilt, CamMove, float>({ 0.0f,0.2f,0.0f }, { -0.3f,0.0f,0.0f }, Deflect::step0));
scenarious.emplace_back(cs);
break;
}
......
......@@ -42,7 +42,7 @@ private:
CamTrans intermedTrans;
CamTrans curTrans;
//CamTrans targetTrans;
float speedCoeff = 5.0f;
float speedCoeff = 10.0f;
Camera cam;
std::vector<CameraScenario> scenarious;
static std::vector<Scenario> pendingScenarios;
......
......@@ -116,7 +116,10 @@ int CombatManager::ProcessInput(Keyboard::Event in_event) //why does it return
EndBattle();
}
if (in_event.GetCode() == 'G') //for testing
{
EH::AddEffect3D(EH::Effect::GhoulAttack);
}
if (in_event.GetCode() == 'T') //for testing
{
CM::PendScenario(CM::Scenario::ThrowSand);
......
......@@ -2,12 +2,18 @@
#include "Framework/BindableCommon.h"
#include "Framework/TransformCbuf2D.h"
Effect2DData EffectDataInterpolate(Effect2DData e1, Effect2DData e2, float progress)
Effect2DData Effect2DDataInterpolate(Effect2DData e1, Effect2DData e2, float progress)
{
return Effect2DData(e1*(1.0f-progress)+e2*progress);
}
HudEffect::HudEffect(DXGraphics& gfx, Effect2DSequence data, std::wstring spriteName) :effectSequence(data), gfx(gfx)
Effect3DData Effect3DDataInterpolate(Effect3DData e1, Effect3DData e2, float progress)
{
return Effect3DData(e1 * (1.0f - progress) + e2 * progress);
}
HudEffect<Effect2DSequence,HudElement>::HudEffect(DXGraphics& gfx, Effect2DSequence data, std::wstring spriteName) :effectSequence(data), gfx(gfx)
{
using namespace Bind;
namespace dx = DirectX;
......@@ -73,7 +79,18 @@ HudEffect::HudEffect(DXGraphics& gfx, Effect2DSequence data, std::wstring sprite
refPosData.emplace_back();
}
HudEffect::HudEffect(HudEffect&& mvFrom):
HudEffect<Effect3DSequence, PlaneTexNorm>::HudEffect(DXGraphics& gfx, Effect3DSequence data, std::wstring spriteName) :
PlaneTexNorm(spriteName, gfx),effectSequence(data), gfx(gfx)
{
BindPositionData(&refPosData);
BindAdditionalData(&refAddData);
refAddData.emplace_back( 1.0f,1.0f,1.0f, 1.0f );
refPosData.emplace_back();
}
template<typename T, typename Base>
HudEffect<T,Base>::HudEffect(HudEffect&& mvFrom):
HudElement(std::move(mvFrom)),
cbData (std::move(mvFrom.cbData)),
refPosData (std::move(mvFrom.refPosData)),
......@@ -81,7 +98,18 @@ cbuf (std::move(mvFrom.cbuf )),
effectSequence (std::move(mvFrom.effectSequence)),
gfx (std::move(mvFrom.gfx)){}
bool HudEffect::UpdateData(float dt)
HudEffect<Effect3DSequence, PlaneTexNorm>::HudEffect(HudEffect&& mvFrom) :
PlaneTexNorm(std::move(mvFrom)),
cbData(std::move(mvFrom.cbData)),
refPosData(std::move(mvFrom.refPosData)),
cbuf(std::move(mvFrom.cbuf)),
effectSequence(std::move(mvFrom.effectSequence)),
gfx(std::move(mvFrom.gfx)) {}
bool HudEffect<Effect2DSequence, HudElement>::UpdateData(float dt)
{
auto nd = effectSequence.Update(dt);
if (nd.has_value())
......@@ -97,6 +125,24 @@ bool HudEffect::UpdateData(float dt)
else return 1;
}
bool HudEffect<Effect3DSequence, PlaneTexNorm>::UpdateData(float dt)
{
auto nd = effectSequence.Update(dt);
if (nd.has_value())
{
refPosData[0].pos.x = nd->posX;
refPosData[0].pos.y = nd->posY;
refPosData[0].pos.z = nd->posZ;
refPosData[0].rot.x = nd->roll;
refPosData[0].rot.y = nd->pitch;
refPosData[0].rot.z = nd->yaw;
//cbData.fillness = nd->opacity;
//cbuf->Update(gfx, cbData);
return 0;
}
else return 1;
}
EffectHandler::EffectHandler(DXGraphics& gfx)
{
EffectHandler::gfx = &gfx;
......@@ -104,7 +150,7 @@ EffectHandler::EffectHandler(DXGraphics& gfx)
void EffectHandler::AddEffect2D(Effect2DSequence data, std::wstring spriteName)
{
e2d.push_back(std::make_unique<HudEffect>(*gfx, data, spriteName));
e2d.push_back(std::make_unique<HudEffect<Effect2DSequence, HudElement>>(*gfx, data, spriteName));
}
void EffectHandler::AddEffect2D(PositionData posData,Effect e)
......@@ -206,28 +252,46 @@ void EffectHandler::AddEffect2D(Effect e)
}
break;
}
}
}
void EffectHandler::AddEffect3D(Effect3DSequence data, std::wstring spriteName)
{
e3d.push_back(std::make_unique<HudEffect<Effect3DSequence, PlaneTexNorm>>(*gfx, data, spriteName));
}
void EffectHandler::AddEffect3D(PositionData posData, Effect e)
{
}
void EffectHandler::AddEffect3D(Effect e)
{
switch (e)
{
case Effect::GhoulAttack: //is called from switch on enemyState in LevelLayout
{
PositionData posData = { 0.05f, -0.1f, 0.6f };
Effect2DSequence e2ds1;
e2ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z * 1.0f, 0.8f }, 0.65f);
e2ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z * 1.5f, 0.0f }, 0.0f);
EffectHandler::AddEffect2D(e2ds1, L"Media\\Sprites\\Enemy_hitSprite.png");
PositionData posData = { 3.3f, -0.1f, 0.6f, 0.0f,0.0f,0.0f };
Effect3DSequence e3ds1;
e3ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z * 1.0f, 0.8f }, 10.65f);
e3ds1.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z * 1.5f, 0.0f }, 0.0f);
EffectHandler::AddEffect3D(e3ds1, L"Media\\Models\\Enemy_hit.obj");
Effect2DSequence e2ds2;
e2ds2.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z, 1.0f }, 1.0f);
e2ds2.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z, 1.0f }, 0.0f);
EffectHandler::AddEffect2D(e2ds2, L"Media\\Sprites\\Enemy_hitSprite.png");
Effect3DSequence e3ds2;
e3ds2.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z, 1.0f }, 11.0f);
e3ds2.AddStage({ posData.pos.x,posData.pos.y,posData.pos.z, 1.0f }, 0.0f);
EffectHandler::AddEffect3D(e3ds2, L"Media\\Models\\Enemy_hit.obj");
break;
}
}
}
void EffectHandler::SubmitAndUpdate(FrameCommander& fc, float dt)
{
e2d.erase(std::remove_if(e2d.begin(), e2d.end(), [dt](std::unique_ptr<HudEffect>& o) {return o->UpdateData(dt); }),e2d.end());
e2d.erase(std::remove_if(e2d.begin(), e2d.end(), [dt](std::unique_ptr<HudEffect<Effect2DSequence, HudElement>>& o) {return o->UpdateData(dt); }),e2d.end());
for (const auto& e : e2d)e->SmartSubmit(fc);
e3d.erase(std::remove_if(e3d.begin(), e3d.end(), [dt](std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>& o) {return o->UpdateData(dt); }), e3d.end());
for (const auto& e : e3d)e->SmartSubmit(fc,Techniques::CamFacingEX);
for (auto& e : e2df)
{
e->SubmitAndUpdateParticles(fc, dt);
......@@ -242,7 +306,7 @@ std::optional<Effect2DData> Effect2DSequence::Update(float dt) //make friend
{
if (currentStageTime < stageTimes[0u])
{
return std::optional<Effect2DData>(EffectDataInterpolate(stages[0u], stages[1u], currentStageTime / stageTimes[0u]));
return std::optional<Effect2DData>(Effect2DDataInterpolate(stages[0u], stages[1u], currentStageTime / stageTimes[0u]));
}
else
{
......@@ -297,6 +361,26 @@ void Effect2DPhysics::SubmitAndUpdateParticles(FrameCommander& fc, float dt)
}
}
std::vector<std::unique_ptr<HudEffect>> EffectHandler::e2d;
std::vector<std::unique_ptr<HudEffect<Effect2DSequence,HudElement>>> EffectHandler::e2d;
std::vector<std::unique_ptr<HudEffect<Effect3DSequence, PlaneTexNorm>>> EffectHandler::e3d;
std::vector<std::unique_ptr<Effect2DPhysics>> EffectHandler::e2df;
DXGraphics* EffectHandler::gfx;
\ No newline at end of file
DXGraphics* EffectHandler::gfx;
std::optional<Effect3DData> Effect3DSequence::Update(float dt)
{
currentStageTime += dt;
for (;;)
{
if (currentStageTime < stageTimes[0u])
{
return std::optional<Effect3DData>(Effect3DDataInterpolate(stages[0u], stages[1u], currentStageTime / stageTimes[0u]));
}
else
{
currentStageTime -= stageTimes[0u];
stages.erase(stages.begin());
stageTimes.erase(stageTimes.begin());
if (stageTimes.size() == 1u) return std::optional<Effect3DData>(); //no more data to interpolate, the effect has done its job
}
}
}
......@@ -3,6 +3,7 @@
#include "Framework\HudElement.h"
#include "Framework\FrameCommander.h"
#include "RandomUnit.h"
#include "Framework\PlaneTexNorm.h"
struct Effect2DData
{
Effect2DData(float pX, float pY, float scale = 1.0f, float opacity = 1.0f,float rotation = 0.0f) : posX(pX), posY(pY), scale(scale), opacity(opacity),rotation(rotation) {}
......@@ -23,9 +24,38 @@ struct Effect2DData
float rotation;
};
struct Effect3DData
{
Effect3DData(float pX, float pY,float pZ, float scale = 1.0f, float opacity = 1.0f, float roll = 0.0f, float pitch = 0.0f, float yaw = 0.0f) :
posX(pX), posY(pY),posZ(pZ), scale(scale), opacity(opacity),roll(roll),pitch(pitch),yaw(yaw) {}
Effect3DData operator*(float f)
{
Effect3DData e3d(posX * f, posY * f, posZ * f, scale * f, opacity * f, roll * f, pitch * f, yaw * f);
return e3d;
}
Effect3DData operator+(Effect3DData in)
{
Effect3DData e3d(posX + in.posX, posY + in.posY, posZ + in.posZ, scale + in.scale, opacity + in.opacity, roll + in.roll, pitch + in.pitch, yaw + in.yaw);
return e3d;
}
float posX;
float posY;
float posZ;
float scale;
float opacity;
float roll;
float pitch;
float yaw;
};
#ifndef EFFECT2DDATAINTERPOL
#define EFFECT2DDATAINTERPOL
Effect2DData EffectDataInterpolate(Effect2DData e1, Effect2DData e2, float progress);
Effect2DData Effect2DDataInterpolate(Effect2DData e1, Effect2DData e2, float progress);
#endif
#ifndef EFFECT3DDATAINTERPOL
#define EFFECT3DDATAINTERPOL
Effect3DData Effect3DDataInterpolate(Effect3DData e1, Effect3DData e2, float progress);
#endif
class Effect2DSequence //sequence of Effect2DData
......@@ -41,6 +71,21 @@ private:
float currentStageTime = 0.0f;
};
class Effect3DSequence
{
public:
Effect3DSequence() = default; //thisobject must be constructed manually due to undefined number of arguments (and my incompetence in handling such things with template metagrogramming)
void AddStage(Effect3DData e3d, float time) //time is the time of iterplation from this stage to the next one. for last stage time is supposed to be 0;
{
stages.push_back(e3d); stageTimes.push_back(time);
}
std::optional<Effect3DData> Update(float dt);
private:
std::vector<Effect3DData> stages;
std::vector<float>stageTimes;
float currentStageTime = 0.0f;
};
class Effect2DPhysics //Effect2DData, transformed according gravity
{
public:
......@@ -58,10 +103,11 @@ private:
static constexpr float partScale = 0.025f;
};
class HudEffect : public HudElement
template<typename T, typename Base>
class HudEffect : public Base
{
public:
HudEffect(DXGraphics& gfx, Effect2DSequence data, std::wstring spriteName);
HudEffect(DXGraphics& gfx, T data, std::wstring spriteName);
HudEffect(HudEffect&&);
HudEffect(const HudEffect&) = delete;
HudEffect& operator = (HudEffect&&) = default;
......@@ -77,8 +123,9 @@ private:
};
EffectCBuff cbData;
std::vector<PositionData> refPosData;
std::vector<DirectX::XMFLOAT4> refAddData;
std::shared_ptr <Bind::PixelConstantBuffer<EffectCBuff>> cbuf;
Effect2DSequence effectSequence;
T effectSequence;
DXGraphics& gfx;
};
#define EH EffectHandler
......@@ -101,10 +148,15 @@ public:
static void AddEffect2D(Effect2DSequence data, std::wstring spriteName);
static void AddEffect2D(PositionData posData, Effect e);
static void AddEffect2D(Effect e); //for effects that are always in the same location
static void AddEffect3D(Effect3DSequence data, std::wstring spriteName);
static void AddEffect3D(PositionData posData, Effect e);
static void AddEffect3D(Effect e); //for effects that are always in the same location
void SubmitAndUpdate(FrameCommander& fc, float dt); //can be made a friend
private:
static std::vector<std::unique_ptr<HudEffect>> e2d; //uses pointers because HudElement cant be copied
static std::vector<std::unique_ptr<HudEffect<Effect2DSequence,HudElement>>> e2d; //uses pointers because HudElement cant be copied
static std::vector<std::unique_ptr<Effect2DPhysics>> e2df;
static std::vector<std::unique_ptr<HudEffect<Effect3DSequence,PlaneTexNorm>>> e3d; //uses pointers because HudElement cant be copied
static DXGraphics* gfx;
};
......
......@@ -463,6 +463,7 @@
<ClCompile Include="RewardMenu.cpp" />
<ClCompile Include="SceneLight.cpp" />
<ClCompile Include="SkillMicroicons.cpp" />
<ClCompile Include="Skills0.cpp" />
<ClCompile Include="StatusBar.cpp" />
<ClCompile Include="RandomBoxManager.cpp" />
<ClCompile Include="RandomUnit.cpp" />
......
......@@ -890,6 +890,12 @@
<ClCompile Include="CameraManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Skills0.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Framework\PlaneTex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="PhongVSNormalMap.hlsl">
......
......@@ -51,7 +51,9 @@ enum class Techniques //all drawables are to implement Techniques in this order
//also for this technique to work correctly, GetTransformXM() must be overloaded
//similarly to PlaneTexNorm in PlaneTexNorm.cpp
CamFacing, //object will be drawn always facing camera
ConsecutiveCamFacing
ConsecutiveCamFacing,
CamFacingEX,
ConsecutiveCamFacingEX
};
class Drawable
{
......@@ -62,6 +64,7 @@ public:
//don't forget to specify in their move constructor
//the call to RebindParent function, otherwise TransformeCbuf will have an invalid pointer
virtual DirectX::XMMATRIX GetTransformXM() const noexcept = 0;
virtual DirectX::XMFLOAT4 GetAdditionalTransformData()const { return{ 0.0f,0.0f,0.0f,0.0f }; };
void Submit(class FrameCommander& frame, Techniques tec) const noexcept;
void Bind(DXGraphics& gfx) const noexcept;
UINT GetIndexCount() const noxnd;
......
......@@ -88,8 +88,8 @@ HudElement::HudElement(std::wstring fontSprite, DXGraphics& gfx, wchar_t spriteN
Step only(3);
auto tex = Texture::Resolve(gfx, fontSprite);
float letterAspectRatio = ((float)tex->GetWidth() / spritesPerRow)
/ //-----------------------------------------
((float)tex->GetHeight() / spritesPerColumn);
/ //-----------------------------------------
((float)tex->GetHeight() / spritesPerColumn);
float screenAspecrRatio = (float)gfx.GetScreenWidth() / (float)gfx.GetScreenHeight();
float totalAR = letterAspectRatio / screenAspecrRatio;
only.AddBindable(std::move(tex));
......
......@@ -31,6 +31,7 @@ PlaneTexNorm::PlaneTexNorm(std::wstring modelName, DXGraphics& gfx, float scale,
const auto rootPath = std::filesystem::path(modelName).parent_path().wstring() + L"\\";
Technique standard;
Technique camFacing;
Technique camFacingEX;
{
bool hasSpecularMap = false;
bool hasAlphaDiffuse = false;
......@@ -68,7 +69,7 @@ PlaneTexNorm::PlaneTexNorm(std::wstring modelName, DXGraphics& gfx, float scale,
}
only.AddBindable(Bind::Sampler::Resolve(gfx)); //for filtering
}
assert(hasDiffuseMap && hasNormalMap && "model is missing either diffuse or normal map");//supposed to have both (just to be sure)
assert(hasDiffuseMap &&"model is missing diffuse map");//supposed to have both (just to be sure)
Dvtx::VertexBuffer vbuf(std::move(
VertexLayout{}
.Append(VertexLayout::Position3D)
......@@ -126,7 +127,10 @@ PlaneTexNorm::PlaneTexNorm(std::wstring modelName, DXGraphics& gfx, float scale,
only.PopBindable(); //replacing TransformCbuf with the new one for camFacing technique
only.AddBindable(std::make_shared<TransformCbuf>(gfx, TransformCbuf::DataType::CameraFacing));
camFacing.AddStep(std::move(only));
camFacing.AddStep(only);
only.PopBindable();
only.AddBindable(std::make_shared<TransformCbuf>(gfx, TransformCbuf::DataType::CamFacingEX));
camFacingEX.AddStep(only);
}
AddTechnique(std::move(standard));
Technique ConsecutiveStandart; //use this only in case where you are drawing the same drawable multiple times in one frame
......@@ -146,7 +150,18 @@ PlaneTexNorm::PlaneTexNorm(std::wstring modelName, DXGraphics& gfx, float scale,
only.AddBindable(std::make_shared<TransformCbuf>(gfx, TransformCbuf::DataType::CameraFacing));
ConsecutiveStandart.AddStep(std::move(only));
}
AddTechnique(std::move(ConsecutiveStandart));
AddTechnique(std::move(ConsecutiveCamFacing));
AddTechnique(std::move(camFacingEX));
Technique ConsecutiveCamFacingEX; //the order of AddTechnique calls matters because for the lookup to succeed
//it has to match the order in witch they are specified in Drawable base class
{
Step only(0);
only.AddBindable(std::make_shared<TransformCbuf>(gfx, TransformCbuf::DataType::CamFacingEX));
ConsecutiveStandart.AddStep(std::move(only));
}
AddTechnique(std::move(ConsecutiveCamFacingEX));
}
PlaneTexNorm::PlaneTexNorm(PlaneTexNorm&& mvFrom)
......@@ -178,11 +193,22 @@ DirectX::XMMATRIX PlaneTexNorm::GetTransformXM() const noexcept
return transMat;
}
DirectX::XMFLOAT4 PlaneTexNorm::GetAdditionalTransformData() const
{
assert(additionlData->size() && "no additional data bound for this object - can't draw CamFacingEX");
return additionlData->at(currentObjectBeingDrawn);
}
void PlaneTexNorm::BindPositionData(std::vector<PositionData>* posData)
{
this->posData = posData;
}
void PlaneTexNorm::BindAdditionalData(std::vector<DirectX::XMFLOAT4>* addData)
{
additionlData = addData;
}
void PlaneTexNorm::SmartSubmit(FrameCommander& fc, Techniques mainTec)
{
this->Submit(fc,mainTec);
......@@ -197,9 +223,15 @@ void PlaneTexNorm::SmartSubmit(FrameCommander& fc, Techniques mainTec)
case Techniques::CamFacing:
for (size_t i = 1; i < posData->size(); i++)this->Submit(fc, Techniques::ConsecutiveCamFacing);
break;
case Techniques::CamFacingEX:
for (size_t i = 1; i < posData->size(); i++)this->Submit(fc, Techniques::ConsecutiveCamFacingEX);
break;
case Techniques::ConsecutiveCamFacing:
assert(false && "ConsecutiveCamFacing can't be main technique");
break;
case Techniques::ConsecutiveCamFacingEX:
assert(false && "ConsecutiveCamFacingEX can't be main technique");
break;
default:
assert(false && "programmer missed the case in SmartSubmit in PlaneTexNorm");
break;
......
......@@ -21,12 +21,15 @@ public:
PlaneTexNorm& operator=(PlaneTexNorm&&) = delete;
PlaneTexNorm& operator=(const PlaneTexNorm&) = default;
DirectX::XMMATRIX GetTransformXM() const noexcept override;
DirectX::XMFLOAT4 GetAdditionalTransformData() const override;
void BindPositionData(std::vector<PositionData>* posData);
void BindAdditionalData(std::vector<DirectX::XMFLOAT4>* addData);
void SmartSubmit(FrameCommander& fc, Techniques mainTec); //uses Submit with standart tecqunice for first draw call
virtual ~PlaneTexNorm() = default;
//and consecutive for all the rest in posData
private:
std::vector<PositionData>* posData; //for every object there will be one position
const std::vector<PositionData>* posData; // one position for one object
const std::vector<DirectX::XMFLOAT4>* additionlData = nullptr; //for CamFacingEX only
mutable size_t currentObjectBeingDrawn = 0;
};
......@@ -45,11 +45,11 @@ namespace Bind
)
};
}
break;
break;
case Bind::TransformCbuf::DataType::CameraFacing:
{
namespace dx = DirectX;
const auto modelTransform = pParent->GetTransformXM(); //world
const auto camera = gfx.GetCamera(); //view
const auto camPos = gfx.GetCamPos();
......@@ -74,21 +74,65 @@ namespace Bind
{
newWorldTrans = dx::XMMatrixRotationX(acos(cosDeltaAngle)) * modelTransform;
}
dx::XMMATRIX newWorldView = dx::XMMatrixMultiply(newWorldTrans, camera);
dx::XMMATRIX newWorldView = dx::XMMatrixMultiply(newWorldTrans, camera);
return {
dx::XMMatrixTranspose(newWorldView),
dx::XMMatrixTranspose(
newWorldView*
newWorldView *
gfx.GetProjection()
)
};
break;
}
case Bind::TransformCbuf::DataType::NotSpecified: assert(false&&"please,specify data type fot transform constant buffer");
case Bind::TransformCbuf::DataType::CamFacingEX:
{
namespace dx = DirectX;
const auto modelTransform = pParent->GetTransformXM(); //world
const auto addData = pParent->GetAdditionalTransformData(); //roll+scale
const auto camera = gfx.GetCamera(); //view
const auto camPos = gfx.GetCamPos();
dx::XMFLOAT4X4 modelTransStored;
dx::XMStoreFloat4x4(&modelTransStored, modelTransform);
dx::XMFLOAT4X4 viewsStored;
dx::XMStoreFloat4x4(&viewsStored, camera);
Vec3 worldPos{ modelTransStored._41, modelTransStored._42,modelTransStored._43 };
Vec3 camPosVec{ camPos.x, camPos.y, camPos.z };
Vec3 diff = camPosVec - worldPos;
float cosDeltaAngle = (diff / diff.Len()) * Vec3{ 0.0f, 0.0f, -1.0f };//no explanation here...
//just know that works ONLY with posData.rot = { 0.0f, 3 * PI / 2, PI / 2 };
dx::XMMATRIX newWorldTrans;
if (diff.x > 0.0f)
{
newWorldTrans = dx::XMMatrixRotationX(-acos(cosDeltaAngle)) * modelTransform;
}
else
{
newWorldTrans = dx::XMMatrixRotationX(acos(cosDeltaAngle)) * modelTransform;
}
newWorldTrans*=dx::XMMatrixRotationAxis({ diff.x,diff.y,diff.z }, addData.x);
newWorldTrans *= dx::XMMatrixScaling(addData.y, addData.y, addData.y);
dx::XMMATRIX newWorldView = dx::XMMatrixMultiply(newWorldTrans, camera);
return {
dx::XMMatrixTranspose(newWorldView),
dx::XMMatrixTranspose(
newWorldView *
gfx.GetProjection()
)
};
break;
}
case Bind::TransformCbuf::DataType::NotSpecified: assert(false && "please,specify data type fot transform constant buffer");
default:
assert(false && "programmer missed the case");
break;
}
}
}
std::unique_ptr<VertexConstantBuffer<TransformCbuf::Transforms>> TransformCbuf::pVcbuf;
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ namespace Bind
{
Standart,
CameraFacing, //for this technik object normal (before transformations) must be {0,0,1}
CamFacingEX, //roll and scale implemented
NotSpecified
};
protected:
......
# Blender MTL File: 'None'
# Material Count: 1
newmtl Enemy_hit
Ns 49.300000
Ka 1.000000 1.000000 1.000000
Kd 1.100000 2.900000 8.300000
Ks 1.300000 0.700000 0.200000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd Enemy_hit.png
\ No newline at end of file
# Blender v2.81 (sub 16) OBJ File: ''
# www.blender.org
mtllib Enemy_hit.mtl
o Plane
v -1.000000 0.000000 0.725000
v 0.450000 0.000000 0.725000
v -1.000000 0.000000 -0.725000
v 0.450000 0.000000 -0.725000
vt 0.999900 0.999900
vt 0.000100 0.000100
vt 0.999900 0.000100
vt 0.000100 0.999900
vn 0.0000 1.0000 0.0000
usemtl Enemy_hit
s off
f 2/1/1 3/2/1 1/3/1
f 2/1/1 4/4/1 3/2/1
......@@ -35,6 +35,8 @@ public:
return upgraded;
}
virtual void Upgrade() {};
float preActTime = 0.0f;
float actTime = 0.0f;
protected:
size_t id = 0; //is used to extract sprite from file
bool quick = 0;
......
#include "Skills0.h"
DustThrow::DustThrow(CombatEntity* owner) : Skill(owner)
{