Jump to content

Search the Community

Showing results for tags 'C++'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Categories

  • Models
    • Animals
    • Barriers
    • Characters
    • Containers
    • Environments
    • Furniture
    • Props
    • Rocks
    • Vegetation
    • Vehicles
    • Weapons
  • Materials
    • Brick
    • Cartoon
    • Decals
    • Dirt
    • Grass
    • Industrial
    • Medieval
    • Metal
    • Plastic
    • Plaster
    • Rock
    • SciFi
    • Sky
    • Signs
    • Tile
    • Stone
    • Walls
    • Wood
  • Scripts
    • GUI
    • Object
    • Utilities
  • Shaders
    • Post-Processing Effects
    • Surface
  • Sounds
    • Ambience
    • Effects
    • Music
  • Tools
  • BATTLE LEAGUE's Assets
  • BATTLE LEAGUE's Mods

Blogs

There are no results to display.

There are no results to display.

Forums

  • Leadwerks
    • Technical Assistance
    • General Discussion
    • Programming
    • Game Art
    • Suggestion Box
    • Bug Reports
  • Platforms
    • Windows
    • Mac
    • Linux
  • Community
    • Showcase
    • Promotion
    • Off-topic
  • BATTLE LEAGUE's Topics
  • Vec-Tec's Releases
  • Vec-Tec's Topics
  • Forth's Development
  • Forth's Game design
  • Forth's Graphics
  • Forth's Documentation
  • Forth's TODO
  • Forth's IMPORTANT
  • Forth's Screenshots
  • The uncertain world's Game Design
  • The uncertain world's Programming
  • The uncertain world's TODO
  • The uncertain world's Graphics
  • The uncertain world's Screenshots

Categories

  • Records
  • Entity
  • Command Reference
  • Vec3
  • Vec4
  • Script Reference
  • Shader
  • Index
  • Material
  • Object
  • Buffer
  • Asset
  • Font
  • Shape
  • Sound
  • Texture
  • App
  • Context
  • Model
  • Light
  • DirectionalLight
  • PointLight
  • SpotLight
  • Attractor
  • Camera
  • Emitter
  • Listener
  • Pivot
  • Bone
  • Sprite
  • FileSystem
  • Key
  • Source
  • Surface
  • Math
  • AABB
  • dVec3
  • Mat3
  • Mat4
  • Plane
  • Transform
  • Vec2
  • Vec3
  • Vec4
  • Mutex
  • Prefab
  • PickInfo
  • Map
  • Stream
  • System
  • Thread
  • Time
  • Window
  • World
  • Driver
  • SoundDriver
  • GraphicsDriver
  • PhysicsDriver
  • OpenGL2GraphicsDriver
  • OpenGLES2GraphicsDriver
  • OpenALSoundDriver
  • NewtonDynamicsPhysicsDriver
  • Draw
  • Color
  • Blend
  • Joint
  • Debug
  • Component
  • Steamworks
  • LensFlare
  • Vehicle
  • Decal
  • Quat
  • Leaderboard
  • Probe
  • Analytics

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


Interests

