Skip to content

Commit

Permalink
fixed flip issues, orb pulses, player upside down
Browse files Browse the repository at this point in the history
  • Loading branch information
adafcaefc committed Dec 6, 2024
1 parent aad5ee3 commit 6bd40e5
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 90 deletions.
24 changes: 17 additions & 7 deletions Geome3Dash/src/LevelDataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,19 @@ namespace g3d
nlohmann::json jsonData = data;
std::string jsonMsg = jsonData.dump();
msgLevelEncode(layer, jsonMsg);
//std::ofstream out("g3d.out.json");
//out << jsonMsg;

// debug
std::ofstream out("g3d.out.json");
out << jsonMsg;
}

LevelData LevelData::getDefault()
{
LevelData ld;
ld.x = -10;
ld.y = 5;
ld.z = 40;
ld.yaw = -55;
ld.x = -12;
ld.y = 6;
ld.z = 38;
ld.yaw = -100;
ld.pitch = -6;
//ld.bezierMultiplier = 1.0 / 3.0;
//ld.bezierCurve =
Expand All @@ -115,7 +117,15 @@ namespace g3d
// 0.412 * 6, 0.352 * 6
//};
ld.spline = Spline();
ld.spline.addSegment(Curve(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(2.0f, 0.0f, 0.0f), glm::vec3(3.0f, 0.0f, 0.0f)));
ld.spline.addSegment(Curve(
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(2.0f, 0.0f, 0.0f),
glm::vec3(3.0f, 0.0f, 0.0f)));
addNewCurveToSpline(&ld.spline);
addNewCurveToSpline(&ld.spline);
addNewCurveToSpline(&ld.spline);
addNewCurveToSpline(&ld.spline);
return ld;
}
}
1 change: 1 addition & 0 deletions Geome3Dash/src/game/editor/G3DCameraEditorPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ namespace g3d
&currentLevelData.spline,
&currentLevelData.keyframe,
&camera,
&light,
&lengthScaleFactor,
&isEditing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace g3d
// need to delete this on destructor (later)
splineTr = new SplineGameObjectTransformer(&ckel->spline, &ckel->lengthScaleFactor);
splinePlayerTr = new SplinePlayerObjectTransformer(&ckel->spline, &ckel->lengthScaleFactor);
splineCamTr = new SplineCameraPlayerObjectModelTransformer(&ckel->spline, &ckel->keyframeBuffer, &ckel->layer3d->camera, &ckel->lengthScaleFactor, &isEditing);
splineCamTr = new SplineCameraPlayerObjectModelTransformer(&ckel->spline, &ckel->keyframeBuffer, &ckel->layer3d->camera, &ckel->layer3d->light, &ckel->lengthScaleFactor, &isEditing);

CCObject* obj;
CCARRAY_FOREACH(ckel->lel->m_objects, obj)
Expand Down
108 changes: 55 additions & 53 deletions Geome3Dash/src/game/playing/G3DPlayLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace g3d

try { levelData = getLevelData(playLayer); } catch (...) { }

playerCameraOffset = glm::vec3(levelData.x, levelData.y, levelData.z);
playerCameraYawOffset = levelData.yaw;
playerCameraPitchOffset = levelData.pitch;
//playerCameraOffset = glm::vec3(levelData.x, levelData.y, levelData.z);
//playerCameraYawOffset = levelData.yaw;
//playerCameraPitchOffset = levelData.pitch;
//bezier = data.bezierCurve;
//constexpr double bezierM = 1000;
//bezier.cx1 *= bezierM;
Expand All @@ -49,6 +49,7 @@ namespace g3d
//bezierSegmentMultiplier = 1.0 / data.bezierMultiplier;

prepareSpline(playLayer, &levelData.spline, &lengthScaleFactor);
setStartingKeyframe(&levelData, &levelData.keyframe, lengthScaleFactor);

