diff --git a/src/samples/dolphin/Makefile b/src/samples/dolphin/Makefile new file mode 100755 index 0000000..d59fe5e --- /dev/null +++ b/src/samples/dolphin/Makefile @@ -0,0 +1,65 @@ +EE_BIN = driver.elf + +EE_OBJS = \ + ../../engine/models/math/matrix.o \ + ../../engine/models/math/plane.o \ + ../../engine/models/math/point.o \ + ../../engine/models/math/vector3.o \ + ../../engine/models/mesh_frame.o \ + ../../engine/models/mesh_material.o \ + ../../engine/models/mesh.o \ + ../../engine/models/mesh_texture.o \ + ../../engine/modules/audio.o \ + ../../engine/modules/camera_base.o \ + ../../engine/modules/file_service.o \ + ../../engine/modules/gif_sender.o \ + ../../engine/modules/light.o \ + ../../engine/modules/pad.o \ + ../../engine/modules/renderer.o \ + ../../engine/modules/texture_repository.o \ + ../../engine/modules/timer.o \ + ../../engine/modules/vif_sender.o \ + ../../engine/utils/math.o \ + ../../engine/utils/string.o \ + ../../engine/loaders/bmp_loader.o \ + ../../engine/loaders/dff_loader.o \ + ../../engine/loaders/md2_loader.o \ + ../../engine/loaders/obj_loader.o \ + ../../engine/vu1_progs/draw3D.o \ + ../../engine/engine.o \ + camera.o \ + objects/player.o \ + driver.o \ + main.o + +EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ +EE_INCS := -I./../../engine/include $(EE_INCS) +EE_DVP = dvp-as +EE_VCL = vcl + +all: $(EE_BIN) + $(EE_STRIP) --strip-all $(EE_BIN) + mv $(EE_BIN) bin/$(EE_BIN) + rm $(EE_OBJS) + +# https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520 +#%.vsm: %.vcl # sudo service binfmt-support start +# $(EE_VCL) $< >> $@ + +%.o: %.vsm + $(EE_DVP) $< -o $@ + +clean: + rm -f $(EE_OBJS) + +run: $(EE_BIN) + killall -v ps2client || true + ps2client reset + ps2client reset + $(EE_STRIP) --strip-all $(EE_BIN) + mv $(EE_BIN) bin/$(EE_BIN) + rm $(EE_OBJS) + cd bin/ && ps2client execee host:$(EE_BIN) + +include $(PS2SDK)/samples/Makefile.pref +include $(PS2SDK)/samples/Makefile.eeglobal diff --git a/src/samples/dolphin/camera.cpp b/src/samples/dolphin/camera.cpp new file mode 100755 index 0000000..8ab5c12 --- /dev/null +++ b/src/samples/dolphin/camera.cpp @@ -0,0 +1,67 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "camera.hpp" + +#include + +const float CAMERA_Y = 15.0F; + + +Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up) +{ + verticalLevel = 80.0F; + up.x = 0.0F; + up.y = 1.0F; + up.z = 0.0F; +} + +Camera::~Camera() {} + +void Camera::update(Pad &t_pad, Mesh &t_mesh) +{ + rotate(t_pad); + followBy(t_mesh); + Vector3 lookPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z); + lookAt(lookPos); +} + +void Camera::rotate(Pad &t_pad) +{ + if (t_pad.rJoyH <= 50) + horizontalLevel -= 0.08; + else if (t_pad.rJoyH >= 200) + horizontalLevel += 0.04; + if (t_pad.rJoyV <= 50 && verticalLevel > 25.0F) + verticalLevel -= 0.9F; + else if (t_pad.rJoyV >= 200 && verticalLevel < 80.0F) + verticalLevel += 0.9F; + unitCirclePosition.x = (Math::sin(horizontalLevel) * verticalLevel); + unitCirclePosition.y = CAMERA_Y; + unitCirclePosition.z = (Math::cos(horizontalLevel) * verticalLevel); +} + +void Camera::followBy(Mesh &t_mesh) +{ + position.x = unitCirclePosition.x + t_mesh.position.x; + position.y = unitCirclePosition.y + t_mesh.position.y; + position.z = unitCirclePosition.z + t_mesh.position.z; + + if (position.x > (-0.04F * verticalLevel) && + position.x < 0.0F && + position.z > (0.998F * verticalLevel)) + { + // TODO + // position.x = 0.0F; + // position.y = 0.0F; + // position.z = 0.0F; + // horizontalLevel = 0.0F; + } +} \ No newline at end of file diff --git a/src/samples/dolphin/camera.hpp b/src/samples/dolphin/camera.hpp new file mode 100755 index 0000000..7bcbde3 --- /dev/null +++ b/src/samples/dolphin/camera.hpp @@ -0,0 +1,41 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _CAMERA_ +#define _CAMERA_ + +#include +#include +#include +#include +#include +#include + +class Camera : public CameraBase +{ + +public: + Vector3 position,up, unitCirclePosition; + float horizontalLevel, verticalLevel; + + Camera(ScreenSettings *t_screen); + ~Camera(); + + void update(Pad &t_pad, Mesh &t_mesh); + void rotate(Pad &t_pad); + void followBy(Mesh &t_mesh); + +protected: + Vector3 *getPosition() { return &position; }; + Vector3 *getUp() { return &up; }; + ScreenSettings screen; +}; + +#endif diff --git a/src/samples/dolphin/driver.cpp b/src/samples/dolphin/driver.cpp new file mode 100755 index 0000000..262f811 --- /dev/null +++ b/src/samples/dolphin/driver.cpp @@ -0,0 +1,48 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "driver.hpp" +#include "utils/math.hpp" + +Driver::Driver(Engine *t_engine) : engine(t_engine), camera(&engine->screen) +{ + +} + +Driver::~Driver() {} + +void Driver::onInit() +{ + engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes); + + texRepo = engine->renderer->getTextureRepository(); + + engine->renderer->disableVSync(); + + island.loadDff("sunnyisl/", "sunnyisl", 1.0F, false); + island.rotation.x = -1.6F; + island.position.set(0.0F, 10.0F, 20.0F); + island.shouldBeBackfaceCulled = true; + island.shouldBeFrustumCulled = false; + + texRepo->addByMesh("dolphin/",player.mesh); + texRepo->addByMesh("sunnyisl/",island); + + bulb.intensity=55; + bulb.position.set(5.0F,10.0F,10.0f); +} + +void Driver::onUpdate() +{ + player.update(engine->pad); + camera.update(engine->pad,player.mesh); + engine->renderer->draw(island); + engine->renderer->draw(player.mesh); +} diff --git a/src/samples/dolphin/driver.hpp b/src/samples/dolphin/driver.hpp new file mode 100755 index 0000000..ce25589 --- /dev/null +++ b/src/samples/dolphin/driver.hpp @@ -0,0 +1,45 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _DRIVER_ +#define _DRIVER_ + +#include +#include +#include +#include +#include +#include +#include "./camera.hpp" +#include "./objects/player.hpp" + + +class Driver : public Game +{ + +public: + Driver(Engine* t_engine); + ~Driver(); + + void onInit(); + void onUpdate(); + + Engine *engine; +private: + LightBulb bulb; + Player player; + Camera camera; + Mesh island; + TextureRepository *texRepo; + + +}; + +#endif diff --git a/src/samples/dolphin/main.cpp b/src/samples/dolphin/main.cpp new file mode 100755 index 0000000..4090b93 --- /dev/null +++ b/src/samples/dolphin/main.cpp @@ -0,0 +1,21 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "driver.hpp" + +int main() +{ + Engine engine = Engine(); + Driver game = Driver(&engine); + game.engine->init(&game,128); + SleepThread(); + return 0; + +} \ No newline at end of file diff --git a/src/samples/dolphin/objects/player.cpp b/src/samples/dolphin/objects/player.cpp new file mode 100755 index 0000000..851f372 --- /dev/null +++ b/src/samples/dolphin/objects/player.cpp @@ -0,0 +1,52 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "player.hpp" + +#include +#include +#include +#include +#include + +Player::Player() +{ + mesh.loadMD2("dolphin/","dolphin",0.05F,true); + mesh.shouldBeFrustumCulled = false; + mesh.position.set(0.0F,20.0F,-10.0f); + mesh.rotation.x = -1.6F; + mesh.setAnimSpeed(0.05F); +} + +Player::~Player() +{ + +} + +void Player::update(Pad& t_pad) +{ + velocity=0; + if(t_pad.lJoyV <= 100) + velocity=1; + else if(t_pad.lJoyV >= 200) + velocity=-1; + + if(t_pad.lJoyH >= 200) + mesh.rotation.z-=0.1; + else if(t_pad.lJoyH <= 100) + mesh.rotation.z+=0.1; + + if(velocity>0 && mesh.getCurrentAnimationFrame()==0) + mesh.playAnimation(0, 14); + + mesh.position.z+=Math::cos(mesh.rotation.z)*velocity; + mesh.position.x+=Math::sin(mesh.rotation.z)*velocity; + +} \ No newline at end of file diff --git a/src/samples/dolphin/objects/player.hpp b/src/samples/dolphin/objects/player.hpp new file mode 100755 index 0000000..b996c1c --- /dev/null +++ b/src/samples/dolphin/objects/player.hpp @@ -0,0 +1,32 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _PLAYER_ +#define _PLAYER_ + +#include "../camera.hpp" +#include +#include + +class Player +{ + +public: + float gravity, velocity; + Mesh mesh; + Player(); + ~Player(); + void update(Pad &t_pad); +private: + Vector3 playerNextPosition; + +}; + +#endif