Skip to content

Commit

Permalink
Add : gravity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kredsya committed Dec 10, 2022
1 parent 4d09d61 commit 3f88194
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 25 deletions.
21 changes: 19 additions & 2 deletions Jumper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Jumper.h"

#define FVF_VERTEX D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1
#define GRAVITY 0.4f

struct _VERTEX {
D3DXVECTOR3 pos;
Expand Down Expand Up @@ -82,6 +83,22 @@ bool Jumper::hasIntersected(Platform& platform) {
return false;
}

void Jumper::jumperUpdate(float timeDiff) {
const float TIME_SCALE = 3.3;
D3DXVECTOR3 cord = this->getPosition();

this->x = cord.x;
this->z = cord.z;

float tX = cord.x + TIME_SCALE * timeDiff * v_x;
float tZ = cord.z + TIME_SCALE * timeDiff * v_z;
this->setPosition(tX, cord.y, tZ);

v_z -= TIME_SCALE * timeDiff * GRAVITY;

setVelocity(v_x, v_z);
}

double Jumper::getVelocity_X() {
return v_x;
}
Expand All @@ -90,7 +107,7 @@ double Jumper::getVelocity_Z() {
return v_z;
}

void Jumper::setPower(double vx, double vz) {
void Jumper::setVelocity(double vx, double vz) {
v_x = vx;
v_z = vz;
}
Expand Down Expand Up @@ -125,7 +142,7 @@ void Jumper::setPosition(float x, float y, float z) {

LPD3DXMESH Jumper::_createMappedBox(IDirect3DDevice9* pDev) {
LPD3DXMESH mesh;
if (FAILED(D3DXCreateBox(pDev, 1, 1, 1, &mesh, NULL)))
if (FAILED(D3DXCreateBox(pDev, 0.1, 0.01, 0.1, &mesh, NULL)))
return nullptr;

LPD3DXMESH texMesh;
Expand Down
3 changes: 2 additions & 1 deletion Jumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class Jumper {
void destroy(void);
void draw(IDirect3DDevice9* pDevice, const D3DXMATRIX& mWorld);
bool hasIntersected(Platform& platform);
void jumperUpdate(float timeDiff);
double getVelocity_X();
double getVelocity_Z();
void setPower(double vx, double vz);
void setVelocity(double vx, double vz);
const D3DXMATRIX& getLocalTransform(void) const;
void setLocalTransform(const D3DXMATRIX& mLocal);
D3DXVECTOR3 getPosition() const;
Expand Down
Binary file modified Release/VirtualLego.exe
Binary file not shown.
14 changes: 5 additions & 9 deletions Release/VirtualLego.log
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
 virtualLego.cpp
 Jumper.cpp
C:\Users\do901\source\repos\OOP-Proj4\d3dUtility.h(23,1): warning C4005: 'INFINITY': 매크로 재정의
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\corecrt_math.h(88,1): message : 'INFINITY'의 이전 정의를 참조하십시오.
C:\Users\do901\source\repos\OOP-Proj4\Status.h(19,3): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Users\do901\source\repos\OOP-Proj4\Status.h(53,65): warning C4290: 함수가 __declspec(nothrow)가 아님을 나타내려는 경우를 제외하고 C++ 예외 사양은 무시됩니다.
C:\Users\do901\source\repos\OOP-Proj4\virtualLego.cpp(40,1): warning C4005: 'PLATFORMWIDTH': 매크로 재정의
C:\Users\do901\source\repos\OOP-Proj4\Platform.h(6,1): message : 'PLATFORMWIDTH'의 이전 정의를 참조하십시오.
C:\Users\do901\source\repos\OOP-Proj4\virtualLego.cpp(41,1): warning C4005: 'PLATFORMHEIGHT': 매크로 재정의
C:\Users\do901\source\repos\OOP-Proj4\Platform.h(7,1): message : 'PLATFORMHEIGHT'의 이전 정의를 참조하십시오.
C:\Users\do901\source\repos\OOP-Proj4\virtualLego.cpp(94,5): warning C4305: '인수': 'double'에서 'float'(으)로 잘립니다.
C:\Users\do901\source\repos\OOP-Proj4\virtualLego.cpp(85,6): warning C4101: 'i' :참조되지 않은 지역 변수입니다.
C:\Users\do901\source\repos\OOP-Proj4\Jumper.cpp(87,30): warning C4305: '초기화 중': 'double'에서 'float'(으)로 잘립니다.
C:\Users\do901\source\repos\OOP-Proj4\Jumper.cpp(111,8): warning C4244: '=': 'double'에서 'float'(으)로 변환하면서 데이터가 손실될 수 있습니다.
C:\Users\do901\source\repos\OOP-Proj4\Jumper.cpp(112,8): warning C4244: '=': 'double'에서 'float'(으)로 변환하면서 데이터가 손실될 수 있습니다.
C:\Users\do901\source\repos\OOP-Proj4\Jumper.cpp(145,5): warning C4305: '인수': 'double'에서 'FLOAT'(으)로 잘립니다.
VirtualLego.vcxproj -> C:\Users\do901\source\repos\OOP-Proj4\Release\VirtualLego.exe
Binary file modified Release/VirtualLego.pdb
Binary file not shown.
Binary file modified Release/VirtualLego.tlog/CL.command.1.tlog
Binary file not shown.
Binary file modified Release/VirtualLego.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified Release/VirtualLego.tlog/CL.write.1.tlog
Binary file not shown.
Binary file modified Release/vc143.pdb
Binary file not shown.
Binary file modified Release/virtualLego.obj
Binary file not shown.
23 changes: 10 additions & 13 deletions virtualLego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include "Jumper.h"

#define NUM_PLATFORM 1
#define PLATFORMWIDTH 2
#define PLATFORMHEIGHT 0.5
#define PLATFORMDEPTH 0.5
#define PLATFORMWIDTH 0.2
#define PLATFORMHEIGHT 0.05
#define PLATFORMDEPTH 0.05

using std::array;

Expand All @@ -53,7 +53,7 @@ D3DXMATRIX g_mProj;
// -----------------------------------------------------------------------------
// Global variables
// -----------------------------------------------------------------------------
float g_camera_pos[3] = { 0.0f, 10.0f, 0.0f };
float g_camera_pos[3] = { 0.0f, 3.0f, 0.0f };

// window size
const int Width = 1024;
Expand All @@ -63,7 +63,6 @@ HWND window;

IDirect3DDevice9* Device = NULL;

Platform g_platform;
vector<Platform> g_platforms(NUM_PLATFORM);
vector<array<float, 3>> g_platform_cord(NUM_PLATFORM);
Jumper g_jumper;
Expand Down Expand Up @@ -91,17 +90,15 @@ bool Setup() {
//if (!displayGameStatus.create("Times New Roman", 16, Device)) return false;

// create platform
if (!g_platform.create(Device, 10, 0.1, 10, d3d::GREEN)) return false;
g_platform.setPosition(0, -5, 0);

for (int i = 0; i < NUM_PLATFORM; i++) {
if (!g_platforms[i].create(Device, PLATFORMWIDTH, PLATFORMHEIGHT, PLATFORMDEPTH, d3d::RED)) return false;
g_platforms[i].setPosition(0, 0, 0);
}

// create jumper
if (!g_jumper.create(Device)) return false;
g_jumper.setPosition(0, 0, 3);
g_jumper.setPosition(0, 0, 1);
g_jumper.setVelocity(0, 0);

// light setting
D3DLIGHT9 lit;
Expand Down Expand Up @@ -142,7 +139,9 @@ bool Setup() {
// set of destroy function
void Cleanup(void)
{
g_platform.destroy();
for (int i = 0; i < NUM_PLATFORM; i++) {
g_platforms[i].destroy();
}
g_light.destroy();
}

Expand All @@ -158,14 +157,12 @@ bool Display(float timeDelta)
Device->BeginScene();

// draw platforms
g_platform.draw(Device, g_mWorld);

for (int i = 0; i < NUM_PLATFORM; i++) {
g_platforms[i].draw(Device, g_mWorld);
}

// intersect between jumper and platform
// todo
g_jumper.jumperUpdate(timeDelta);

// draw jumper
g_jumper.draw(Device, g_mWorld);
Expand Down

0 comments on commit 3f88194

Please sign in to comment.