Skip to content

Commit

Permalink
Initial Comit
Browse files Browse the repository at this point in the history
Add : Jumper.cpp
Modify : a lot
  • Loading branch information
Kredsya committed Dec 9, 2022
1 parent 0c8a777 commit 2a90f02
Show file tree
Hide file tree
Showing 182 changed files with 6,709 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vs
81 changes: 81 additions & 0 deletions CBorder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "d3dUtility.h"
#include "CBorder.h"

// 테두리의 생성자
CBorder::CBorder(D3DXCOLOR color)
{
D3DXMatrixIdentity(&m_mLocal);
ZeroMemory(&m_mtrl, sizeof(m_mtrl));
mesh = nullptr;

m_mtrl.Ambient = color;
m_mtrl.Diffuse = color;
m_mtrl.Specular = color;
m_mtrl.Emissive = d3d::BLACK;
m_mtrl.Power = 5.0f;
}

// 테두리의 소멸자
CBorder::~CBorder()
{
d3d::Release<ID3DXMesh*>(mesh);

for (int i = 0; i < Textures.size(); i++)
{
d3d::Release<IDirect3DTexture9*>(Textures[i]);
}
}

bool CBorder::create(IDirect3DDevice9* pDevice, float ix, float iz, float iwidth, float iheight, float idepth, D3DXCOLOR color = d3d::WHITE)
{
if (NULL == pDevice)
return false;

m_mtrl.Ambient = color;
m_mtrl.Diffuse = color;
m_mtrl.Specular = color;
m_mtrl.Emissive = d3d::BLACK;
m_mtrl.Power = 5.0f;

m_width = iwidth;
m_depth = idepth;

if (FAILED(D3DXCreateBox(pDevice, iwidth, iheight, idepth, &m_pBoundMesh, NULL)))
return false;
return true;
}

// 벽을 화면에서 소멸시킴
void CBorder::destroy()
{
if (mesh != nullptr)
{
mesh->Release();
mesh = nullptr;
}
}

// 테두리를 화면에 그려냄
void CBorder::draw(IDirect3DDevice9* pDevice, const D3DXMATRIX& mWorld)
{
if (NULL == pDevice)
return;
pDevice->SetTransform(D3DTS_WORLD, &mWorld);
pDevice->MultiplyTransform(D3DTS_WORLD, &m_mLocal);
pDevice->SetMaterial(&m_mtrl);
m_pBoundMesh->DrawSubset(0);
}

void CBorder::setPosition(float x, float y, float z)
{
D3DXMATRIX m;
/*this->m_x = x;
this->m_z = z;*/
this->center_x = x;
this->center_y = y;
this->center_z = z;

D3DXMatrixTranslation(&m, x, y, z);
setLocalTransform(m);
}
void CBorder::setLocalTransform(const D3DXMATRIX& mLocal) { m_mLocal = mLocal; }
33 changes: 33 additions & 0 deletions CBorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _CBORDER_
#define _CBORDER_

#include "d3dUtility.h"
#include <vector>

// -----------------------------------------------------------------------------
// CBorder class definition
// 당구대(다이)의 테두리에 관련한 클래스에 대한 정의 (3ds max와 maya로 작업)
// -----------------------------------------------------------------------------
class CBorder
{
private:
float m_width;
float m_depth;
float center_x, center_y, center_z;
D3DMATERIAL9 m_mtrl;
D3DXMATRIX m_mLocal;
ID3DXMesh* mesh;
std::vector<D3DMATERIAL9> Mtrls;
std::vector<IDirect3DTexture9*> Textures;
ID3DXMesh* m_pBoundMesh;
void setLocalTransform(const D3DXMATRIX& mLocal);
public:
CBorder(D3DXCOLOR color); // 테두리의 생성자
~CBorder(); // 테두리의 소멸자
void setPosition(float x, float y, float z);
bool create(IDirect3DDevice9* pDevice, float ix, float iz, float iwidth, float iheight, float idepth, D3DXCOLOR color); // 테두리를 화면에 생성함
void draw(IDirect3DDevice9* pDevice, const D3DXMATRIX& mWorld); // 테두리를 화면에 그려냄
void destroy(); // 테두리를 화면에서 소멸시킴
};

#endif
22 changes: 22 additions & 0 deletions CBottomWall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "CBottomWall.h"

CBottomWall::CBottomWall(float iwidth, float iheight, float idepth, D3DXCOLOR color)
: CWall(iwidth, iheight, idepth, color) {
}

bool CBottomWall::hasIntersected(CSphere& ball) const noexcept {
if (ball.getPosition().x > this->center_x - (this->m_width / 2) &&
ball.getPosition().x < this->center_x + (this->m_width / 2)) {
if (ball.getPosition().z - ball.getRadius() < this->center_z + (this->m_depth / 2)) {
return true;
}
}
return false;
}

void CBottomWall::hitBy(CSphere& ball) noexcept {
if (hasIntersected(ball)) {
this->adjustPosition(ball);
ball.setPower(ball.getVelocity_X() * (1 - LOSS_RATIO), -ball.getVelocity_Z() * (1 - LOSS_RATIO));
}
}
12 changes: 12 additions & 0 deletions CBottomWall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _CBOTTOMWALL_
#define _CBOTTOMWALL_
#include "CWall.h"

