Basic hit detection
This commit is contained in:
		| @@ -6,9 +6,9 @@ | ||||
| # Check for build target, or default. This is pretty much not guaranteed. | ||||
| if(NOT DEFINED DAWN_BUILD_TARGET) | ||||
|   if(WIN32) | ||||
|     set(DAWN_BUILD_TARGET "target-helloworld-win32-glfw") | ||||
|     set(DAWN_BUILD_TARGET "target-rose-win32-glfw") | ||||
|   elseif(UNIX AND NOT APPLE) | ||||
|     set(DAWN_BUILD_TARGET "target-helloworld-linux64-glfw") | ||||
|     set(DAWN_BUILD_TARGET "target-rose-linux64-glfw") | ||||
|   endif() | ||||
| endif() | ||||
|  | ||||
|   | ||||
| @@ -178,8 +178,8 @@ struct PokerTurn PokerPlayer::getAITurn() { | ||||
|       amount = bluffBet; | ||||
|       isBluff = true; | ||||
|     } | ||||
|   } else if ((expectedGain < 1.0f && confidence < 0.85f) || confidence < 0.1f) { | ||||
|     if (random < 80) { | ||||
|   } else if((expectedGain < 1.0f && confidence < 0.85f) || confidence < 0.1f) { | ||||
|     if(random < 80) { | ||||
|       amount = 0; | ||||
|     } else if(random < 5) { | ||||
|       amount = callBet; | ||||
| @@ -188,13 +188,13 @@ struct PokerTurn PokerPlayer::getAITurn() { | ||||
|       amount = bluffBet; | ||||
|       isBluff = true; | ||||
|     } | ||||
|   } else if ((expectedGain < 1.3f && confidence < 0.9f) || confidence < 0.5f) { | ||||
|     if (random < 60 || confidence < 0.5f) { | ||||
|   } else if((expectedGain < 1.3f && confidence < 0.9f) || confidence < 0.5f) { | ||||
|     if(random < 60 || confidence < 0.5f) { | ||||
|       amount = callBet; | ||||
|     } else { | ||||
|       amount = maxBet; | ||||
|     } | ||||
|   } else if (confidence < 0.95f || this->pokerGame->community.size() < 4) { | ||||
|   } else if(confidence < 0.95f || this->pokerGame->community.size() < 4) { | ||||
|     if(random < 20) { | ||||
|       amount = callBet; | ||||
|     } else { | ||||
|   | ||||
| @@ -71,16 +71,16 @@ int32_t Dawn::ticTacToeGetBoardScore( | ||||
|     uint8_t countEmpty = 0; | ||||
|  | ||||
|     for (uint8_t j = 0; j < 3; j++) { | ||||
|       if (board[lines[i][j]] == player) { | ||||
|       if(board[lines[i][j]] == player) { | ||||
|         countPlayer++; | ||||
|       } else if (board[lines[i][j]] == TIC_TAC_TOE_EMPTY) { | ||||
|       } else if(board[lines[i][j]] == TIC_TAC_TOE_EMPTY) { | ||||
|         countEmpty++; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     if (countPlayer == 2 && countEmpty == 1) { | ||||
|     if(countPlayer == 2 && countEmpty == 1) { | ||||
|       score += 10; | ||||
|     } else if (countPlayer == 1 && countEmpty == 2) { | ||||
|     } else if(countPlayer == 1 && countEmpty == 2) { | ||||
|       score += 1; | ||||
|     } | ||||
|   } | ||||
|   | ||||
| @@ -13,3 +13,69 @@ bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max) { | ||||
|     point.y >= min.y && point.y <= max.y | ||||
|   ); | ||||
| } | ||||
|  | ||||
| bool_t Dawn::boxCheckCollision( | ||||
|   glm::vec2 posA, glm::vec2 minA, glm::vec2 maxA, | ||||
|   glm::vec2 posB, glm::vec2 minB, glm::vec2 maxB, | ||||
|   glm::vec2 velocity, | ||||
|   glm::vec2 &normal, | ||||
|   float_t &entryTime, | ||||
|   float_t &exitTime, | ||||
|   glm::vec2 &entryPoint, | ||||
|   glm::vec2 &exitPoint | ||||
| ) { | ||||
|   // Calculate the time intervals of overlap in the x and y axes | ||||
|   glm::vec2 invEntry = glm::vec2(0.0f); | ||||
|   glm::vec2 invExit = glm::vec2(0.0f); | ||||
|  | ||||
|   if (velocity.x >= 0.0f) { | ||||
|     invEntry.x = ((minB.x + posB.x) - (maxA.x + posA.x)) / velocity.x; | ||||
|     invExit.x = ((maxB.x + posB.x) - (minA.x + posA.x)) / velocity.x; | ||||
|   } else { | ||||
|     invEntry.x = ((maxB.x + posB.x) - (minA.x + posA.x)) / velocity.x; | ||||
|     invExit.x = ((minB.x + posB.x) - (maxA.x + posA.x)) / velocity.x; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   if (velocity.y >= 0.0f) { | ||||
|     invEntry.y = ((minB.y + posB.y) - (maxA.y + posA.y)) / velocity.y; | ||||
|     invExit.y = ((maxB.y + posB.y) - (minA.y + posA.y)) / velocity.y; | ||||
|   } else { | ||||
|     invEntry.y = ((maxB.y + posB.y) - (minA.y + posA.y)) / velocity.y; | ||||
|     invExit.y = ((minB.y + posB.y) - (maxA.y + posA.y)) / velocity.y; | ||||
|   } | ||||
|  | ||||
|   // Calculate the time of entry and exit for each axis | ||||
|   glm::vec2 entry = glm::max(invEntry, glm::vec2(0.0f)); | ||||
|   glm::vec2 exit = glm::min(invExit, glm::vec2(1.0f)); | ||||
|  | ||||
|   // Find the time of entry and exit | ||||
|   entryTime = glm::max(entry.x, entry.y); | ||||
|   exitTime = glm::min(exit.x, exit.y); | ||||
|  | ||||
|   // If there is no overlap in either axis, there is no collision | ||||
|   if (entryTime > exitTime || entry.x < 0.0f && entry.y < 0.0f || entry.x > 1.0f || entry.y > 1.0f) { | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   // Calculate the normal of the collision | ||||
|   if (entry.x > entry.y) { | ||||
|     if (invEntry.x < 0.0f) { | ||||
|       normal = glm::vec2(1.0f, 0.0f); | ||||
|     } else { | ||||
|       normal = glm::vec2(-1.0f, 0.0f); | ||||
|     } | ||||
|   } else { | ||||
|     if (invEntry.y < 0.0f) { | ||||
|       normal = glm::vec2(0.0f, 1.0f); | ||||
|     } else { | ||||
|       normal = glm::vec2(0.0f, -1.0f); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // Calculate the entry and exit points | ||||
|   entryPoint = posA + velocity * entryTime; | ||||
|   exitPoint = posA + velocity * exitTime; | ||||
|  | ||||
|   return true; | ||||
| } | ||||
| @@ -6,8 +6,20 @@ | ||||
| #pragma once | ||||
| #include "dawnlibs.hpp" | ||||
| #include "assert/assert.hpp" | ||||
| #include "util/mathutils.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   bool_t boxCheckCollision( | ||||
|     glm::vec2 posA, glm::vec2 minA, glm::vec2 maxA, | ||||
|     glm::vec2 posB, glm::vec2 minB, glm::vec2 maxB, | ||||
|     glm::vec2 velocity, | ||||
|     glm::vec2 &normal, | ||||
|     float_t &entryTime, | ||||
|     float_t &exitTime, | ||||
|     glm::vec2 &entryPoint, | ||||
|     glm::vec2 &exitPoint | ||||
|   ); | ||||
|  | ||||
|   /** | ||||
|    * Checks if a given point is within the 2D Boundaries of an object. | ||||
|    *  | ||||
|   | ||||
| @@ -18,7 +18,7 @@ bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) { | ||||
|   float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y; | ||||
|   float_t s = (-direction.y * j.x + direction.x * j.y) / f; | ||||
|   float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f; | ||||
|   if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { | ||||
|   if(s >= 0 && s <= 1 && t >= 0 && t <= 1) { | ||||
|     *out = position + (t * direction); | ||||
|     return true; | ||||
|   } | ||||
|   | ||||
| @@ -47,7 +47,7 @@ bool_t aabb3dSweep( | ||||
|  | ||||
|   // If the earliest time of overlap is greater than the length of the timestep, the cubes | ||||
|   // will not collide during the timestep | ||||
|   if (tmin > 1.0f) { | ||||
|   if(tmin > 1.0f) { | ||||
|     fraction = 1.0f; | ||||
|     return false; | ||||
|   } | ||||
|   | ||||
| @@ -187,9 +187,9 @@ bool_t Dawn::raytestQuad( | ||||
|  | ||||
|   // perform ray-quad intersection test | ||||
|   float_t t = -localRayOrigin.z / localRayDirection.z; // intersection distance along ray | ||||
|   if (t < 0) return false; // intersection is behind the ray origin | ||||
|   if(t < 0) return false; // intersection is behind the ray origin | ||||
|   glm::vec2 intersectionPoint = glm::vec2(localRayOrigin) + t * glm::vec2(localRayDirection); | ||||
|   if ( | ||||
|   if( | ||||
|     glm::any(glm::lessThan(intersectionPoint, min)) || | ||||
|     glm::any(glm::greaterThan(intersectionPoint, max)) | ||||
|   ) { | ||||
|   | ||||
| @@ -10,3 +10,7 @@ using namespace Dawn; | ||||
| BoxCollider::BoxCollider(SceneItem *i) : Collider2D(i) { | ||||
|    | ||||
| } | ||||
|  | ||||
| enum Collider2DType BoxCollider::getColliderType() { | ||||
|   return COLLIDER2D_TYPE_BOX; | ||||
| } | ||||
| @@ -14,5 +14,6 @@ namespace Dawn { | ||||
|       glm::vec2 max = glm::vec2( 0.5f,  0.5f); | ||||
|  | ||||
|       BoxCollider(SceneItem *item); | ||||
|       enum Collider2DType getColliderType() override; | ||||
|   }; | ||||
| } | ||||
| @@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME} | ||||
|   PRIVATE | ||||
|     BoxCollider.cpp | ||||
|     Collider2D.cpp | ||||
|     CharacterController2D.cpp | ||||
| ) | ||||
| @@ -0,0 +1,71 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "CharacterController2D.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| CharacterController2D::CharacterController2D(SceneItem *i) : | ||||
|   SceneItemComponent(i) | ||||
| { | ||||
| } | ||||
|  | ||||
| void CharacterController2D::onStart() { | ||||
|   useEvent([&](float_t delta){ | ||||
|     // Friction | ||||
|     velocity -= velocity * friction * delta; | ||||
|  | ||||
|     auto myCollider = item->getComponent<Collider2D>(); | ||||
|     glm::vec2 currentPosition( | ||||
|       this->transform->getLocalPosition().x, | ||||
|       this->transform->getLocalPosition().z | ||||
|     ); | ||||
|  | ||||
|  | ||||
|     // Perform movement and check for collisions. | ||||
|     glm::vec2 moveAmount; | ||||
|     if(myCollider == nullptr) { | ||||
|       moveAmount = velocity; | ||||
|     } else { | ||||
|       // Perform sweep | ||||
|       auto allColliders = getScene()->findComponents<Collider2D>(); | ||||
|       auto itColliders = allColliders.begin(); | ||||
|  | ||||
|       glm::vec2 normal; | ||||
|       float_t entryTime; | ||||
|       float_t exitTime; | ||||
|       glm::vec2 entryPoint; | ||||
|       glm::vec2 exitPoint; | ||||
|       bool_t result; | ||||
|  | ||||
|       // Check for collisions, definitely not working 100% yet  | ||||
|       while(itColliders != allColliders.end()) { | ||||
|         auto c = *itColliders; | ||||
|         ++itColliders; | ||||
|         if(c == myCollider) continue; | ||||
|         result = myCollider->getCollidingResult( | ||||
|           velocity, c, normal, entryTime, exitTime, entryPoint, exitPoint | ||||
|         ); | ||||
|         if(result) break; | ||||
|       } | ||||
|  | ||||
|       if(result && entryTime <= delta) { | ||||
|         // Slide Resolution https://www.gamedev.net/articles/programming/general-and-gameplay-programming/swept-aabb-collision-detection-and-response-r3084/ | ||||
|         float dotprod = (velocity.x * normal.y) + (velocity.y * normal.x) * (1.0f - entryTime); | ||||
|         moveAmount = velocity * entryTime; | ||||
|  | ||||
|         // Respond to changes | ||||
|         velocity.x = dotprod * normal.y;  | ||||
|         velocity.y = dotprod * normal.x; | ||||
|       } else { | ||||
|         moveAmount = velocity; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     transform->setLocalPosition( | ||||
|       transform->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta) | ||||
|     ); | ||||
|   }, getScene()->eventSceneUpdate); | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "Collider2D.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class CharacterController2D : public SceneItemComponent { | ||||
|     private: | ||||
|       void move(glm::vec2 distance); | ||||
|        | ||||
|     public: | ||||
|       glm::vec2 velocity; | ||||
|       float_t friction = 12.0f; | ||||
|        | ||||
|       CharacterController2D(SceneItem *i); | ||||
|       void onStart() override; | ||||
|   }; | ||||
| } | ||||
| @@ -4,9 +4,64 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "Collider2D.hpp" | ||||
| #include "BoxCollider.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| Collider2D::Collider2D(SceneItem *i) : SceneItemComponent(i) { | ||||
|    | ||||
| } | ||||
|  | ||||
| bool_t Collider2D::getCollidingResult( | ||||
|   glm::vec2 movement, | ||||
|   Collider2D *other, | ||||
|   glm::vec2 &normal, | ||||
|   float_t &entryTime, | ||||
|   float_t &exitTime, | ||||
|   glm::vec2 &entryPoint, | ||||
|   glm::vec2 &exitPoint | ||||
| ) { | ||||
|   assertNotNull(other); | ||||
|   assertTrue(movement.x != 0 || movement.y != 0); | ||||
|  | ||||
|   auto localPos = this->transform->getLocalPosition(); | ||||
|   glm::vec2 myPos(localPos.x, localPos.z); | ||||
|  | ||||
|  | ||||
|   // Check what THIS is | ||||
|   switch(this->getColliderType()) { | ||||
|     case COLLIDER2D_TYPE_BOX: { | ||||
|       auto box1 = dynamic_cast<BoxCollider*>(this); | ||||
|       assertNotNull(box1); | ||||
|  | ||||
|       // Box VS ? | ||||
|       switch(other->getColliderType()) { | ||||
|         case COLLIDER2D_TYPE_BOX: { | ||||
|           auto box2 = dynamic_cast<BoxCollider*>(other); | ||||
|           assertNotNull(box2); | ||||
|           auto localPos2 = box2->transform->getLocalPosition(); | ||||
|           glm::vec2 otherPos(localPos2.x, localPos2.z); | ||||
|  | ||||
|           return boxCheckCollision( | ||||
|             myPos, box1->min, box1->max, | ||||
|             otherPos, box2->min, box2->max, | ||||
|             movement, | ||||
|             normal, entryTime, exitTime, entryPoint, exitPoint | ||||
|           ); | ||||
|         } | ||||
|          | ||||
|         default: { | ||||
|           assertUnreachable(); | ||||
|         } | ||||
|       } | ||||
|       break; | ||||
|     } | ||||
|  | ||||
|     default: { | ||||
|       assertUnreachable(); | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   assertUnreachable(); | ||||
|   return false; | ||||
| } | ||||
| @@ -5,10 +5,54 @@ | ||||
|  | ||||
| #pragma once | ||||
| #include "scene/SceneItemComponent.hpp" | ||||
| #include "physics/2d/Box.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   enum Collider2DType { | ||||
|     COLLIDER2D_TYPE_BOX | ||||
|   }; | ||||
|    | ||||
|   struct Collider2DAxisAlignedCollidingResult { | ||||
|     glm::vec2 normal; | ||||
|     float_t entryTime; | ||||
|     float_t exitTime; | ||||
|     glm::vec2 entryPoint; | ||||
|     glm::vec2 exitPoint; | ||||
|   }; | ||||
|  | ||||
|   class Collider2D : public SceneItemComponent { | ||||
|     public: | ||||
|       Collider2D(SceneItem *item); | ||||
|  | ||||
|       /** | ||||
|        * Returns which type of collider this is. | ||||
|        *  | ||||
|        * @return The collider type that this is. | ||||
|        */ | ||||
|       virtual enum Collider2DType getColliderType() = 0; | ||||
|  | ||||
|       /** | ||||
|        * Gets the result of checking if two collider bodies are intersecting. | ||||
|        * This is performed WITH movement to return entry and exit times. | ||||
|        *  | ||||
|        * @param result Where to store the results of the calculation. | ||||
|        * @param movement Movement operation that THIS object is performing. | ||||
|        * @param other Other Collider that is being compared. | ||||
|        * @param normal Output normal of the intersection. | ||||
|        * @param entryTime Output entry time when the two objects will intersect. | ||||
|        * @param exitTime Output exit time when the object will pass through. | ||||
|        * @param entryPoint Output point in 2D space where object will enter. | ||||
|        * @param exitPoint Output point where object will have passed through. | ||||
|        * @return True if the two objects will intersect at move otherwise false. | ||||
|        */ | ||||
|       bool_t getCollidingResult( | ||||
|         glm::vec2 movement, | ||||
|         Collider2D *other, | ||||
|         glm::vec2 &normal, | ||||
|         float_t &entryTime, | ||||
|         float_t &exitTime, | ||||
|         glm::vec2 &entryPoint, | ||||
|         glm::vec2 &exitPoint | ||||
|       ); | ||||
|   }; | ||||
| } | ||||
| @@ -9,6 +9,8 @@ | ||||
| #include "scene/Scene.hpp" | ||||
| #include "scene/components/physics/3d/Collider3D.hpp" | ||||
| #include "scene/components/physics/3d/CubeCollider.hpp" | ||||
| #include "scene/components/physics/2d/Collider2D.hpp" | ||||
| #include "scene/components/physics/2d/BoxCollider.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| @@ -162,4 +164,40 @@ void Scene::debugHitboxes() { | ||||
|     } | ||||
|     ++itColliders; | ||||
|   } | ||||
|  | ||||
|   auto colliders2d = this->findComponents<Collider2D>(); | ||||
|   auto itColliders2 = colliders2d.begin(); | ||||
|   while(itColliders2 != colliders2d.end()) { | ||||
|     auto c = *itColliders2; | ||||
|     switch(c->getColliderType()) { | ||||
|       case COLLIDER2D_TYPE_BOX: | ||||
|         auto asBox = dynamic_cast<BoxCollider*>(c); | ||||
|         this->debugLine({ | ||||
|           .v0 = glm::vec3(asBox->min.x, 0, asBox->min.y), | ||||
|           .v1 = glm::vec3(asBox->max.x, 0, asBox->min.y), | ||||
|           .color = COLOR_BLUE, | ||||
|           .transform = c->transform->getWorldTransform() | ||||
|         }); | ||||
|         this->debugLine({ | ||||
|           .v0 = glm::vec3(asBox->max.x, 0, asBox->min.y), | ||||
|           .v1 = glm::vec3(asBox->max.x, 0, asBox->max.y), | ||||
|           .color = COLOR_BLUE, | ||||
|           .transform = c->transform->getWorldTransform() | ||||
|         }); | ||||
|         this->debugLine({ | ||||
|           .v0 = glm::vec3(asBox->max.x, 0, asBox->max.y), | ||||
|           .v1 = glm::vec3(asBox->min.x, 0, asBox->max.y), | ||||
|           .color = COLOR_BLUE, | ||||
|           .transform = c->transform->getWorldTransform() | ||||
|         }); | ||||
|         this->debugLine({ | ||||
|           .v0 = glm::vec3(asBox->min.x, 0, asBox->max.y), | ||||
|           .v1 = glm::vec3(asBox->min.x, 0, asBox->min.y), | ||||
|           .color = COLOR_BLUE, | ||||
|           .transform = c->transform->getWorldTransform() | ||||
|         }); | ||||
|         break; | ||||
|     } | ||||
|     ++itColliders2; | ||||
|   } | ||||
| } | ||||
| @@ -49,7 +49,7 @@ void TextureRenderTarget::setSize(float_t width, float_t height) { | ||||
|   ); | ||||
|  | ||||
|   // Validate things went correct. | ||||
|   if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { | ||||
|   if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { | ||||
|     assertUnreachable(); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -6,8 +6,6 @@ | ||||
| #include "PlayerController.hpp" | ||||
| #include "game/DawnGame.hpp" | ||||
|  | ||||
| #include "scene/components/physics/3d/CapsuleCollider.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| PlayerController::PlayerController(SceneItem *item) : SceneItemComponent(item) { | ||||
| @@ -16,7 +14,7 @@ PlayerController::PlayerController(SceneItem *item) : SceneItemComponent(item) { | ||||
|  | ||||
| std::vector<SceneItemComponent*> PlayerController::getDependencies() { | ||||
|   return { | ||||
|     (this->characterController = item->getComponent<CharacterController3D>()) | ||||
|     (this->characterController = item->getComponent<CharacterController2D>()) | ||||
|   }; | ||||
| } | ||||
|  | ||||
| @@ -35,7 +33,7 @@ void PlayerController::onStart() { | ||||
|      | ||||
|     if(inputMove.x != 0 || inputMove.y != 0) { | ||||
|       float_t angle = atan2(inputMove.y, inputMove.x); | ||||
|       glm::vec3 movement = glm::vec3(cos(angle), 0, sin(angle)); | ||||
|       glm::vec2 movement(cos(angle), sin(angle)); | ||||
|       characterController->velocity += movement * delta * moveSpeed; | ||||
|     } | ||||
|   }, getScene()->eventSceneUpdate); | ||||
|   | ||||
| @@ -4,12 +4,12 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "scene/components/physics/3d/CharacterController3D.hpp" | ||||
| #include "scene/components/physics/2d/CharacterController2D.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class PlayerController : public SceneItemComponent { | ||||
|     protected: | ||||
|       CharacterController3D *characterController; | ||||
|       CharacterController2D *characterController; | ||||
|  | ||||
|     public: | ||||
|       float_t moveSpeed = 40.0f; | ||||
|   | ||||
| @@ -12,11 +12,9 @@ | ||||
| #include "scene/components/display/MeshHost.hpp" | ||||
| #include "scene/components/display/material/SimpleTexturedMaterial.hpp" | ||||
| #include "scene/components/example/ExampleSpin.hpp" | ||||
| #include "scene/components/physics/3d/SphereCollider.hpp" | ||||
| #include "scene/components/physics/3d/CubeCollider.hpp" | ||||
| #include "scene/components/physics/3d/CapsuleCollider.hpp" | ||||
| #include "display/mesh/SphereMesh.hpp" | ||||
| #include "display/mesh/CapsuleMesh.hpp" | ||||
| #include "scene/components/physics/2d/BoxCollider.hpp" | ||||
| #include "scene/components/physics/2d/CharacterController2D.hpp" | ||||
| #include "display/mesh/CubeMesh.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class HelloWorldScene : public Scene { | ||||
| @@ -24,22 +22,15 @@ namespace Dawn { | ||||
|       Camera *camera; | ||||
|  | ||||
|       void stage() override { | ||||
|  | ||||
|         auto playerItem = this->createSceneItem(); | ||||
|         auto player = playerItem->addComponent<PlayerController>(); | ||||
|         playerItem->addComponent<MeshRenderer>(); | ||||
|         auto meshHost = playerItem->addComponent<MeshHost>(); | ||||
|         playerItem->addComponent<SimpleTexturedMaterial>(); | ||||
|         auto hitbox = playerItem->addComponent<CapsuleCollider>(); | ||||
|         playerItem->addComponent<CharacterController3D>(); | ||||
|         CapsuleMesh::create(&meshHost->mesh, hitbox->radius, hitbox->height); | ||||
|         auto hitbox = playerItem->addComponent<BoxCollider>(); | ||||
|         playerItem->addComponent<CharacterController2D>(); | ||||
|  | ||||
|         playerItem->transform.setLocalPosition(glm::vec3(0, 4, 0)); | ||||
|  | ||||
|         auto wall = this->createSceneItem(); | ||||
|         auto wallHitbox = wall->addComponent<CubeCollider>(); | ||||
|         // wall->transform.setLocalPosition(glm::vec3(-5, -1, -5)); | ||||
|         wallHitbox->min = -(wallHitbox->max = glm::vec3(5, 0.25f, 5)); | ||||
|         auto wallItem = this->createSceneItem(); | ||||
|         auto wallBox = wallItem->addComponent<BoxCollider>(); | ||||
|         wallBox->min = glm::vec2(-4, -3); | ||||
|         wallBox->max = glm::vec2(-3, 3); | ||||
|          | ||||
|         camera = Camera::create(this); | ||||
|         camera->transform->lookAt(glm::vec3(10, 10, 10), glm::vec3(0, 0, 0)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user