Jump to content

Charrua

Developers
  • Posts

    230
  • Joined

  • Last visited

Everything posted by Charrua

  1. there are some spanish speakers over there (like me!) but unfortunately i'm new here and probably has more questions than you. HI!
  2. this fragment must be in app.cpp before start() function this is my complete App.cpp: #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Vec3 camerarotation; #if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS) bool freelookmode=true; #else bool freelookmode=false; #endif //Store entities vector<Entity*> entities; //Store all entities when map is loaded void StoreWorldObjects(Entity* entity, Object* extra) { System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name") + " /" + entity->GetKeyValue("anInt") + "/" + entity->GetKeyValue("aString")+"/"); entities.push_back(entity); } bool App::Start() { //Initialize Steamworks (optional) /*if (!Steamworks::Initialize()) { System::Print("Error: Failed to initialize Steam."); return false; }*/ //Create a window window = Leadwerks::Window::Create("GetMapEntity"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); //Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); Map::Load(mapname, StoreWorldObjects); vector<Entity*>::iterator iter = entities.begin(); int id = 0; for (iter; iter != entities.end(); iter++) { Entity* entity = *iter; System::Print(entity->GetKeyValue("name")); if (entity->GetKeyValue("name") == "EditorCamera"){ camera = entity; System::Print("found a camera in the editor"); } } if (camera == NULL) { System::Print("no camera from editor"); //Create a camera camera = Camera::Create(); camera->Move(0, 2, -5); } //Hide the mouse cursor window->HideMouse(); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2); freelookmode = false; return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) return false; //Press escape to end freelook mode if (window->KeyHit(Key::Escape)) { if (!freelookmode) return false; freelookmode=false; window->ShowMouse(); } if (freelookmode) { //Keyboard movement float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Leadwerks::Time::GetSpeed() * 0.05; float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Leadwerks::Time::GetSpeed() * 0.05; camera->Move(strafe,0,move); //Get the mouse movement float sx = context->GetWidth()/2; float sy = context->GetHeight()/2; Vec3 mouseposition = window->GetMousePosition(); float dx = mouseposition.x - sx; float dy = mouseposition.y - sy; //Adjust and set the camera rotation camerarotation.x += dy / 10.0; camerarotation.y += dx / 10.0; camera->SetRotation(camerarotation); //Move the mouse to the center of the screen window->SetMousePosition(sx,sy); } Leadwerks::Time::Update(); world->Update(); world->Render(); context->Sync(false); return true; }
  3. @shadoh i use entities name's to embed csv's with extra info i found a way in leadwerks to do so via SetKeyValue with this simple script: Script.AnInt=5--int "anInt" Script.AString="Hola"--string "string" function Script:Start() self.entity:SetKeyValue("anInt", self.AnInt) self.entity:SetKeyValue("aString", self.AString) end attached to an entity you can pass any value, so you may have a general name: "WayPoint" and pass as keyvalues other properties not handled by the editor you only has to use GetKeyValue from C++ System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name") + " /" + entity->GetKeyValue("anInt") + "/" + entity->GetKeyValue("aString")+"/");
  4. did you declare the entities vector and the function? //Store entities vector<Entity*> entities; //Store all entities when map is loaded void StoreWorldObjects(Entity* entity, Object* extra) { System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name")); entities.push_back(entity); }
  5. map.cpp was posted by Josh http://www.leadwerks.com/werkspace/topic/10139-leadwerks-map-class/ if you want to take a look.... and translate to some simple words....
  6. AZ wrote: the situation, and i guess the needs of AZ was to get a camera created in the editor from c++ so, i created a camera in the editor, name it EditorCamera and then inside c++ i scan the list of objects and get's the "EditorCamera"entity i create a camera only if i didn't found the one i created on the editor, because, as you said, having no camera is no sense. in App.h, the variable camera is declared as Camera if we change the declaration from Camera to Entity, then there are no problem and we can get the EditorCamera from the map and assign it to the global variable camera from c++ i'm just trying to solve the AZ trouble, and by te way, learning a bit more.
  7. it works! thanks declaring camear as entity in app.h was enough. //Camera* camera; Entity* camera; in App::Start() : //Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); Map::Load(mapname, StoreWorldObjects); vector<Entity*>::iterator iter = entities.begin(); int id = 0; for (iter; iter != entities.end(); iter++) { Entity* entity = *iter; System::Print(entity->GetKeyValue("name")); if (entity->GetKeyValue("name") == "EditorCamera"){ camera = entity; System::Print("found a camera in the editor"); } } if (camera == NULL) { System::Print("no camera from editor"); //Create a camera camera = Camera::Create(); camera->Move(0, 2, -5); } now i got the Editor Camera, it's position and orientation works with freelookmode if i set it to true Why use the editor camera and not the one created in c++? For me is just a matter of connecting lua and c++ Perhaps editor is a better place to set the camera, position it etc I'm not concerned only about cameras. Probably in a near future, i will only use c++, but at this moment i'm using a combination and want to see how can i define one thing in the editor and have a reference from c++ thxs again
  8. in the code above, there are two cameras, the one created in code, the one created in the editor. The one on the editor is over the first one, so if you run the code, you will see what the editor camera see. But the freelook is working on the code created camera who's viewport is overlapped by the editor camera viewport. if i, inside the Vector items loop i write: if (entity->GetKeyValue("name") == "EditorCamera") entity->Release(); then the editor camera is released and the code created camera is seen and work as supposed So i get the camera from the editor, but can't assign it to the Camera type variable camera defined in app.h the sentence camera=entity is not legal, the error message is: a value of type "Leadwerks::Entity *" cannot be assigned to an entity of type "Leadwerks::Camera *" does any one know if it is possible to do that?
  9. due to my lack of knowledge about c++ (and in general!)... i can't give you a solution. if you place a hook on the Load function, you may store map entities for future use. But entities are not strictly speaking a camera. i don't know how to cast an entity to a camera for instance in app.cpp you may: //Store entities vector<Entity*> entities; //Store all entities when map is loaded void StoreWorldObjects(Entity* entity, Object* extra) { System::Print("Loaded an entity and stored it: " + entity->GetKeyValue("name")); entities.push_back(entity); } and to load and invoke this function: //Load the map std::string mapname = System::GetProperty("map", "Maps/start.map"); //Map::Load(mapname); Map::Load(mapname, StoreWorldObjects); //Store position of every entity vector<Entity*>::iterator iter = entities.begin(); int id = 0; for (iter; iter != entities.end(); iter++) { Entity* entity = *iter; if (entity->script != NULL) { System::Print(entity->GetKeyValue("name")); } // 2 IntelliSense: a value of type "Leadwerks::Entity *" cannot be assigned to an entity of type "Leadwerks::Camera *" c:\Users\usuario\Documents\Leadwerks\Projects\GetMapEntity\Source\App.cpp 60 61 GetMapEntity //if (entity->GetKeyValue("name") == "EditorCamera") camera = entity; } but, the camera=entity isn't legal if it works, then , you may test ic camera==nil and if so (no camera from map) you can create the camera by code.. any idea? (i started a thread about lua-cpp iterations, should be good to have a simple way of connecting both)
  10. i'm using hinges only. to get wheel rotation, simply read the current joint angle and set it to some value ahead, having motor enabled speed is controlled by MotorSpeed wheels are cylinders ... made by segments and so the whell gets jumping constantly and so, the vehicle goes slower that it should... if you tell the camera to follow the vehicle, then you will see how unstable it is... i'm not applying forces/torque, just MotorSpeed, Limits, Angle also, to much or to less mass on the individual parts of the vehicle make it behave differently, bad/worse i'm doing some code-clean-up, then i will post the scripts i'm using. Not sure if it is the correct way of doing things, but problably some one can point me in the right direction... thank's for the comments
  11. @shadmar: nice unrelated shoot!, at least it gives some beauty to this thread... ok, now i'm controlling steer and speed not too much stable, but working
  12. thank's if i have time, my intention is to create some prefabs/scripts to play with. is a way of learning and have fun.
  13. sliders will came late... and balls also i'm still playing with hinges. 4 or 3 wheels: tricycle or car.. very elemental, with no control (until) a couple of captures, on the editor, and running the code. the video is uploading...
  14. thank's for share it just a small typo: on grid.lua, start function entities[x]:SetPosition(Math:Random(-500,500),0,SetPosition(Math:Random(-500,500)) should be entities[x]:SetPosition(Math:Random(-500,500),0,Math:Random(-500,500))
  15. not all is work! Here the code that does the magic: Create a sphere on start function Script:Start() --as this script is attached to the camera, here is a good place to --set a global camera variable and so, it can be used in any other script of this project. camera=self.entity --Create a sphere to indicate where the pick hits self.picksphere = Model:Sphere() self.picksphere:SetColor(1.0,0.0,0.0) self.picksphere:SetPickMode(0) self.picksphere:SetScale(pickradius*2.0) self.picksphere:Hide() System:Print("fly.lua start") end on the update world function: if appWindow:MouseHit(1) then local pickinfo = PickInfo() local p = appWindow:GetMousePosition() --do a camera pick --place a new instance of the picksphere ent at the picked position --place a hinge joint to keep the sphere and the picked object together if (camera:Pick(p.x,p.y,pickinfo,pickradius,true)) then local newEnt = self.picksphere:Instance() newEnt:SetPhysicsMode(Entity.RigidBodyPhysics) newEnt:SetMass(10) local shape = Shape:Sphere() newEnt:SetShape(shape) shape:Release() newEnt:SetPosition(pickinfo.position) local hingeVar = Joint:Slider(pickinfo.position.x, pickinfo.position.y, pickinfo.position.z, 0, 0, 0, pickinfo.entity, newEnt) hingeVar:SetLimits(0,0) hingeVar:EnableLimits() newEnt:Show() end end a note about: appWindow on app.lua, i declare this global variable and pass the window created there, so i can use it on any other script here the modification of app.lua: appWindow=nil --global variable, so fly.lua can reach and use the window created on start function App:Start() --Initialize Steamworks (optional) --Steamworks:Initialize() --Set the application title self.title="MyGame" --Create a window self.window=Window:Create(self.title) --self.window:HideMouse() --do not hide the mouse pointer appWindow=self.window --set the global variable appWindow with the window just created --rest of the script/function as default
  16. here are my settings: alpha is on the diffuse texture, compression DXT5 and a snapshoot of the perspective view
  17. yes, it works ok movement is very small, which i guess is ok. don't try to modify or find a variable inside the shader to evantually set via coding. it's fbx so placing it on the assets folder automatically convert it to mdl, mat etc have to manually create the material and set the texture as dtx5 if not alpha don't behaves as spected. (i first test it with other models, but they were bought from dexsoft, and has to manipulate them the same way)
  18. try a free one http://tf3dm.com/3d-model/tree-alan-2-68600.html remember to set diffuse texture as DTX5 (for alpha to work correctly), and naturally, to modify the material for the shader, specially texture 4 equal diffuse texture for the vegetation shader.
  19. thank's, understood. then, the Dynamic drop down box is for?, shouldn't it be omitted if the entity is a brush instead of a model? or the Shadows Dynamic has another purpose. naturally, a question needs an explanation but, if there is a solution is better: must i create a Shape and attach it to it? must i create a prefab? or the only solution is to use a 3d modeler, create a box, export as mdl and then import on the editor? thank's in advance
  20. just open the MyGame\Maps\start.map wrote the rotator.lua script of: http://www.leadwerks.com/werkspace/page/tutorials/_/script/creating-your-first-object-script-r110 and attach the script to Box2
  21. i used tree objects with two meshes, one for trunk and other for branches/leaves i used shaders applied to selected meshes which vasically read and modify vertex positions giving the illusion of movement. grass waving shader do the exact thing. i'm very new here and i'm in the stage of doing (or trying to do) simple things. When i have time, i'll try to see le shaders format and see if i can modify them easily. if not, will see or wait for some one else i should read the previous post...! sorry
  22. yes, after saving, no material appear to be applied. material control is empty (also, there are no chances of de-attach a shader) With a point light seems to work ok, shadows appear as supposed to be may it be a directional light bug?
  23. thank's disabling this checkbox makes it work again!
  24. should be good not only for grass, for trees also.
  25. i'm just rotating a box, is the start map with the rotator script from tutorials i try to modify Appeareance->Cast Shadows->Static/Dynamic, no difference i see that the material has no Shadow shadder applied, does it should be applied here the shadows, which seems to be created by the faces seen of the cube, when it started to ratate. i'm shure that i'm missing something. also, i noted that, no material seems to be applied to objects. if i apply one, the text box tells the material name, but i y quit and restart the editor, again the material textbox is empty. but the object has the correct material.
×
×
  • Create New...