//bezierTr = new BezierGameObjectModelTransformer(bezier, bezierSegmentMultiplier, bezierSegmentCount);
fadeTr = new FadeGameObjectModelTransformer(playLayer, 700, 400, ease::InOutSine::get(), glm::vec3(0, 0, 0));
Expand All @@ -61,6 +62,7 @@ namespace g3d
&levelData.spline,
&levelData.keyframe,
&camera,
&light,
&lengthScaleFactor,
&isEditing);

Expand Down Expand Up @@ -183,57 +185,57 @@ namespace g3d
OpenGLStateHelper::pushState();
}

void G3DPlayLayer::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods) {
if (button == GLFW_MOUSE_BUTTON_RIGHT) {
if (action == GLFW_PRESS) {
isRightClicking = true;
isRightClickingGetPos = false;
}
else if (action == GLFW_RELEASE) {
isRightClicking = false;
}
}
}
//void G3DPlayLayer::onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods) {
// if (button == GLFW_MOUSE_BUTTON_RIGHT) {
// if (action == GLFW_PRESS) {
// isRightClicking = true;
// isRightClickingGetPos = false;
// }
// else if (action == GLFW_RELEASE) {
// isRightClicking = false;
// }
// }
//}

void G3DPlayLayer::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) {
if (isRightClicking) {
if (!isRightClickingGetPos) {
lastMouseX = static_cast<float>(x);
lastMouseY = static_cast<float>(y);
isRightClickingGetPos = true;
}
else {
float deltaX = static_cast<float>(x) - lastMouseX;
float deltaY = static_cast<float>(y) - lastMouseY;
if (isPressingControl) {
float sensitivity = 0.032f;
playerCameraOffset += camera.getUp() * deltaY * sensitivity;
playerCameraOffset += glm::normalize(glm::cross(camera.getFront(), camera.getUp())) * deltaX * -sensitivity;
}
else {
float sensitivity = 0.05f;
playerCameraYawOffset -= deltaX * sensitivity;
playerCameraPitchOffset -= deltaY * sensitivity;
}
lastMouseX = static_cast<float>(x);
lastMouseY = static_cast<float>(y);
}
}
}
//void G3DPlayLayer::onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y) {
// if (isRightClicking) {
// if (!isRightClickingGetPos) {
// lastMouseX = static_cast<float>(x);
// lastMouseY = static_cast<float>(y);
// isRightClickingGetPos = true;
// }
// else {
// float deltaX = static_cast<float>(x) - lastMouseX;
// float deltaY = static_cast<float>(y) - lastMouseY;
// if (isPressingControl) {
// float sensitivity = 0.032f;
// playerCameraOffset += camera.getUp() * deltaY * sensitivity;
// playerCameraOffset += glm::normalize(glm::cross(camera.getFront(), camera.getUp())) * deltaX * -sensitivity;
// }
// else {
// float sensitivity = 0.05f;
// playerCameraYawOffset -= deltaX * sensitivity;
// playerCameraPitchOffset -= deltaY * sensitivity;
// }
// lastMouseX = static_cast<float>(x);
// lastMouseY = static_cast<float>(y);
// }
// }
//}

void G3DPlayLayer::scrollWheel(float y, float x) {
// Adjust the camera zoom level using the scroll wheel
float zoomSensitivity = -0.128f;
playerCameraOffset += camera.getFront() * y * zoomSensitivity;
}
//void G3DPlayLayer::scrollWheel(float y, float x) {
// // Adjust the camera zoom level using the scroll wheel
// float zoomSensitivity = -0.128f;
// playerCameraOffset += camera.getFront() * y * zoomSensitivity;
//}

