-
Posts
339 -
Joined
-
Last visited
Paul Thomas's Achievements
-
-
This is some great progress!
-
Ah, thanks! I love learning new things every day. I didn't even know world->SetSkybox() exists either. It's not on here: https://www.leadwerks.com/learn?page=API-Reference_Object_World I need to start relying on just reading the headers LOL Also, for my purposes, I will soon be doing a lot more than just a skybox. Day/night cycles, weather, clouds, etc.. I want the sky to be completely responsible.
-
SpiderPig started following Paul Thomas
-
Copy and pasted as-is, edit for your purposes, this is a direct recode (with minor additions) of the provided LUA script. #pragma once #include "Leadwerks.h" using namespace Leadwerks; class Spectator { private: // context width int width = 1024; // context height int height = 768; // parent Entity* parent = nullptr; // camera Camera* camera = nullptr; public: Spectator() {} Spectator(int _width, int _height) : width(_width), height(_height) {} Spectator(int _width, int _height, Entity* _parent) : width(_width), height(_height), parent(_parent) {} Spectator(int _width, int _height, Camera* _camera) : width(_width), height(_height), camera(_camera) {} Spectator(int _width, int _height, Camera* _camera, Entity* _parent) : width(_width), height(_height), camera(_camera), parent(_parent) {} void Create() { camera = Camera::Create(); } void Create(Entity* _parent) { parent = _parent; camera = Camera::Create(_parent); } void Create(int _width, int _height) { width = _width; height = _height; camera = Camera::Create(); } void Create(int _width, int _height, Entity* _parent) { width = _width; height = _height; parent = _parent; camera = Camera::Create(_parent); } void Create(int _width, int _height, Camera* _camera) { width = _width; height = _height; camera = _camera; } void SetWidth(int _width) { width = _width; } int GetWidth() { return width; } void SetHeight(int _height) { height = _height; } int GetHeight() { return height; } void SetDimensions(Vec3 dimension) { width = dimension.x; height = dimension.y; } Vec2 GetDimensions() { return Vec2(width, height); } void SetParent(Entity* _parent) { parent = _parent; } Entity* GetParent() { return parent; } void SetCamera(Camera* _camera) { camera = _camera; } Camera* GetCamera() { return camera; } private: bool enabled = true; Vec2 center = Vec2(0.0f, 0.0f); Model* spectator; public: float moveSpeed = 5.0f; float maxSpeed = 50.0f; float speedStep = 5.0f; float moveSmoothing = 0.3f; float radius = 0.5f; float lookSpeed = 0.1f; float lookSmoothing = 0.5f; Vec3 mousePos = Vec3(0.0f, 0.0f, 0.0f); Vec3 cameraRot = Vec3(0.0f, 0.0f, 0.0f); virtual void Initialize() { if (camera == nullptr) { Create(width, height); } center = Vec2(width * 0.5f, height * 0.5f); mousePos = Vec3(center.x, center.y, 0.0f); cameraRot = camera->GetRotation(); spectator = Model::Sphere(8); spectator->SetMass(10.0f); spectator->SetGravityMode(false); spectator->SetBuoyancyMode(false); spectator->SetCollisionType(Collision::Projectile); spectator->SetShadowMode(0); spectator->SetFriction(0.0f, 0.0f); spectator->SetElasticity(0.0f); spectator->SetSweptCollisionMode(true); camera->SetPosition(spectator->GetPosition()); camera->SetParent(spectator); } virtual void Update(Window* window) { if (window == nullptr) return; // debug if (window->KeyDown(Key::F1)) { enabled = !enabled; } if (window->KeyDown(Key::F2)) { camera->SetDebugEntityBoxesMode(!camera->GetDebugEntityBoxesMode()); } if (window->KeyDown(Key::F3)) { camera->SetDebugPhysicsMode(!camera->GetDebugPhysicsMode()); } if (!enabled) return; Vec3 mpos = window->GetMousePosition(); window->SetMousePosition(center.x, center.y); mpos = mpos * lookSmoothing + mousePos * (1 - lookSmoothing); float dx = (mpos.x - center.x) * lookSpeed; float dy = (mpos.y - center.y) * lookSpeed; cameraRot.x = cameraRot.x + dy; cameraRot.y = cameraRot.y + dx; mousePos = mpos; Vec3 move = Vec3(0.0f, 0.0f, 0.0f); if (window->KeyDown(Key::W) || window->KeyDown(Key::Up)) { move.z += moveSpeed; } if (window->KeyDown(Key::S) || window->KeyDown(Key::Down)) { move.z -= moveSpeed; } if (window->KeyDown(Key::D) || window->KeyDown(Key::Right)) { move.x += moveSpeed; } if (window->KeyDown(Key::A) || window->KeyDown(Key::Left)) { move.x -= moveSpeed; } if (window->KeyDown(Key::Q) || window->KeyDown(Key::Space) || window->KeyDown(Key::PageDown)) { move.y += moveSpeed; } if (window->KeyDown(Key::E) || window->KeyDown(Key::ControlKey) || window->KeyDown(Key::PageUp)) { move.y -= moveSpeed; } if (window->KeyDown(Key::Shift)) { moveSpeed = maxSpeed; } else { moveSpeed = 5.0f; } Vec3 velocity = spectator->GetVelocity(false); Vec3 desired = Vec3(move.x, 0.0f, move.z) + Transform::Vector(0.0f, move.y, 0.0f, nullptr, spectator); spectator->AddForce((desired - velocity) * spectator->GetMass() / moveSmoothing, false); spectator->PhysicsSetRotation(cameraRot); } virtual ~Spectator() { delete camera; } virtual void Enable() { enabled = true; } virtual void Disable() { enabled = false; } }; I will edit the class later if needed. Cheers!
-
You are setting the mouse position to center with this line: window:SetMousePosition(cx, cy) If you have game logic that needs to stop the mouse from being forced to center, then you need to encapsulate this line with that logic.
-
-
I found the Leadwerks Wikidot again, here: http://leadwerks.wikidot.com/
-
A buddy asked me about the Skybox in my latest blog screenshots. As I had mentioned to him, credit is not mine, I found it perusing the API documents. I'm sure it's somewhere on the forums, but I'm pasting my C++ conversion here. At the time (apparently July 16th) I had shared the code on the "Leadwerks Community Wiki" but my ignorant self had a hard time finding the link again. Please clean this up for your own purposes. This code is an exact copy conversion from the LUA code written by .. not sure .. probably Josh? class Sky { private: Model* sky; Surface* surface; Material* material; public: Sky(Camera* camera) : sky(nullptr), surface(nullptr), material(nullptr) { sky = Model::Create(); surface = sky->AddSurface(); surface->AddVertex(-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddVertex(0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddVertex(0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddVertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddTriangle(2, 1, 0); surface->AddTriangle(0, 3, 2); sky->SetPosition(camera->GetPosition()); sky->SetRotation(camera->GetRotation()); sky->Move(0.0f, 0.0f, camera->GetRange().y - 50.0f); sky->SetScale(camera->GetRange().y * 10.0f); sky->SetParent(camera); material = Material::Load("Materials/Sky/skybox_texture.mat"); sky->SetMaterial(material); } virtual ~Sky() { delete material; delete surface; delete sky; } inline Model* GetSky() { return sky; } inline void SetSky(Model* mesh) { sky = mesh; } inline Surface* GetSurface() { return surface; } inline void SetSurface(Surface* face) { surface = face; } inline Material* GetMaterial() { return material; } inline void SetMaterial(Material* mat) { material = mat; } }; A camera must be provided as seen in the original LUA code. Here is an example: Camera* camera = Camera::Create(); Sky* sky = new Sky(camera); Remember to delete the sky when the game loop is closed. delete sky; The "Materials/Sky/skybox_texture.mat" and texture "Materials/Sky/skybox_texture.tex" is already provided by Leadwerks. This is not for Ultra Engine. Sharing a snippet library doesn't sound like a bad idea. Cheers P.S. I was going to attach a .zip file with my personal "sky.h" file, but I decided to paste here directly (no need to download a .zip for a single file - no, I did NOT try uploading just the H file, I'm just pushing forward at this point): // LEADWERKS 4 / STEAM LEADWERKS C++ // https://leadwerks.com // https://ultraengine.com #pragma once #include "Leadwerks.h" using namespace Leadwerks; // SKY class Sky { private: // skybox mesh Model* sky; // skybox surfaces Surface* surface; // skybox material - @edit: change line 38 to include your own material Material* material; // camera Camera* camera; // material path std::string materialPath; public: // SKY //@notes: A camera is required //@params: CAMERA Sky(Camera* icamera) : sky(nullptr), surface(nullptr), material(nullptr), camera(icamera), materialPath("Materials/Sky/skybox_texture.mat") { Initialize(); } // SKY //@params: CAMERA, string MATERIAL PATH Sky(Camera* icamera, const std::string& ipath) : sky(nullptr), surface(nullptr), material(nullptr), camera(icamera), materialPath(ipath) { Initialize(); } // destructor virtual ~Sky() { delete material; delete surface; delete sky; } // get/set functions inline Model* GetSky() { return sky; } inline void SetSky(Model* mesh) { sky = mesh; } inline Surface* GetSurface() { return surface; } inline void SetSurface(Surface* face) { surface = face; } inline Material* GetMaterial() { return material; } inline void SetMaterial(Material* mat) { material = mat; } private: // Initialize Sky void Initialize() { sky = Model::Create(); surface = sky->AddSurface(); surface->AddVertex(-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddVertex(0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddVertex(0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddVertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f); surface->AddTriangle(2, 1, 0); surface->AddTriangle(0, 3, 2); sky->SetPosition(camera->GetPosition()); sky->SetRotation(camera->GetRotation()); sky->Move(0.0f, 0.0f, camera->GetRange().y - 50.0f); sky->SetScale(camera->GetRange().y * 10.0f); sky->SetParent(camera); material = Material::Load(materialPath); sky->SetMaterial(material); } }; // Example: // Camera* camera = Camera::Create(); // Sky* skybox = new Sky(camera); // If you have a custom material use: // std::string material_path = "path/to/skybox/material.mat"; // Sky* skybox = new Sky(camera, material_path); // // Do not forget to delete when the game loop ends with: delete sky;
-
Hello! This blog was created in 2012, but here I am resurrecting it. The option to create a new blog disappeared when I deleted another old blog that had no articles. Anyways, please ignore the previous entries, because they are really old and outdated. The code shown in those blogs do not work with LE 4, and I don't even think I have the engine that was released around 2012. To catch up a bit; back then I ended up doing contract work with various game engines, then getting the job/career I have now, and I work on personal 2D/3D projects when I get the time. Time is expensive lately, and I'm sure it is for most. I had no work and a large web related contract fell through, and I ended up purchasing Leadwerks on Steam. I was in the middle of finding random new engines or rendering libraries I've never tried before. I saw Leadwerks during the sale, made my purchase on July 7th, and started reading the API. I got nostalgic reading the API and tutorials. Leadwerks 2 with BlitzMax. It was excellent. During those times I had a "Blogger" blog showing my progress learning the engine. I made a bunch of post-process shaders (which I actually need to do again), a day and night cycle, dynamic clouds, and so forth. Great times. So, I started another blog. Laziness and lack of time prevented me from also writing here. I wasn't sure when I started if I would even make a game. I'm still not sure. My day job is fairly relaxed right now, but it often jumps into 12 hour days at times during the Summer. Maybe I can get myself to keep returning even if I only have 30 minutes of time available. Now, to explain the map used as my Featured Photo. That is the result of my Biome Generator. Technically, it's just written in C++, but overall it's for a Leadwerks project. You can think of it as a Minecraft clone, but I don't like the word "clone." I will have custom gameplay, points of interest, and so on. I don't have a copy of Minecraft source code either, so my results are from trial and error. Procedurally generated terrain is the shared major difference, and the decision to use blocky art. The biome map shown is actually seed #18446744073709551614 (not joking) and is 2048x2048. This is roughly 8 regions worth (8 chunks, and each chunk has 16 blocks) and has 40 different biomes, which include mixed/blended biomes, and generated under the constraints of a temperature map. If you look closely, it includes rivers, ponds, even beaches and coasts. You can read more detail about those development days here: https://leadwerks-scavenge.blogspot.com/2023/07/biome-generation.html The attached images are the results from development yesterday into this morning (date of this blog posted - yes, I'm tired). It's entirely experimental, but it's basically what I want. I need caves under the ground, and in the end it looks like several layers of caves in a single 16x16 chunk.. I think. At the end I threw in some textures so it wasn't just white. I have a LOT of work to do to add all of the block types. Thanks to SpiderPig for the SimplexNoise library! If you want to read the details you can here: https://leadwerks-scavenge.blogspot.com/2023/07/3d-landscapes.html Starting on the next blog I will write it on Leadwerks first, and then copy & paste over to Blogger. I may just leave Blogger out of it from now on. Thanks for reading! P.S. The game name is "Scavenge." The name "Scavenge" is actually the name of a game I had designed on paper meant for a post-apocalyptic world. It's too ambitious for a single person with no extra budget. I'm stealing the name from myself for this project.
-
Voxel Terrain Part 3 - Dynamic Components
Paul Thomas commented on SpiderPig's blog entry in The Seventh World
Very nice! -
Oh yeah, sol is way easier. Thanks
-
I apologize if this has already been answered, but the answers I've found don't seem to work. The answers are also from 2015 if I'm not mistaken, and I tried those answers in multiple ways to expose a C++ class to LUA. How do we expose C++ classes to LUA? Thanks!
-
You're welcome man. I'm glad I was able to help.
-
I am interested in trying this with my DK2. Anyone tried with the latest build and Oculus version/drivers/etc? Thanks
-
I voted on an RTS because it can give everyone plenty of features and would consume less time than a full RPG. I would have said vehicles because they don't exist yet, but I was thinking that a game template for vehicles wouldn't be as important as documentation and an example vehicle for a newly releasing feature. Learn the vehicle instead of the template or the game. My second vote would be RPG if you have the time and resources.