Found 308 results

  1. khotan

    Fracture ?

    Can i create a fracture sim based with voronoi in Leadwerks that control over on vertices or edges ? is it possible ? Lua or C++?
  2. Hi. I want to load the player entity position from an object in the editor. It works very well but; I want to spawn in the center of the scene when there is no object named "info_player_start". When I remove the comment lines, it always spawns at the center of the scene. I don't understand why. Here is my code... #include "Game.h" Game::Game() { loadMap(); loadEntities(); player = new Player(playerStartPosition); } Game::~Game() { delete player; } void Game::loadMap() { std::string mapname = System::GetProperty("map", "Maps/start.map"); if (!Map::Load(mapname)) Debug::Error("Failed to load map \"" + mapname + "\"."); } void Game::loadEntities() { for (const auto e : World::GetCurrent()->entities) { if (e->GetKeyValue("name") == "info_player_start") { playerStartPosition = e->GetPosition(); } /*else { playerStartPosition = Vec3(0.0f, 0.0f, 0.0f); }*/ } } void Game::Update() { player->Update(); }
  3. Hello, is it just me or are prefabs broken inside Leadwerks 3.0 ? I am not able to create any prefab that does not crash the editor and my application. My application will crash with the following error: The exception is thrown inside Prefab::Load(): Entity* entity = Prefab::Load("asd.pfb"); The Leadwerks editor crashes as soon as trying to open the prefab with ACCESS_VIOLATION. The documentation seems to be wrong too for the prefab class. I have not been able to find the "static const int NoStartCall" member inside it. I attached a prefab that is causing the error stated above. Thank you. asd.zip
  4. I create a collision patch for my terrain on the fly with the following code which increases the memory usage over time. Commenting out creating the shape seams to stop it. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* box; Camera* camera; bool wireframe = false; bool App::Start() { window = Window::Create("PolyMesh",50,50, 1024, 768); window->Show(); context = Context::Create(window); world = World::Create(); DirectionalLight* light = DirectionalLight::Create(); light->SetRotation(35, 35, 35); camera = Camera::Create(); box = Model::Box(); box->Move(0, 0, 2); return true; } bool App::Loop() { if (window->KeyHit(Key::Escape) == true) { return false; } if (window->KeyHit(Key::F1) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); } if (window->KeyHit(Key::F2) == true) { if (wireframe == true) { camera->SetDrawMode(0); wireframe = false; } else { camera->SetDrawMode(2); wireframe = true; } } Vec3 rot = box->GetRotation(); rot.x += 0.2f; rot.y += 0.2f; rot.z += 0.2f; box->SetRotation(rot); //Make a collsion surface on the fly for terrain/////////////////// int xGrid = 3; int zGrid = 3; int vertIndex = 0; Surface* surface = Surface::Create(); for (int z = 0; z < zGrid; z++) { for (int x = 0; x < xGrid; x++) { surface->AddVertex(x, 0.0f, z); if (z != 0 && x != 0) { surface->AddTriangle(vertIndex, vertIndex - xGrid, vertIndex - 1); surface->AddTriangle(vertIndex - xGrid, vertIndex - xGrid - 1, vertIndex - 1); } vertIndex++; } } Shape* shape = Shape::PolyMesh(surface);//memory leak here? //box->SetShape(shape); shape->Release(); surface->Release(); ////////////////////////////////////////////////////////////////////// Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->DrawStats(10.0f, 10.0f, true); context->Sync(true); return true; }
  5. Here is how i made it possible to call C++ from LUA. I want to build Multiplayer game in Leadwerks. But i couldn't find networking libraries and threading libraries that would make it usable in Lua. So i build a Networking client in C++ with libcurl and libpthread . But i want to still use the Lua scripting on the prefabs since a lot of work is already done for me here. And also programming in Higher level languages is just faster. I decided to use the libtolua++ libraries, since this is already build into Leadwerks. I work on Ubuntu 15.04. Here the tolua++ libs are installed with: sudo apt-get install libtolua++5.1-dev The tolua++ program needs a pck file which shall contain the c++ like seudo code that is translated into lua classes. My package: $#include "shot.h" class ShotListener { ShotListener(); ~ShotListener(); void shot(Object* oEntity, float damage); float getHealth(Object* oEntity); }; I have made two functions. One to emit shots detected on the Entities from the Lua scripting. Another to get the current health status from C++ side. My actual ShotListener.h class looks like this: #pragma once #include "App.h" #include "Leadwerks.h" using namespace Leadwerks; class ShotListener { private: public: ShotListener(void) { } ~ShotListener(void){} void shot(Object* oEntity, float damage) { App *app = App::getInstance(); Entity * entity = (Entity*)oEntity; app->entityShot(entity, damage); return; } float getHealth(Object* oEntity) { App *app = App::getInstance(); Entity * entity = (Entity*)oEntity; float value = app->getEntityHealth(entity); return value; } }; As you can see i changed the default App class into a Singleton so that i can get the App object from the instances of ShotListener that is used from Lua. Having placed these two files in the same folder i ran the following function from the terminal: tolua++5.1 -o tolua_shot.cpp -H tolua_shot.h -n Shot shot.pkg This generated two files tolua_shot.cpp and tolua_shot.h that i included in my C++ project along with the shot.h file. This way i can do a self.shotListener = ShotListener:new() In the Script:Start() function in mu Lua objects and a self.shotListener:shot(self.entity, self.hits) When Hurt is called in the Lua object. After this i just had to sort out all the Segmentation error bugs because of multithreading. I forgot to mention that the ShotListener Lua also needs to be initialized in the main.cpp before app->Start() with the following: if (Interpreter::L==NULL) Interpreter::Reset(); tolua_ShotListener_open(Interpreter::L);
  6. Does any one know how to get a normal that will tell the general direction all the vertices of an object lay in? Like an average position, but as a normal... any one got any ideas?
  7. PickInfo.triangle returns -1 for me, and PickInfo.face is NULL. This is my code; Vec3 _mPos = window->GetMousePosition(); PickInfo _pickInfo; if (camera->Pick(_mPos.x, _mPos.y, _pickInfo, 0.01f, true) == true) { int _index = _pickInfo.triangle; auto _face = _pickInfo.face; } Is there a way to get this data?
  8. Is it possible to change a window between full-screen and windowed mode while it is running? Can the full-screen window be created and then set as the default, then the old window deleted? 🤔
  9. How can I check if the Steam Overlay is active? I can't see anything that looks relevant under the Steamworks class.
  10. I'm loading a few data files in c++ and have included these files in the publishing process (below) lod, data and strc are just binary files. lua, mat, mdl, phy, shader, tex, ttf, wav, ogg, mpd, cfg, lod, dat, strc Am I correct in saying that loading with ordinary commands like fopen_s() won't be able to access the encrypted files in data.zip? I can think of a few workarounds, like not including those files in the data.zip and adding them manually after publishing (won't be encrypted but it's not really needed for these I guess), or maybe using the internal Leadwerks file commands? Is there a way the publisher can change or retrieve the password used for encryption?
  11. I have a large world and there are heights exceeding 2000m, this quick code example shows that at a height higher than 660m the shadow disappears but interestingly the stats still say it's being drawn. Can anyone else confirm this? Is there shadow range for the world or something or is this a bug? #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* box; Camera* camera; bool wireframe = false; bool App::Start() { window = Window::Create("Shadows",50,50, 1024, 768); window->Show(); context = Context::Create(window); world = World::Create(); DirectionalLight* light = DirectionalLight::Create(); light->SetRotation(35, 35, 35); float offsetY = 670.0f;//Increase to 670.0f and shadow disapears. camera = Camera::Create(); camera->Move(0, 1 + offsetY, -2); box = Model::Box(); box->Move(0, 1 + offsetY, 0); Pivot* centre = Pivot::Create(); int xGrid = 3; int zGrid = 3; int vertIndex = 0; Model* mdl = Model::Create(); Surface* surface = mdl->AddSurface(); for (int z = 0; z < zGrid; z++) { for (int x = 0; x < xGrid; x++) { surface->AddVertex(x, offsetY, z,0,1,0); if (z != 0 && x != 0) { surface->AddTriangle(vertIndex, vertIndex - xGrid, vertIndex - 1); surface->AddTriangle(vertIndex - xGrid, vertIndex - xGrid - 1, vertIndex - 1); } vertIndex++; } } surface->Update(); mdl->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB); return true; } bool App::Loop() { if (window->KeyHit(Key::Escape) == true) { return false; } if (window->KeyHit(Key::F1) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); } if (window->KeyHit(Key::F2) == true) { if (wireframe == true) { camera->SetDrawMode(0); wireframe = false; } else { camera->SetDrawMode(2); wireframe = true; } } Vec3 rot = box->GetRotation(); rot.x += 0.2f; rot.y += 0.2f; rot.z += 0.2f; box->SetRotation(rot); Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->DrawStats(10.0f, 10.0f, true); context->Sync(true); return true; } EDIT : It seems to be fine in the editor. I have some objects at a Y position of 23000.0
  12. I've started creating a large texture atlas for my terrain so that I can use more textures with less slots. The problem is the default mip-map generation creates bleeding on lower mip levels, and from what it says here, I need to create each mip-map separately and then combine them. Does anyone know of a way to manually set each mip-map level into a texture? Can I perhaps make a .dds texture with the mip-maps I want and will the editor then convert it to .tex format using those mip-maps?
  13. As well as trying out texture atlases I'm looking into textures arrays too, but am having trouble finding information on how to set it up. This is what I have so far; Material* mat = Material::Load("Materials\\terrain.mat"); Texture* texture = Texture::Load("Terrain\\beach_dirt_b.tex"); OpenGLShader* shader = (OpenGLShader*)mat->GetShader(); int _width = texture->GetWidth(), _height = texture->GetHeight(); char* buf = new char[texture->GetMipmapSize(0) * 4]; texture->GetPixels(buf); glUseProgram(shader->program); GLuint _buffer; glGenTextures(1, &_buffer); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, _buffer); glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, _width, _height, 1); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _width, _height, 1, GL_RGBA8, GL_BYTE, buf); Part of the Fragment Shader; #version 430 layout (binding = 0) uniform sampler2DArray tex; //in main() outcolor = texture(tex, vec3(coords.x, coords.y, 0)); All I get is total blackness on the terrain. Wondering if any of you guys know how to implement this? If needed I can make a small test program and upload that. A link I used; https://ferransole.wordpress.com/2014/06/09/array-textures/
  14. I can't seem to adjust the radius of my players character controller; physicsPivot->SetGravityMode(false); physicsPivot->SetDamping(0.0f, 0.0f); physicsPivot->SetPhysicsMode(Entity::CharacterPhysics); physicsPivot->SetCollisionType(COLLISION::PLAYER); physicsPivot->SetMass(1.0f); physicsPivot->charactercontroller->SetMaxSlope(80.0f); physicsPivot->charactercontroller->SetRadius(0.2f); float r = physicsPivot->charactercontroller->GetRadius(); The change is being detected in the variable "r" but in game there is no difference. Any suggestions?
  15. How does the PlayAnimation() time each frame? Is a speed of 1 dependent on FPS? If I have an animation that needs to run at 30 FPS, what would speed need to be?
  16. I'm aware the files will be needed in order to reproduce the problem but since they are quite large (~5GB) I wanted to first see if anyone else has come across crashes like this: Unhandled Exception at 0x00401DB1 : Fatal program exit requested I've attempted to debug the problem myself but as you'd expect with such little information it has been quite difficult. These crashes generally occur after about 10 - 15 minutes of play time either at the start or middle of a map.
  17. I use this code to create the normals for my terrain model. How would I create the Tangents and Bi-normals? I can't use the surface->UpdateTangentsAndBinormals() function, as I want the code to able to update normals for specific vertices only. How exactly do the tangents and bi-normals relate to the normal and how do they effect normal mapping? Vec3 _cPos = _getTerrainVertexPosition(x, z); Vec3 _lPos = _getTerrainVertexPosition(x - 1, z); Vec3 _rPos = _getTerrainVertexPosition(x + 1, z); Vec3 _uPos = _getTerrainVertexPosition(x, z + 1); Vec3 _dPos = _getTerrainVertexPosition(x, z - 1); //==================================================================================================// // TOP LEFT // //==================================================================================================// _U.x = _uPos.x - _lPos.x; _U.y = _uPos.y - _lPos.y; _U.z = _uPos.z - _lPos.z; _V.x = _cPos.x - _lPos.x; _V.y = _cPos.y - _lPos.y; _V.z = _cPos.z - _lPos.z; _topLeft.x = (_U.y * _V.z) - (_U.z * _V.y); _topLeft.y = (_U.z * _V.x) - (_U.x * _V.z); _topLeft.z = (_U.x * _V.y) - (_U.y * _V.x); //==================================================================================================// // TOP RIGHT // //==================================================================================================// _U.x = _cPos.x - _rPos.x; _U.y = _cPos.y - _rPos.y; _U.z = _cPos.z - _rPos.z; _V.x = _uPos.x - _rPos.x; _V.y = _uPos.y - _rPos.y; _V.z = _uPos.z - _rPos.z; _topRight.x = (_U.y * _V.z) - (_U.z * _V.y); _topRight.y = (_U.z * _V.x) - (_U.x * _V.z); _topRight.z = (_U.x * _V.y) - (_U.y * _V.x); //==================================================================================================// // BOTTOM LEFT // //==================================================================================================// _U.x = _dPos.x - _cPos.x; _U.y = _dPos.y - _cPos.y; _U.z = _dPos.z - _cPos.z; _V.x = _lPos.x - _cPos.x; _V.y = _lPos.y - _cPos.y; _V.z = _lPos.z - _cPos.z; _bottomLeft.x = (_U.y * _V.z) - (_U.z * _V.y); _bottomLeft.y = (_U.z * _V.x) - (_U.x * _V.z); _bottomLeft.z = (_U.x * _V.y) - (_U.y * _V.x); //==================================================================================================// // BOTTOM RIGHT // //==================================================================================================// _U.x = _rPos.x - _cPos.x; _U.y = _rPos.y - _cPos.y; _U.z = _rPos.z - _cPos.z; _V.x = _dPos.x - _cPos.x; _V.y = _dPos.y - _cPos.y; _V.z = _dPos.z - _cPos.z; _bottomRight.x = (_U.y * _V.z) - (_U.z * _V.y); _bottomRight.y = (_U.z * _V.x) - (_U.x * _V.z); _bottomRight.z = (_U.x * _V.y) - (_U.y * _V.x); _normal.x = (_topLeft.x + _topRight.x + _bottomLeft.x + _bottomRight.x) / 4.0f; _normal.y = (_topLeft.y + _topRight.y + _bottomLeft.y + _bottomRight.y) / 4.0f; _normal.z = (_topLeft.z + _topRight.z + _bottomLeft.z + _bottomRight.z) / 4.0f; //==================================================================================================// // NORMALIZE // //==================================================================================================// float _vectorLength = sqrt((_normal.x * _normal.x) + (_normal.y * _normal.y) + (_normal.z * _normal.z)); _normal.x = _normal.x / _vectorLength; _normal.y = _normal.y / _vectorLength; _normal.z = _normal.z / _vectorLength;
  18. I'm looking at the Actor class, when does ReceiveSignal() execute?
  19. Here's my attempt so far at making my own character controller. The reason for this is because I'm using multiple gravity directions in the same world and the current controller doesn't like gravity in any direction other than down the y axis. The problem I'm having is getting the controller to stay constrained to the up axis, when you move it with speed (shift key) you'll see that it drags across the terrain and bounces around. I'm not sure how to correctly use the joints settings to stop this kind of movement. Any help is appreciated. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } float lookspeed = 0.1, looksmoothing = 0.5; Vec3 mousepos; float jointpos = 1; bool wireframe = false; Joint* joint; Entity* parent; Joint* k = nullptr; Entity* child; bool App::Start() { window = Leadwerks::Window::Create(); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 0, -4); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); parent = Model::Box(); parent->SetColor(0.0, 0.0, 1.0); parent->SetMass(1); parent->SetGravityMode(false); child = Model::Box(); child->SetColor(1.0, 0.0, 0.0); child->SetShape(Shape::Box()); child->SetMass(1); child->SetGravityMode(true); k = Joint::Kinematic(0, 0, 0, parent); joint = Joint::Slider(0, 0, 0, 0, 1, 0, child, parent); joint->EnableLimits(); joint->SetLimits(-5, 5); joint->SetMotorSpeed(100); Model* mdl = Model::Load("Models\\Terrain.mdl"); mdl->SetScale(20, 20, 20); mdl->SetPosition(0, -3, 0); Shape* shp = Shape::PolyMesh(mdl->GetSurface(0)); mdl->SetShape(shp); mousepos = window->GetMousePosition(); window->SetMousePosition(context->GetWidth() / 2, context->GetHeight() / 2); return true; } bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) return false; if (window->KeyHit(Key::F3) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); } if (window->KeyHit(Key::F4) == true) { camera->GetDebugEntityBoxesMode() == true ? camera->SetDebugEntityBoxesMode(false) : camera->SetDebugEntityBoxesMode(true); } if (window->KeyHit(Key::F2) == true) { if (wireframe == true) { camera->SetDrawMode(0); wireframe = false; } else { camera->SetDrawMode(2); wireframe = true; } } float cx = Math::Round(context->GetWidth() / 2); float cy = Math::Round(context->GetHeight() / 2); Vec3 mpos = window->GetMousePosition(); window->SetMousePosition(cx, cy); mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing); float dx = (mpos.x - cx) * lookspeed; float dy = (mpos.y - cy) * lookspeed; Vec3 camrot = camera->GetRotation(); camrot.x += dy; camrot.y += dx; camera->SetRotation(camrot); mousepos = mpos; float _time = Time::GetSpeed(); float camspeed = 0.2f * _time; if (window->KeyDown(Key::Shift) == true) { camspeed = camspeed * 5.0f; } if (window->KeyDown(Key::W) == true) { camera->Move(0, 0, camspeed); } else if (window->KeyDown(Key::S) == true) { camera->Move(0, 0, -camspeed); } if (window->KeyDown(Key::A) == true) { camera->Move(-camspeed, 0, 0); } else if (window->KeyDown(Key::D) == true) { camera->Move(camspeed, 0, 0); } if (window->KeyDown(Key::T) == true) { camera->Move(0, camspeed, 0); } else if (window->KeyDown(Key::G) == true) { camera->Move(0, -camspeed, 0); } Vec3 p = parent->GetPosition(true); Vec3 r = parent->GetRotation(true); float speed = 0.1f; if (window->KeyDown(Key::Shift) == true) { speed = 1.0f; } if (window->KeyDown(Key::Up)) { k->SetTargetPosition(p.x, p.y, p.z + speed); } if (window->KeyDown(Key::Down)) { k->SetTargetPosition(p.x, p.y, p.z - speed); } if (window->KeyDown(Key::Left)) { k->SetTargetPosition(p.x - speed, p.y, p.z); } if (window->KeyDown(Key::Right)) { k->SetTargetPosition(p.x + speed, p.y, p.z); } //Jumping...? joint->SetAngle(jointpos); if (joint->MotorEnabled() == true) { joint->DisableMotor(); } if (window->KeyHit(Key::Space)) { joint->EnableMotor(); } Leadwerks::Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->DrawText("Target position: " + String(jointpos), 0, 0); context->DrawText("Current position: " + String(joint->GetAngle()), 0, 20); context->DrawText("Motor enabled: " + String(joint->MotorEnabled()), 0, 40); context->SetBlendMode(Blend::Solid); context->Sync(); return true; } Other links; https://www.leadwerks.com/community/topic/17437-physics-constraints/ Project.zip
  20. Hello every one ! Today i wanted to add c++ code to object but looks to accept only lua script 🤷‍♂️ It is possible to add c++ into this box Or we just use c++ into app.cpp (add class but every thing is connected to the app file) ?
  21. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } float jointpos = 1; bool wireframe = false; Joint* joint; Entity* parent; bool App::Start() { window = Leadwerks::Window::Create(); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 0, -4); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); parent = Model::Box(); parent->SetColor(0.0, 0.0, 1.0); Entity* child = Model::Box(); child->SetColor(1.0, 0.0, 0.0); child->SetShape(Shape::Box()); child->SetMass(1); child->SetFriction(0, 0); child->SetGravityMode(true); joint = Joint::Slider(0, 0, 0, 0, 1, 0, child, parent); joint->EnableLimits(); joint->SetLimits(-3, 1); Model* mdl = Model::Box(); mdl->SetScale(10, 0.1, 10); mdl->SetPosition(0, -2, 0); Shape* shp = Shape::Box(); mdl->SetShape(shp); return true; } bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) return false; if (window->KeyHit(Key::F3) == true) { camera->GetDebugPhysicsMode() == true ? camera->SetDebugPhysicsMode(false) : camera->SetDebugPhysicsMode(true); } if (window->KeyHit(Key::F4) == true) { camera->GetDebugEntityBoxesMode() == true ? camera->SetDebugEntityBoxesMode(false) : camera->SetDebugEntityBoxesMode(true); } if (window->KeyHit(Key::F2) == true) { if (wireframe == true) { camera->SetDrawMode(0); wireframe = false; } else { camera->SetDrawMode(2); wireframe = true; } } if (window->KeyDown(Key::Up)) { parent->Move(0, 0, 0.1); } if (window->KeyDown(Key::Down)) { parent->Move(0, 0, -0.1); } if (window->KeyDown(Key::Left)) { parent->Move(-0.1, 0, 0); } if (window->KeyDown(Key::Right)) { parent->Move(0.1, 0, 0); } joint->SetAngle(jointpos); if (window->KeyHit(Key::Space)) { if (!joint->MotorEnabled()) { joint->EnableMotor(); } else { joint->DisableMotor(); } } Leadwerks::Time::Update(); world->Update(); world->Render(); context->SetBlendMode(Blend::Alpha); context->DrawText("Target position: " + String(jointpos), 0, 0); context->DrawText("Current position: " + String(joint->GetAngle()), 0, 20); context->DrawText("Motor enabled: " + String(joint->MotorEnabled()), 0, 40); context->SetBlendMode(Blend::Solid); context->Sync(); return true; } Using the arrows keys to move the sliders parent around you can see that the child takes time to realign itself. Is it possible to stop this delay?
  22. Can this be made a smart pointer so delete doesn't have to be called? int* index = new int[1024]; Or are smart pointers only for creating things like classes?
  23. What's the best way to add physics constraints to a custom player controller? For example, the cylinder shape is pulled toward gravity (which is not always straight down) then collides with an object, how do I stop little movements like sliding and twisting once it collides? As far as I can tell, the inbuilt character controller only slides if the slope is greater than max slope. And when it moves around by key press it doesn't rotate left or right or jitter as it goes over various sloped polygons. Gravity is added like so in a different class to the controller; float _force = -9.8f; entity->AddForce(_gravity->gravityDirection.x * _force, _gravity->gravityDirection.y * _force, _gravity->gravityDirection.z * _force); //gravityDirection is a normalized vector And so far for the controller I've been doing this to make it move; Vec3 _velocity = entity->GetVelocity(true); //Get the current velocity Vec3 _gravityVelocity = _velocity.Multiply(upDirection); //Find how much of the velocity is along the gravity vector Vec3 _otherVelocity = _velocity.Subtract(_gravityVelocity); //Any remaining velocity other than gravity Vec3 _forwardVelocity = _forwardVector * move; //A vector in front of the player and perpindicular to gravity Vec3 _strafeVelocity = _strafeVector * strafe; //A vector that is the cross of gravity and the forward vector (out to the side) Vec3 _jumpVelocity = upDirection * jump; //GravityDirection * -1.0f movementVector = _forwardVelocity + _strafeVelocity + _jumpVelocity; //Find total movement vector (don't normalize, magnitude is speed) entity->SetVelocity((_velocity - _otherVelocity) + movementVector, true); //Subtract othervelocity to get only what gravity is, then add any movemnt entity->SetOmega(0.0f, 0.0f, 0.0f, true); //Been using this to reduce angular rotation, not perfect though The above code has issues still, but it's my attempt at constraining it along gravity unless needed to move. This code isn't done in a physics hook, which I was wondering if that might be better? And here's a quick video showing the physic shape jittering. It doesn't translate to the camera much at the moment but it does when the jitter is larger. Also I can't move the shape along it's local axis because of the jitter and the random rotation that happens as a result of moving. https://youtu.be/ZA_UNsYCEQs Any thoughts on more accurate ways of constraining are appreciated
  24. What would cause the background to seep through the leaves? I've attached the two materials of the trees. PineTreeLeaves.mat PineTreeTrunk.mat
  25. Can the gravity direction be changed on a per object basis rather than per world? I'd like to change the direction for the character controller. Would it be possible to turn off the world gravity and add forces to the controller object, or will this mess things up? 🤔
×
×
  • Create New...