void G3DPlayLayer::onKey(enumKeyCodes key, bool pressed, bool holding) {
switch (key) {
case KEY_Control:
isPressingControl = pressed;
break;
default:
break;
}
}
//void G3DPlayLayer::onKey(enumKeyCodes key, bool pressed, bool holding) {
// switch (key) {
// case KEY_Control:
// isPressingControl = pressed;
// break;
// default:
// break;
// }
//}
}
14 changes: 7 additions & 7 deletions Geome3Dash/src/game/playing/G3DPlayLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ namespace g3d
// !! moved to block storage !!
//std::unordered_map<GameObject*, sus3d::Model*> blocks;
//std::unordered_map<int, sus3d::Model*> blockModels;
glm::vec3 playerCameraOffset;
double playerCameraYawOffset;
double playerCameraPitchOffset;
//glm::vec3 playerCameraOffset;
//double playerCameraYawOffset;
//double playerCameraPitchOffset;
CocosShaderProgram* shaderProgram;

//CubicBezier bezier;
Expand Down Expand Up @@ -117,10 +117,10 @@ namespace g3d

virtual void draw();

virtual void onKey(enumKeyCodes key, bool pressed, bool holding);
virtual void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods);
virtual void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
virtual void scrollWheel(float y, float x);
//virtual void onKey(enumKeyCodes key, bool pressed, bool holding);
//virtual void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int mods);
//virtual void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
//virtual void scrollWheel(float y, float x);

friend class BezierCameraPlayerObjectModelTransformer;
friend class SplineCameraPlayerObjectModelTransformer;
Expand Down
10 changes: 10 additions & 0 deletions Geome3Dash/src/helper/spline/Spline.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ namespace g3d

Spline() {}
};

