Jump to content

Charrua

Developers
  • Posts

    247
  • Joined

  • Last visited

Everything posted by Charrua

  1. OK, thank's to Rick y now have a complete working example of integrating leadwerks and awesomium the example now has 2 buttons, one to SayHello the other to exit the application and work as expected! 7z file has the Source folder with all the source files needed, those files which came from awesomium form part of one of the tutorials general gelp on awesomium: http://wiki.awesomium.com/getting-started/ tut files: https://github.com/awesomium/tutorial-framework/archive/master.zip complete c++ source and executable for you to try: https://dl.dropboxusercontent.com/u/78894295/leadwerks/awe1.7z had happens to me that the first time i run seem not to respond to mouse down events... but works ok if exit and run again do not know why can it be! enjoy jio
  2. at least should be goo to get a working all included example to start with I'll will update this thread as soon as i get something new to show. (too much information for me to digest.. it will take a while...) thank's again jio
  3. rick, i was writing my second post when you answer my first thank's for your input, i have to read it carefully about keyboard input... je je, the docs say not to much... even tells us to read some other doc which has no link! would be nice if some one else has a code for that jio
  4. forgot to include an executable for you to try if you change the boton.html for another more elaborated html it should work also. but i'm only using 300x200 pixels for the ui texture, so not too much space for being much creative. int the app dir, a snapshoot of the html as is after loaded is saved as result.jpg here the 7z file: https://dl.dropboxusercontent.com/u/78894295/leadwerks/awe.7z enjoy jio
  5. Hi, i was trying to get awesomium to work with leadwerks. Mi knowledge about javascript and html are almost nothing, (ok, my knowledge of c++ isn't too much also) I need a ui for leadwerks, which is a must, i guess. The following code is what i could make to work: 1) load a local html file 2) on every loop send mouse events to the html "web view" get how it look on a leadwerks texture show it on the screen (context->DrawImage) What i miss is how to bind java events to c++ functions Does someone has a simple example of how to do that. A snapshoot: here the complete source: /* Awesomium - Leadwerks tests by Juan Ignacio Odriozola, aka charrua http://wiki.awesomium.com/getting-started/ What this code does load a simple html page: just a label and a button get what it show and copy that info to a Leadwerks texture Send to the html mouse events Display the texture on screen with a cube rotating on the 3d space if you hover the button, mouse down or mouse up, the control draws as spected. What it doesn't the code do not bind button press and do not call any c++ function OnMouseHit SO I'm asking if anyone has a simple code to showme how to do that. I'm know nothing about html neither javascript, i will try to learn abot them if i got awesomium to work with leadwerks! Hope this code will catch interest in other about awesomium or short the learning path that's the html source of "boton.html": <html> <body> <h1>Awesomium Test</h1> <button onclick="app.sayHello()">Say Hello</button> </body> </html> */ #include "App.h" #include <Awesomium/WebCore.h> #include <Awesomium/BitmapSurface.h> #include <Awesomium/STLHelpers.h> using namespace Awesomium; WebCore* web_core = NULL; WebView* my_web_view = NULL; BitmapSurface* uiSurface = NULL; Texture* uiTex = NULL; unsigned char* pixels = NULL; using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* model = NULL; JSValue jsResult; bool App::Start() { window = Window::Create(); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 0, -3); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); // Create the WebCore singleton with default configuration web_core = WebCore::Initialize(WebConfig()); // al salir: WebCore::Shutdown(); my_web_view = web_core->CreateWebView(320, 200); WebURL url(WSLit("file:///./boton.html")); //acceso al dir local! my_web_view->LoadURL(url); uiTex = Texture::Create(320, 200); pixels = (unsigned char*)malloc(uiTex->GetMipmapSize(0)); // Wait for our WebView to finish loading while (my_web_view->IsLoading()) web_core->Update(); Sleep(300); web_core->Update(); uiSurface = (BitmapSurface*)my_web_view->surface(); // para esto hay que: #include <Awesomium/BitmapSurface.h> if (uiSurface != 0) { uiSurface->SaveToJPEG(WSLit("./result.jpg")); //just to verify html was loaded and how it look! uiSurface->CopyTo(pixels, uiTex->GetWidth() * 4, 4, true, false); uiTex->SetPixels((char*)pixels); } // now a cube and btw texture it with the html view //Create a material Material* material = Material::Create(); //use uiTex as texture material->SetTexture(uiTex); //Load and apply a shader Shader* shader = Shader::Load("Shaders/Model/diffuse.shader"); material->SetShader(shader); shader->Release(); //Create a model and apply the material model = Model::Box(); model->SetMaterial(material); model->SetPosition(0, 0, 1); return true; } bool mouseLeftDown = false; bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) { free(pixels); my_web_view->Destroy(); WebCore::Shutdown(); return false; } model->Turn(Time::GetSpeed()/3, Time::GetSpeed()/4, Time::GetSpeed() / 2); //get new pixel data from html view if (uiSurface != 0) { uiSurface->CopyTo(pixels, uiTex->GetWidth() * 4, 4, true, false); uiTex->SetPixels((char*)pixels); } // Inject a mouse-movement my_web_view->InjectMouseMove(window->MouseX(), window->MouseY()); if (window->MouseDown(1)){ // Inject a left-mouse-button down event my_web_view->InjectMouseDown(kMouseButton_Left); mouseLeftDown = true; } else { if (mouseLeftDown) { mouseLeftDown = false; // Inject a left-mouse-button up event my_web_view->InjectMouseUp(kMouseButton_Left); } } web_core->Update(); Time::Update(); world->Update(); world->Render(); context->DrawImage(uiTex, 0, 0); context->Sync(); return true; } more snapshoots, when mouse hover the button and when i'ts clicked thank's in advance jio
  6. ok solved the init errors.. (most my fault)! now, i think i get lost forever, when i try to update the gui, then: i tested version 1060 and 1110, 1060 do not pass the initiate function version 1110 pass the init (initiate is deprecated in this new version) so some checks like valid window and graphics devices are passed. i can call many of the functions to create and set parameters, just update seems to fail
  7. Hey, thank's for you fast response:) the first step seemed to be the easiest one and... i'm stuck on it! but when i call the init function the message isn't about window o graphics pointers ... is about that the pointer to input is null. so... i'll keep trying
  8. Hi i'm trying to connect Leadwerks to a gui, which development has stopped, but that i used and use at present with other engines (albalynx). One of the firsts steps consist in passing pointers of the window's window and the graphics device (openGL i guess), albalynx is supposed to support DirecX9,10,11 and OpenGL 4 I found some functions and properties like: Context* context->getCurrent(); Window* window->getCurrent(); window->whnd; i readed about Window:GetHandle() http://www.leadwerks.com/werkspace/topic/10381-requested-features-and-improvements/page__st__40#entry76787 but seems to not exists. any help is appreciated! thank's in advance jio
  9. i always been interested in this subject i know that the following isn't the best way, but is better than nothing basically i use the GetKeyValue and SetKeyValue to store pairs: key,value on a "messenger" entity i create a pivot named "messenger" in my map (or the number needed) and name it the same then in c++ scan the world.entities and catch that entity. once i have it's handle (address, pointer...) then i have a simple, brute force, but working line of comunication: -------------------------------------------------- more explained create a messenger object (a pivot) in your map name it "messenger" in your lua start function you may: self.messenger:SetKeyValue("Hit","0") self.messenger:SetKeyValue("xPos","0") self.messenger:SetKeyValue("yPos","0") -------------------------------- c++ side Entity* messenger; //after map load for (auto e : world->entities){ if (e->GetKeyValue("name") == "messenger"){ messenger = e; //catch messenger entity } } //from c++ ent->SetKeyValue("Hit", "1"); //set Hit property to 1 to signal something spected in lua --------------------------------- lua side //UpdateWorld perhaps if self.messenger:GetKeyValue("Hit")=="1" then self.messenger:SetKeyValue("Hit","0") // may signal : readed //do whatever HIT does/needs end (sorry my bad English) Juan
  10. thxs i'm going to do so i receive a pm from josh about a steam key so, thread resolved!
  11. i have the stand alone version 3.3 is only for the ones that has steam version? my updater tells me that there are no files to update. do i have access to that version? do i have to pay for it? i was off for a while, do i miss something obvious? thank's in advance Juan
  12. hi i am getting some troubles, due to my lack of knowledge. the easy part is: add #include "lua.h" in your App.h so, any scripted object will work, but: if you create a camera in your map (via editor) you have to make some tricks to use that camera and not create another via c++ your initila c++ code, creates a context, window etc, you have to write your scripts using those objects... you may write something like this on your Scripts functions: function Script:PostRender() local window = Window:GetCurrent() local context = Context:GetCurrent() if window:KeyHit(Key.M) then self.showtext = not(self.showtext) end if self.showtext context:SetBlendMode(Blend.Alpha) context:SetColor(255,255, 255) context:DrawText("hello", x, y) end end as i get some troubles using a camera defined in c from lua scripts (sure i am doing something wrong) i define the camera inside the editor and then i use that camera from c++ see: http://www.leadwerks.com/werkspace/topic/10154-set-camera-to-a-camera-in-the-scenelevelmap/ Juan
  13. thank's i have to seriously start studying c++ and lua by the moment i have to evade call a script function from c++, till i get older! thank's again
  14. i have many objects with scripts attached if i get one of them via collision or ray pick, can i call a function declared inside the entity's script? something like pickinfo.entity.script.Hit(), if Hit is defined inside the script thank's in advance Juan
  15. i used this to use an entity rotation and transform it to a normalized rotation, perhaps is very indirect, but seems to work guess there should be a simpler mathematical way, but still unknown for me. hope that helps: if self.usepivotpin then local pvtTemp = Pivot:Create() --get ent rotation, to set hinge pin if pvtTemp ~= nil then pvtTemp:SetRotation(self.entity:GetRotation()) pvtTemp:Move(0,0,1) --transform from euler angles to 0..1 axis coords ... a vector of lenght one: nomarized local rot = pvtTemp:GetPosition(false) self.pin.x = rot.x self.pin.y = rot.y self.pin.z = rot.z --System:Print("pin: " .. self.pin.x .. ", " .. self.pin.y .. ", " .. self.pin.z) pvtTemp:Release() end end i used to set hinge joint pin, btw
  16. there are some spanish speakers over there (like me!) but unfortunately i'm new here and probably has more questions than you. HI!
  17. 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; }
  18. @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")+"/");
  19. 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); }
  20. 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....
  21. 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.
  22. 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
  23. 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?
  24. 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)
×
×
  • Create New...