Skip to content

Commit

Permalink
Update sample character controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Sep 27, 2024
1 parent 0da6ad6 commit e1c63de
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Samples/CharacterController/Source/CapsuleMesh/CCapsuleMesh.cpp
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 Samples/CharacterController/Source/CapsuleMesh/CCapsuleMesh.h
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 Samples/CharacterController/Source/CapsuleMesh/CLatheMesh.cpp
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 Samples/CharacterController/Source/CapsuleMesh/CLatheMesh.h
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 Samples/CharacterController/Source/CapsuleMesh/CLine3D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "pch.h"
#include "CLine3D.h"

CLine3D::CLine3D()
{

}

CLine3D::~CLine3D()
{

}
12 changes: 12 additions & 0 deletions Samples/CharacterController/Source/CapsuleMesh/CLine3D.h
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();
};

0 comments on commit e1c63de

Please sign in to comment.