Basic 3D Game Engine with usage of DirectX 11 & PhysX on C++
- DirectX 11 as graphics engine
- PhysX as physics engine
- Basic lighting (point light, directional light, spot light)
- Basic shadows (shadow mapping using depth)
- Basic event timer
- Entity system
- Camera system (field-of-view setting, perspective & orthogonal projection)
- Textures, normal maps while rendering
- Skeleton animation system
- Being able to load FBX models (Autodesk format) with animation
Window* pMainWnd = new Window(hInstance, WND_TITLE, WIDTH, HEIGHT);
InputHandler class is a wrapper for keyboard and mouse classes, also create Keyboard & Mouse objects.
EventHandler* pEventHandler = new EventHandler();
InputHandler* pInputHandler = new InputHandler();
Keyboard* pKeyb = new Keyboard();
Mouse* pMouse = new Mouse();
Graphics* pGfx = new Graphics(pMainWnd->GetHandler(), WIDTH, HEIGHT, GRAPHICS_REFRESH_RATE);
Physics* pPhy = new Physics(GRAVITY, PHYSICS_REFRESH_RATE);
Character::worldGravity = GRAVITY / PHYSICS_REFRESH_RATE;
World integrates physics and graphics components.
Game setups the game scene.
World* pWorld = new World(pGfx, pPhy, pAud);
pWorld->Setup();
Game* pGame = new Game(pWorld, pInputHandler);
pGame->Setup();
pMainWnd->Setup(pKeyb, pMouse);
pInputHandler->Setup(pKeyb, pMouse, pEventHandler, pWorld);
wMainCamera.setPerspectiveProjection(FOV, WIDTH / HEIGHT);
this->pWorld->addCamera(&this->wMainCamera);
Mesh* boxMesh = new Mesh();
boxMesh->createBoxGeometry({ 1,1,1 });
CollisionShape* groundBoxColShape = new CollisionShape();
CollisionActor* groundBoxColActor = new CollisionActor(COLLISION_ACTOR_STATIC);
Entity* groundBox = new Entity(
{ 2000, 0.1f, 2000 },
{ 0, 0, 0 },
{ 0,0,0,0 },
NULL,
NULL,
boxMesh,
groundBoxColShape,
groundBoxColActor
);
this->pWorld->addEntity(groundBox);
// Collision.
CollisionShape* mainCharacterCollisionShape = new CollisionShape();
CollisionActor* mainCharacterCollisionActor = new CollisionActor(COLLISION_ACTOR_CCT);
Material* mainCharacterMaterial = new Material(NULL, { 1, 1, 1, 1 }, 1, 5);
// Create bash mesh object
Mesh* mainCharacterMesh = new Mesh();
mainCharacter = new Character(
{ 0.01f, 0.01f, 0.01f },
{ 0,0,0 },
{ 0,0,0,0 },
mainCharacterMaterial,
NULL,
mainCharacterMesh,
mainCharacterCollisionShape,
mainCharacterCollisionActor,
0.1f, {0, 0, 1}
);
// Load mesh.
if (mainCharacterMesh->LoadFBX("CHARACTER_FBX_PATH", "")) {
// Set Animation
MeshDeformer* mainCharacterMeshDeformer = new MeshDeformer();
mainCharacter->attachMeshDeformer(mainCharacterMeshDeformer);
this->mainCharacter->setAnimation("Take 001");
// Add entity to world.
this->pWorld->addEntity(mainCharacter);
this->pInputHandler->setMainCharacter(mainCharacter);
// Add character camera.
Camera* pCharacterCamera = new Camera(
Vector3(0.0f, 0.0f, 0.0f),
Vector3::ZAxis(),
WIDTH, HEIGHT,
PROJECTION_TYPE::PERSPECTIVE
);
pCharacterCamera->setPerspectiveProjection(FOV, WIDTH / HEIGHT);
pWorld->addCamera(pCharacterCamera, true);
this->mainCharacter->setCamera(pCharacterCamera);
VectorRelation* characterCam = new Vector3Relation(
&(this->mainCharacter->gPosition),
&(pCharacterCamera->gPosition),
VECTOR_RELATION_TYPE::RLTV,
&(this->mainCharacter->dataChanged),
&(pCharacterCamera->dataChanged),
true,
Vector3(0, 2.5f, -2.5f)
);
this->pWorld->addVectorRelation(characterCam);
}
this->directionalSunLight = new DirectionalLight(Vector3(-1, -1, 1), 0.15f, Color(0.99f, 0.72f, 0.074f), true, 3);
this->pWorld->addLight(this->directionalSunLight);
this->wMainCameraSpotLight = new SpotLight(Vector3(), Vector3(), 1, Color(0.66f, 0.66f, 0.66f), dx::XM_PIDIV4);
this->pWorld->addLight(this->wMainCameraSpotLight);
this->pointLight = new PointLight(Vector3(15, 5, 3), 1, Color(1,1,1));
this->pWorld->addLight(this->pointLight);
//// Create secondary camera, attach spot light to it.
Camera* pwSecondaryCamera = new Camera(
Vector3(-20, 5, -12),
Vector3::ZAxis(),
WIDTH, HEIGHT,
PROJECTION_TYPE::PERSPECTIVE
);
pwSecondaryCamera->setPerspectiveProjection(FOV, WIDTH / HEIGHT);
pWorld->addCamera(pwSecondaryCamera);
Attach camera position&direction vectors with spot light position&direction vector.
So they can navigate the scene together.
// Position relation, camera to spot light.
VectorRelation* camPositionSL = new Vector3Relation(
&(pwSecondaryCamera->gPosition),
&(this->wMainCameraSpotLight->gPosition),
VECTOR_RELATION_TYPE::COPY,
&(pwSecondaryCamera->dataChanged),
&(this->wMainCameraSpotLight->dataChanged)
);
this->pWorld->addVectorRelation(camPositionSL);
// Direction relation, camera to spot light.
VectorRelation* camDirectionSL = new Vector3Relation(
&(pwSecondaryCamera->gDirection),
&(this->wMainCameraSpotLight->gDirection),
VECTOR_RELATION_TYPE::COPY,
&(pwSecondaryCamera->dataChanged),
&(this->wMainCameraSpotLight->dataChanged)
);
this->pWorld->addVectorRelation(camDirectionSL);