-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0da6ad6
commit e1c63de
Showing
6 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Samples/CharacterController/Source/CapsuleMesh/CCapsuleMesh.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "pch.h" | ||
#include "CCapsuleMesh.h" | ||
#include "Debug/CSceneDebug.h" | ||
|
||
CCapsuleMesh::CCapsuleMesh() | ||
{ | ||
|
||
} | ||
|
||
CCapsuleMesh::~CCapsuleMesh() | ||
{ | ||
|
||
} | ||
|
||
void CCapsuleMesh::init(float radius, float height) | ||
{ | ||
if (height < radius * 2) | ||
height = radius * 2; | ||
|
||
initOutline(radius, height); | ||
initLatheMesh(); | ||
} | ||
|
||
void CCapsuleMesh::initOutline(float radius, float height) | ||
{ | ||
m_outline.Points.clear(); | ||
|
||
core::vector3df center; | ||
center.set(0.0f, height - radius, 0.0f); | ||
|
||
int step = 5; | ||
float angle = 0.0f; | ||
float stepAngle = 90.0f / (float)step; | ||
core::vector3df p; | ||
|
||
// top capsule | ||
for (int i = 0; i <= step; i++) | ||
{ | ||
angle = i * stepAngle; | ||
p.set(0.0f, radius * cosf(angle * core::DEGTORAD), radius * sinf(angle * core::DEGTORAD)); | ||
m_outline.Points.push_back(center + p); | ||
} | ||
|
||
// body capsule | ||
center.set(0.0f, radius, 0.0f); | ||
p.set(0.0f, 0.0f, radius); | ||
m_outline.Points.push_back(center + p); | ||
|
||
// bottom capsule | ||
for (int i = 0; i <= step; i++) | ||
{ | ||
angle = i * stepAngle; | ||
p.set(0.0f, -radius * sinf(angle * core::DEGTORAD), radius * cosf(angle * core::DEGTORAD)); | ||
m_outline.Points.push_back(center + p); | ||
} | ||
} | ||
|
||
void CCapsuleMesh::drawOutline() | ||
{ | ||
if (m_outline.Points.size() >= 2) | ||
{ | ||
CSceneDebug* sceneDebug = CSceneDebug::getInstance(); | ||
sceneDebug->addLinestrip(m_outline.Points, SColor(255, 255, 0, 0)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Samples/CharacterController/Source/CapsuleMesh/CCapsuleMesh.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "CLatheMesh.h" | ||
|
||
class CCapsuleMesh : public CLatheMesh | ||
{ | ||
protected: | ||
|
||
public: | ||
CCapsuleMesh(); | ||
|
||
virtual ~CCapsuleMesh(); | ||
|
||
void init(float radius, float height); | ||
|
||
void drawOutline(); | ||
|
||
protected: | ||
|
||
void initOutline(float radius, float height); | ||
|
||
}; |
37 changes: 37 additions & 0 deletions
37
Samples/CharacterController/Source/CapsuleMesh/CLatheMesh.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "pch.h" | ||
#include "CLatheMesh.h" | ||
|
||
// uv: https://catlikecoding.com/unity/tutorials/procedural-meshes/uv-sphere/ | ||
|
||
CLatheMesh::CLatheMesh() : | ||
m_mesh(NULL) | ||
{ | ||
m_mesh = new CMesh(); | ||
} | ||
|
||
CLatheMesh::~CLatheMesh() | ||
{ | ||
m_mesh->drop(); | ||
} | ||
|
||
void CLatheMesh::initLatheMesh() | ||
{ | ||
/* | ||
int numPoint = (int)m_outline.Points.size(); | ||
if (numPoint == 0) | ||
return; | ||
int step = 10; | ||
float angleStep = 360.0f / (float)step; | ||
float angle = 0.0f; | ||
for (int i = 0; i < step; i++) | ||
{ | ||
for (int j = 0; j < numPoint; j++) | ||
{ | ||
core::vector3df& p = m_outline.Points[j]; | ||
} | ||
} | ||
*/ | ||
} |
24 changes: 24 additions & 0 deletions
24
Samples/CharacterController/Source/CapsuleMesh/CLatheMesh.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "CLine3D.h" | ||
#include "RenderMesh/CMesh.h" | ||
|
||
class CLatheMesh | ||
{ | ||
protected: | ||
CLine3D m_outline; | ||
CMesh* m_mesh; | ||
|
||
public: | ||
CLatheMesh(); | ||
|
||
virtual ~CLatheMesh(); | ||
|
||
inline CMesh* getMesh() | ||
{ | ||
return m_mesh; | ||
} | ||
protected: | ||
|
||
void initLatheMesh(); | ||
}; |
12 changes: 12 additions & 0 deletions
12
Samples/CharacterController/Source/CapsuleMesh/CLine3D.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "pch.h" | ||
#include "CLine3D.h" | ||
|
||
CLine3D::CLine3D() | ||
{ | ||
|
||
} | ||
|
||
CLine3D::~CLine3D() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
class CLine3D | ||
{ | ||
public: | ||
core::array<core::vector3df> Points; | ||
|
||
public: | ||
CLine3D(); | ||
|
||
virtual ~CLine3D(); | ||
}; |