class CBottomWall : public CWall
{
public:
CBottomWall(float iwidth, float iheight, float idepth, D3DXCOLOR color);
bool hasIntersected(CSphere& ball) const noexcept;
void hitBy(CSphere& ball) noexcept;
};
#endif
92 changes: 92 additions & 0 deletions CFloor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "CFloor.h"
#include "CSphere.h"
#include <iostream>
using namespace std;

#define M_RADIUS 0.21
#define PI 3.14159265
#define M_HEIGHT 0.01
#define DECREASE_RATE 0.9982

const float CFloor::LOSS_RATIO = 0.006;

CFloor::CFloor(void) {
D3DXMatrixIdentity(&m_mLocal);
ZeroMemory(&m_mtrl, sizeof(m_mtrl));
m_width = 0;
m_depth = 0;
m_pBoundMesh = NULL;
}

CFloor::CFloor(float iwidth, float iheight, float idepth, D3DXCOLOR color) {
D3DXMatrixIdentity(&m_mLocal);
ZeroMemory(&m_mtrl, sizeof(m_mtrl));

m_mtrl.Ambient = color;
m_mtrl.Diffuse = color;
m_mtrl.Specular = color;
m_mtrl.Emissive = d3d::BLACK;
m_mtrl.Power = 5.0f;
m_width = iwidth;
m_height = iheight;
m_depth = idepth;
m_pBoundMesh = nullptr;
}

CFloor::~CFloor(void) {}

bool CFloor::create(IDirect3DDevice9* pDevice, float ix, float iz, float iwidth, float iheight, float idepth, D3DXCOLOR color = d3d::WHITE) {
if (NULL == pDevice)
return false;

m_mtrl.Ambient = color;
m_mtrl.Diffuse = color;
m_mtrl.Specular = color;
m_mtrl.Emissive = d3d::BLACK;
m_mtrl.Power = 5.0f;

m_width = iwidth;
m_depth = idepth;

if (FAILED(D3DXCreateBox(pDevice, iwidth, iheight, idepth, &m_pBoundMesh, NULL)))
return false;
return true;
}

void CFloor::destroy(void) {
if (m_pBoundMesh != NULL) {
m_pBoundMesh->Release();
m_pBoundMesh = NULL;
}
}

void CFloor::draw(IDirect3DDevice9* pDevice, const D3DXMATRIX& mWorld) {
if (NULL == pDevice)
return;
pDevice->SetTransform(D3DTS_WORLD, &mWorld);
pDevice->MultiplyTransform(D3DTS_WORLD, &m_mLocal);
pDevice->SetMaterial(&m_mtrl);
m_pBoundMesh->DrawSubset(0);
}


void CFloor::setPosition(float x, float y, float z) {
D3DXMATRIX m;
this->m_x = x;
this->m_z = z;

D3DXMatrixTranslation(&m, x, y, z);
setLocalTransform(m);
}

float CFloor::getHeight(void) const { return M_HEIGHT; }

void CFloor::setLocalTransform(const D3DXMATRIX& mLocal) { m_mLocal = mLocal; }

void CFloor::setType(int type) { type = type; }

D3DXVECTOR3 CFloor::getPosition() const {
D3DXVECTOR3 org(center_x, center_y, center_z);
return org;
}

41 changes: 41 additions & 0 deletions CFloor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _CFloor_
#define _CFloor_

#include "d3dUtility.h"
#include "CSphere.h"


class CFloor
{
protected:
float m_x;
float m_z;
float m_width;
float m_depth;
float m_height;

int type;

D3DXMATRIX m_mLocal;
D3DMATERIAL9 m_mtrl;
ID3DXMesh* m_pBoundMesh;

float center_x, center_y, center_z;

void setLocalTransform(const D3DXMATRIX& mLocal);

public:
static const float LOSS_RATIO;
CFloor(void);
CFloor(float iwidth, float iheight, float idepth, D3DXCOLOR color);
~CFloor(void);
bool create(IDirect3DDevice9* pDevice, float ix, float iz, float iwidth, float iheight, float idepth, D3DXCOLOR color);
void destroy(void);
void draw(IDirect3DDevice9* pDevice, const D3DXMATRIX& mWorld);
void setPosition(float x, float y, float z);
float getHeight(void) const;
void setType(int type);
D3DXVECTOR3 getPosition() const;
};

#endif
22 changes: 22 additions & 0 deletions CHandSphere.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "CHandSphere.h"

CHandSphere::CHandSphere(const char* ballImageFileName) : CSphere("0") {
this->firstHitBallType = BallType::NONE;
}

BallType CHandSphere::getFirstHitBallType() const noexcept {
return this->firstHitBallType;
}

void CHandSphere::setFirstHitBallType(BallType ballType) noexcept {
this->firstHitBallType = ballType;
}

void CHandSphere::hitBy(CSphere& ball) noexcept {
if (this->hasIntersected(ball)) {
if (this->firstHitBallType == BallType::NONE) {
this->firstHitBallType = ball.getBallType();
}
super::hitBy(ball);
}
}
15 changes: 15 additions & 0 deletions CHandSphere.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _CHANDSPHERE_
#define _CHANDSPHERE_
#include "CSphere.h"

class CHandSphere : public CSphere
{
private:
BallType firstHitBallType;
public:
CHandSphere(const char* ballImageFileName);
BallType getFirstHitBallType() const noexcept;
void setFirstHitBallType(BallType ballType) noexcept;
void hitBy(CSphere& ball) noexcept;
};
#endif
Loading

0 comments on commit 2a90f02

Please sign in to comment.