Skip to content

Commit

Permalink
#123 Update viewpoint texture
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed May 5, 2021
1 parent 88b2cc5 commit 3493594
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Assets/Editor/Font.meta

This file was deleted.

3 changes: 3 additions & 0 deletions Assets/Editor/Fonts.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<meta>
<guid id="62598da491d46164a18fc7914a6cd0b2994cc84cfc704af01665f1e1489e06b2"/>
</meta>
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Assets/Editor/Textures.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<meta>
<guid id="562e646369fd86d0274ce8bf2ffc51f4be3d567e2081e1b7373c35a7d2c04aff"/>
</meta>
Binary file added Assets/Editor/Textures/oxyz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Assets/Editor/Textures/oxyz.png.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<meta>
<guid id="52f889e17450ca6658b867d28b5217f58af18cd2eeb61a821f66de7c97cf0743"/>
</meta>
Binary file added Assets/Editor/Textures/oxyz.psd
Binary file not shown.
3 changes: 3 additions & 0 deletions Assets/Editor/Textures/oxyz.psd.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<meta>
<guid id="45de206b95363ec7f8e5d2d93438056b716e85c3a99cbed31bd5d47b55534ddb"/>
</meta>
2 changes: 1 addition & 1 deletion Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ namespace Skylicht
core::vector3df up(matData[4], matData[5], matData[6]);
up.normalize();

float distance = 2.5f;
float distance = 2.0f;
core::vector3df pos = -dir * distance;

m_viewpointCamera->setPosition(pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This file is part of the "Skylicht Engine".
#include "CViewpointData.h"
#include "Projective/CProjective.h"
#include "Material/Shader/CShaderManager.h"

#include "TextureManager/CTextureManager.h"
#include "GameObject/CGameObject.h"
#include "Camera/CCamera.h"

Expand All @@ -37,11 +37,14 @@ namespace Skylicht
CViewpointData::CViewpointData()
{
Buffer = new CMeshBuffer<video::S3DVertex>(getVideoDriver()->getVertexDescriptor(EVT_STANDARD));
Buffer->getMaterial().MaterialType = CShaderManager::getInstance()->getShaderIDByName("VertexColor");
Buffer->getMaterial().MaterialType = CShaderManager::getInstance()->getShaderIDByName("TextureColorAlpha");
Buffer->getMaterial().BackfaceCulling = false;
Buffer->setHardwareMappingHint(EHM_STREAM);

const float p = 1.0f;
ITexture* texture = CTextureManager::getInstance()->getTexture("Editor/Textures/oxyz.png");
Buffer->getMaterial().setTexture(0, texture);

const float p = 0.8f;

Position[0].set(p, 0.0f, 0.0f);
Position[1].set(-p, 0.0f, 0.0f);
Expand All @@ -67,12 +70,12 @@ namespace Skylicht
idx[i * 6 + 5] = i * 4 + 3;
}

SColor blue = SColor(255, 65, 105, 140);
SColor blue = SColor(255, 44, 143, 255);
SColor red = SColor(255, 155, 65, 80);
SColor green = SColor(255, 105, 140, 45);
core::vector3df zero(0.0f, 0.0f, 0.0f);

float s = 0.7f;
float s = 0.8f;
addLineVertexBatch(zero, Position[0] * s, red);
addLineVertexBatch(zero, Position[2] * s, blue);
addLineVertexBatch(zero, Position[4] * s, green);
Expand All @@ -83,7 +86,7 @@ namespace Skylicht

}

void CViewpointData::updateBillboard(const core::vector3df& look, const core::vector3df& up)
void CViewpointData::updateBillboard(const core::vector3df& look, const core::vector3df& up, const core::vector3df& campos)
{
video::S3DVertex* vtx = (video::S3DVertex*)Buffer->getVertexBuffer()->getVertices();

Expand All @@ -97,17 +100,67 @@ namespace Skylicht
sideQuad *= 0.25f;

SColor color(255, 255, 255, 255);
core::vector2df uvScale(1.0f, 1.0f);
core::vector2df uvScale(0.5f, 0.5f);
core::vector2df uvOffset(0.0f, 0.0f);

// sort to fix alpha depth
std::vector<std::pair<int, float>> sortPosition;
for (int i = 0; i < 6; i++)
{
float d = Position[i].getDistanceFromSQ(campos);
sortPosition.push_back(std::pair<int, float>(i, d));
}
struct {
bool operator()(const std::pair<int, float>& a, const std::pair<int, float>& b) const { return a.second > b.second; }
} customLess;
std::sort(sortPosition.begin(), sortPosition.end(), customLess);

for (int i = 0; i < 6; i++)
{
int offset = i * 4;
int offsetVertex = offset;

float x = Position[i].X;
float y = Position[i].Y;
float z = Position[i].Z;
int id = sortPosition[i].first;

float x = Position[id].X;
float y = Position[id].Y;
float z = Position[id].Z;

if (id == 1)
{
// -x
uvOffset.set(0.5f, 0.5f);
color.set(255, 154, 57, 71);
}
else if (id == 3)
{
// -y
uvOffset.set(0.5f, 0.5f);
color.set(255, 52, 100, 154);
}
else if (id == 5)
{
// -z
uvOffset.set(0.5f, 0.5f);
color.set(255, 98, 138, 34);
}
else if (id == 0)
{
// x
uvOffset.set(0.0f, 0.0f);
color.set(255, 255, 255, 255);
}
else if (id == 2)
{
// y
uvOffset.set(0.0f, 0.5f);
color.set(255, 255, 255, 255);
}
else if (id == 4)
{
// z
uvOffset.set(0.5f, 0.0f);
color.set(255, 255, 255, 255);
}

// top left vertex
vtx[offset].Pos.set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Skylicht

virtual ~CViewpointData();

void updateBillboard(const core::vector3df& look, const core::vector3df& up);
void updateBillboard(const core::vector3df& look, const core::vector3df& up, const core::vector3df& campos);

EAxis hit(CCamera* camera, float x, float y, int viewportW, int viewportH);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This file is part of the "Skylicht Engine".

#include "pch.h"
#include "CViewpointRenderer.h"
#include "Entity/CEntityManager.h"

namespace Skylicht
{
Expand Down Expand Up @@ -90,6 +91,8 @@ namespace Skylicht
look.normalize();
up.normalize();

core::vector3df camPos = entityManager->getCamera()->getGameObject()->getPosition();

for (u32 i = 0, n = m_viewpoints.size(); i < n; i++)
{
driver->setTransform(video::ETS_WORLD, transforms[i]->World);
Expand All @@ -101,7 +104,7 @@ namespace Skylicht
for (u32 i = 0, n = m_viewpoints.size(); i < n; i++)
{
driver->setTransform(video::ETS_WORLD, transforms[i]->World);
viewpoints[i]->updateBillboard(look, up);
viewpoints[i]->updateBillboard(look, up, camPos);

IMeshBuffer* buffer = viewpoints[i]->Buffer;
driver->setMaterial(buffer->getMaterial());
Expand Down
2 changes: 1 addition & 1 deletion Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Skylicht
namespace GUI
{
std::string CThemeConfig::FontName = "Droid Sans";
std::string CThemeConfig::FontPath = "Editor/Font/droidsans.ttf";
std::string CThemeConfig::FontPath = "Editor/Fonts/droidsans.ttf";

SGUIColor CThemeConfig::White = SGUIColor(255, 255, 255, 255);
SGUIColor CThemeConfig::Black = SGUIColor(255, 0, 0, 0);
Expand Down

0 comments on commit 3493594

Please sign in to comment.