// adaf additions
inline void addNewCurveToSpline(Spline* spline)
{
auto p1 = spline->segments.back().p2;
auto m1 = spline->segments.back().p2 * 2.f - spline->segments.back().m2;
auto m2 = spline->segments.back().p2 * 2.f - spline->segments.back().m1;
auto p2 = spline->segments.back().p2 * 2.f - spline->segments.back().p1;
spline->addSegment(Curve(p1, m1, m2, p2));
}
}
15 changes: 13 additions & 2 deletions Geome3Dash/src/transformer/AnimationGameObjectModelTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ namespace g3d
{
void AnimationGameObjectModelTransformer::transform(GameObjectModel* gom)
{
auto block = gom->getGameObject();
auto scale = gom->getScale();
// do animations
switch (gom->getGameObject()->m_objectID)
switch (block->m_objectID)
{
case 142:
case 36:
case 84:
case 141:
case 1022:
case 1330:
case 1333:
case 1704:
case 1751:
gom->setScaleY(scale.y / block->m_scaleY * block->getScaleY());
gom->setScaleZ(scale.z / block->m_scaleX * block->getScaleX());
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ namespace g3d
auto newR = pom->getRotation();
auto playerYaw = newR.y;
auto playerYawR = -glm::radians(playerYaw);
const auto playerCameraOffset = playLayer3d->playerCameraOffset;
const auto playerCameraYawOffset = playLayer3d->playerCameraYawOffset;
const auto playerCameraPitchOffset = playLayer3d->playerCameraPitchOffset;
//const auto playerCameraOffset = playLayer3d->playerCameraOffset;
//const auto playerCameraYawOffset = playLayer3d->playerCameraYawOffset;
//const auto playerCameraPitchOffset = playLayer3d->playerCameraPitchOffset;

glm::vec3 rotatedOffset =
{
playerCameraOffset.x * std::cos(playerYawR) - playerCameraOffset.z * std::sin(playerYawR),
playerCameraOffset.y,
playerCameraOffset.x * std::sin(playerYawR) + playerCameraOffset.z * std::cos(playerYawR)
};
//glm::vec3 rotatedOffset =
//{
// playerCameraOffset.x * std::cos(playerYawR) - playerCameraOffset.z * std::sin(playerYawR),
// playerCameraOffset.y,
// playerCameraOffset.x * std::sin(playerYawR) + playerCameraOffset.z * std::cos(playerYawR)
//};

playLayer3d->camera.setPosition(playerPos + rotatedOffset);
// Clamp pitch to prevent flipping
playLayer3d->camera.setYaw(playerCameraYawOffset - playerYaw);
auto pitch = std::clamp(static_cast<float>(playerCameraPitchOffset), -89.0f, 89.0f);
playLayer3d->camera.setPitch(pitch);
//playLayer3d->camera.setPosition(playerPos + rotatedOffset);
//// Clamp pitch to prevent flipping
//playLayer3d->camera.setYaw(playerCameraYawOffset - playerYaw);
//auto pitch = std::clamp(static_cast<float>(playerCameraPitchOffset), -89.0f, 89.0f);
//playLayer3d->camera.setPitch(pitch);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace g3d
auto cameraState = buffer->getInterpolatedCameraKeyframe(pom->getPlayerObject()->getPositionX());
camera->setPosition(getPlayerOrientedCameraPosition(pom) + cameraState.offset);
camera->setFront(getPlayerOrientedCameraFront(pom) + cameraState.front);

light->setPosition(camera->getPosition());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace sus3d
{
class Camera;
class Light;
}

namespace g3d
Expand All @@ -19,18 +20,21 @@ namespace g3d
Spline* spline;
CameraKeyframeBuffer* buffer;
sus3d::Camera* camera;
sus3d::Light* light;
float* lengthScaleFactor;
bool* isEditing;
virtual void transform(GameObjectModel* gom) override;
SplineCameraPlayerObjectModelTransformer(
Spline* spline,
CameraKeyframeBuffer* buffer,
sus3d::Camera* cam,
sus3d::Light* lght,
float* lcf,
bool* isEditing)
: spline(spline)
, buffer(buffer)
, camera(cam)
, light(lght)
, lengthScaleFactor(lcf)
, isEditing(isEditing)
{
Expand Down
4 changes: 2 additions & 2 deletions Geome3Dash/src/transformer/SplineGameObjectTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace g3d
gom->setRotation(eulerDegrees);
gom->setScale(glm::vec3(
0.5 * (block->m_startFlipX ? -1 : 1) * (*lengthScaleFactor) * 30,
0.5 * (block->m_startFlipY ? -1 : 1) * (*lengthScaleFactor) * 30 * block->getScaleY(),
0.5 * (*lengthScaleFactor) * 30 * block->getScaleX()));
0.5 * (block->m_startFlipY ? -1 : 1) * (*lengthScaleFactor) * 30 * block->m_scaleY,
0.5 * (block->m_startFlipX ? -1 : 1) * (*lengthScaleFactor) * 30 * block->m_scaleX));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace g3d
gom->setRotation(eulerDegrees);
gom->setScale(glm::vec3(
0.5 * (player->m_startFlipX ? -1 : 1) * (*lengthScaleFactor) * 30,
0.5 * (player->m_startFlipY ? -1 : 1) * (*lengthScaleFactor) * 30 * scale,
0.5 * (player->m_isUpsideDown ? -1 : 1) * (*lengthScaleFactor) * 30 * scale,
0.5 * (*lengthScaleFactor) * 30 * scale));
}
}
Expand Down
3 changes: 1 addition & 2 deletions bin/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Geome3Dash

![titlebar](screenshots/gp1.jpg)
![gp1](screenshots/gp1.jpg)

**Geome3Dash** transforms the 2D Geometry Dash you know and love into an exciting, open-source 3D experience. Jump into a new dimension of gameplay, customize levels like never before, and explore the adventure of a lifetime.

Expand Down Expand Up @@ -39,7 +39,6 @@ Have suggestions or need help? Connect with developers and fans on our [Discord

## Screenshots

![gp1](screenshots/gp1.jpg)
![gp2](screenshots/gp2.png)
![world1](screenshots/world1.png)
![world2](screenshots/world2.png)
Expand Down

0 comments on commit 6bd40e5

Please sign in to comment.