Jump to content

Paul Thomas

Members
  • Posts

    339
  • Joined

  • Last visited

Posts posted by Paul Thomas

  1. 9 hours ago, reepblue said:

    Why would you make a class for the sky? Just use world->SetSkybox().

    Also, don't use delete with Leadwerks entities. You would use Release() but the world class does this for you and you'll run into crashes if you try to manage entities on your own.

    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.

     

    • Like 2
  2. 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!

    • Like 1
  3. 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;

     

  4. 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!

  5. 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.

  6. So its you. I have donated some time ago, so i can download the source code, what you are doing here? :0) Yes i have finished the whole tutorial as well.

    Excellent, thank you for your donation.

     

    I was using Leadwerks before UDK had released. On rainy days or one of those days you want to break routine I work a bit on LE from time to time.

     

    For your bones issue, all there is left to do is import them into an application of some type, like Blender. You can evaluate the bones there. Other than that I'm not sure what your real motive is beyond bones and the reason of your original question.

  7. Weapons are skeletal meshes (skinned meshes/animated meshes/whatever) in UDK because they are animated and you use sockets to attach the weapon to other actors and to attach actors to weapons. Sockets are basically entities parented to a bone that can share the bones local translation/rotation or a global translation/rotation (plus an offset value if desired). We have provided a tutorial on weapons in UE3 but you may find the video modeling and animation tutorials useful: www.magicstonestudios.com/tutorials

     

    You should name your bones once and keep the same rig going so that it's consistent for multiple projects. This way a pistol will fit in in two separate meshes (as long as they too share consistent bone names), otherwise do as you please, it depends on your project and how many weapons you plan to have in your game.

     

    Hopefully that helps. I'm sure others can provide advice from an artists perspective.

  8. Depends on how important those beams are to the player. If they are expected to get in close then you should probably model them unless it's a shallow beam and is more flush to the wall, then you could get away with texture and bump mapping.

  9. That's what it boils down to, Valve evading the job of going through applications, and now you pay them. I'm hoping this greenlight just dies off but I doubt it. Greenlight and free to play can both disappear.

     

    EDIT: To top it off, they started this whole thing, with a buggy ranking system; you know, the most important part of this whole idea. Way to rush.

  10. 1) Not inherit, you have to do the work yourself.

    2) Only one terrain is supported (4096 height map). If you need larger or more, you'll have to use meshes.

    3) You will always have a draw call limit no matter what engine. Most engines use distance culling for this reason. I would say 1k objects/entities at once is safe, possibly up to 5k, but that's not good design behavior.

    4) Haven't seen an engine yet that you couldn't change simple options such as paths. To an extent, yes, LE lets you customize.

    5) No

    6) It does the job but it's missing some features. One feature it's missing is an undo/redo. A lot of LE2 members have built their own editors and/or tools, but not everyone needs more than what the editor provides. Depends on your project.

     

    Last I checked the demo is outdated by several minor versions but there are bugs that still exist, mostly ignored since LE3 started development, and I wouldn't count on any major LE2 updates.

  11. That night town looks great. Nothing bad to say about that scene at all, even the sky has it's own taste with a bit of humor. Great job, I like it a lot.

     

    Definitely an improvement in quality compared to EP1 (tweaked shaders all around?), great job on that. EP2 in three months? That's quick for a second episode to release, good luck to you and your team man. Let me know if you ever need a hand with something.

×
×
  • Create New...