Jump to content

Charrua

Developers
  • Posts

    230
  • Joined

  • Last visited

Everything posted by Charrua

  1. thank's aside of another problems i have... now is working if and only if the boxes that has the textures are not hidden if i hide a box, then it's texture isn't updated based on the "intended behavior" (not so logical to me) sounds ok, because if the system do not update a texture of an object outside the view of the camera, then it will not render a texture of a hidden box. the documentation refers that the texture "can" be used in a material and applied to an object, or draw on screen" i understand from that that "can" is not "must" (but my English is terrible). any way, our language (english spanish etc) isn't so exact as computer languages so my problem is not with documentation, knowing what is possible to do and what isn't is what i need. i was working with buffers, doing a world::render for each one and then getting the texture from the buffer, doing some handling on the texture (cropping it mostly) and then drawing each processed texture. Started doing cropping by hand (memcpy) and reaching a 14 fps on my laptop then as pointed by macklebee (thank's man) i starting to try a shader to do so http://www.leadwerks.com/werkspace/topic/12537-drawing-a-section-of-a-2d-texture-setting-uv-coords/#entry90453 after some mistakes of mine (use to have lots) i make it work and fps rise up to 28 so, i starting to ask, what about render to a texture instead of render to a buffer... well if i render to textures i'm having 12 fps (worse than using by hand texture copy, crop: handling) and i have to have in front of the camera boxes with those textures on it (not supposed to be) probably i'm still doing something wrong, but for now i'll keep with buffers + shader thank's for your help Juan
  2. I was trying to render to a texture without success. Texture shows always the same no matter the camera position/rotation... I roll back to the RenderToTexture Lua example, wrote it for cpp and works ok, then i realize that: 1) If the texture is not applied to a material then the rendered texture is what the camera sees when at it's starting position/rotation : 0,0,0 / 0,0,0 2) if the texture is applied to a material, and this material is applied to an object, the rendered texture is ok if the object is visible by the camera, if not, then the rendered texture is again what the camera sees on the default position. The documentation says: " The texture can be used in a material and applied to an object, or drawn onscreen. " but if not applied to a material, it does not render, and if applied to a material then it mus be applied to an object visible by the camera. following is a cpp to test, with the commented lines (with //) the example do not work if applied to the box works ok until you uncomment the line that moves it outside the view range of the camera. perhaps this is the intended behavior and i am missing something obvious. What I need is to render to a texture with the intention of draw it with context->DrawImage. I do no plan to place a visible object with the texture in front of the camera. is it possible to render to a texture without applying it to an object with a materila with it? thank's in advance Juan #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Model* model = NULL; Camera* camera2; Pivot* pivot; Material* mtl; Texture* tex; bool App::Start() { window = Window::Create("render to textue",0,0,1024,768); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 0, -3); Map::Load("Maps/start.map"); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); camera2 = Camera::Create(); camera2->Move(0, 0, -4); camera2->SetClearColor(1, 0, 0); pivot = Pivot::Create(); camera2->SetParent(pivot); pivot->SetPosition(-2, 2, 1); tex = Texture::Create(256, 512); mtl = Material::Create(); mtl->SetShader("Shaders/Model/Diffuse.shader"); mtl->SetTexture(tex); camera2->SetRenderTarget(tex); model = Model::Box(); //model->SetPosition(0, -4, 0); //if not visible: render texture gets freezed //model->SetMaterial(mtl); //if material is not applied to a visible object render texture gets freezed model = Model::Cylinder(); model->SetColor(0.0, 1.0, 0.0); model->SetPosition(0, 0, 0); model = Model::Cone(); model->SetColor(0.0, 0.0, 1.0); model->SetPosition(2, 0, 0); return true; } bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) return false; pivot->Turn(0, Time::GetSpeed(), 0); Time::Update(); world->Update(); world->Render(); context->DrawImage(tex, 10, 10); context->Sync(); return true; }
  3. Hi, i'm working on a shooting simulator. Here are some screenshots. The graphics part of it isn't of too much interest at this stage I'm more concerned about the hardware interface with the guns. Gun range: 6 feet under (more or less) Out side Testing the app with the mouse (not the intended input, but for ease) https://drive.google.com/open?id=0B8-7vR0QcsPkaDBXRk5qUzc1Tkk https://drive.google.com/open?id=0B8-7vR0QcsPkbG5hWFFPZHV6b3c https://drive.google.com/open?id=0B8-7vR0QcsPkZlJxU0M1emhxeUE Testing it with the real input hardware. https://drive.google.com/open?id=0B8-7vR0QcsPkMlJLVENIRWRCZ0k https://drive.google.com/open?id=0B8-7vR0QcsPkbmZGeGFPUHE1OW8 https://drive.google.com/open?id=0B8-7vR0QcsPkNXJ1QVNiNHl1c3M https://drive.google.com/open?id=0B8-7vR0QcsPkMDRLaThmZDcwbDQ https://drive.google.com/open?id=0B8-7vR0QcsPkcV8wbV94WkhpRDg https://drive.google.com/open?id=0B8-7vR0QcsPkUlNVbTl1Y3dqYVU Juan
  4. nice has you found a way of getting constant speed over the spline? are you using some criteria for placing control points based on endpoints? i mean, you only set the endpoints and then pre-calculate based on them the control points, then manually adjust the ones that need adjustment...hope you understand my question.
  5. thank's i'm using the 360 SDK v1.8 the video was made with aproject that only loads a map and connects to the kinect, the other hawdware/software was not present. the complete systems includes guns with a sensor on the trigger and a IR laser beam, and an IR camera to know where the gun's are heading... gun: https://photos.google.com/photo/AF1QipOqR9tke1JGI1CstXfA8BTUuf10rsGBG0BC0Tg stuff https://photos.google.com/photo/AF1QipMEaQRfJe9fK8v7AlRiUxERY5iUYLOiS2fVNec test (no kinect still, no scene at all either!) https://photos.google.com/photo/AF1QipPydG6AouTsLWBA1gi2UcZio6ym1MF2tl364wU
  6. Hi, i'm doing some test with a kinect, the idea is to follow player's position (head tracking) and project on a screen (not laptop or pc screen/monitor) 5 meters away from the player a "window" through which we see the 3D world. Each player has it's own line of sight and a "window" to look throug. First test are nice (ok, are not the first tests.. this is the first that look promising!) Juan
  7. quite interesting! thank's i'll give it a try.. for a while
  8. is there a simple way of copying a sub part of an image/texture to other image/texture. i mean, instead of getting the pixel data and copying pixel by pixel with a couple of nested for/next loops? has leadwers a copyrect o drawrect command? Juan
  9. totally agree, i'm just fan of crtl left/right, auto indentation and many other helper thing's we usually has on editors (i came from the Ctrl+K+AnotherNiceKey era!, when a mouse simply were a strange thing)
  10. don't know it it's a bug, but this afternoon happens to me that i minimized the leadwerks editor, left the laptop alone for a while and it goes to sleep. After wake up, i couldn't maximize the editor. I close and start again and i goes minimized. i take a look at the .cfg file and found the "MainWindowShape" parameter with this: MainWindowShape="-25600","-25600","136","47","0" i look on other .cfg files posted here and simply replace this line for something like MainWindowShape="236","27","1186","768","0" and start leadwerks again and looking as spected. i simply report this issue, and a solution i found. Juan
  11. great! thank's for sharing just a small note (happens to me : in: function Script:Record_Mode_Toggle() FileSystem:WriteFile retutn null if lua sandboxing is enabled a check for a null and an advice would be nice Juan
  12. the "someValue" should be dependent of the distance from the player and the camera, probably the angle (camera x angle) and naturally the camera FOV
  13. if you want the bar over the head in 2d space project the head, and then use the 2D x axis as the center of the bar, and use the 2D Y axis minus some value to rise up (in 2D space) the bar. isn't it?
  14. hi, here there are some notes i wrote about c++ lua bindings http://www.leadwerks.com/werkspace/blog/183/entry-1612-lua-cpp-bindings-how-to-tutorial-17/ once yo compile your c++ code, that one is used from the Leadwearks editor when you press paly/debug on the editor.
  15. every day i felt a couple of month outdated about almost everything! thinking it twice that's a good signature to use
  16. i tested the opposite, change a key in cpp and test it on lua side.. i realize how i forgot how to code in lua.. --simply to pass data to c++ Script.AnInt=0 --int "anInt" Script.AString="Hola" --string "string" function Script:Start() self.entity:SetKeyValue("anInt", self.AnInt) self.entity:SetKeyValue("aString", self.AString) end function Script:UpdateWorld() if self.entity:GetKeyValue("anInt") ~= self.AnInt then self.AnInt = self.entity:GetKeyValue("anInt") System:Print("AnInt changed: "..self.AnInt) end end and in cpp, after found "theEnt" (as i named the entity with this script attached) and storend on a Entity* pointer.. i delared a glogal int int anInt=0; in main loop: somewhere: if (window->KeyHit(Key::G)) { anInt++; theEnt->SetKeyValue("anInt", String(anInt)); }
  17. found a script i used ... when testing set/get key value its called EntData.lua --simply to pass data to c++ 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 if you attach this script to an entity in the editor, you may set the values you want and at startup, keys are asigned to the entity i'm sure i used that to then read the keys from cpp side, i only found the lua side other thing i used to use... just because name is safe, was use the "name" as a csv, with something like name=theentty, customval1=34, customval2=hola, and so.. then whit a utiliti function like getNthCsvFromString(string s, int nth) i get the "name" key and get the individual csv items with the previous function... i know that this kind of names are a mess, but was what i used before knowing better ones jio
  18. this is from when? last year i passed via keyvalues data from cpp to lua and back to cpp using an entity as a placeholder. this is not working at present?, i don't tested recently
  19. but if you find the "block" entity, then GetKeyValue("name") is working. "name" is a key already implemented, so it allways work, you have a textbox on the editor for the name. if i'm not wrong, then the problem is with keys created by you, isn't it? probably your problem is on the SetKeyValue command, which i suppose you are setting in the lua script.
  20. where is world created? if in lua, then cpp world should be empty (or NULL)
  21. these both are very handy, or if you named the object properly then you can search it inside the world->Entities list see: http://www.leadwerks.com/werkspace/blog/183/entry-1613-lua-cpp-how-to-27/
  22. it there is a better place, no problem just updated the post with the link to a zip file with allincluded
  23. 6) How to expose a Cpp Class to LUA using tolua++ At a glance: A way to create instances of objects defined in Cpp from LUA scripts, so functions created in Cpp side should be called from LUA side. Somewhat the opposite direction of items 4, 5 and 6 of this series. The way is not so difficult once you travelled it, as always! First you have to write a header with your class declaration, then you have to use tolua++ application to translate it to LUA I'll started a new cpp empty project, so i have only: Main.cpp, App.h and App.cpp Added: cToLuaTest.h declaration of the class cToLuaTest.cpp implementation of the class cToLua translation to lua generated by tolua++ cToLua.cpp si generated by tolua++ with the following command line: (on a terminal good great and legendary DOS window.. haa those times!) tolua++ -o cToLua cToLuaTest.h the command line explained: a) first parameter -o nomGeneratedFile :desired name of outputfile b) second parameter cToLuaTest.h :name of input file this generates a long.. more than expected file, that at the end has a function: https://dl.dropboxusercontent.com/u/78894295/leadwerks/cToLua.cpp note: you will have to include as source this file, so name it differently than the cToLuaTest.cpp which implements the class. If you do not especify -o, then the same name as input is assumend, becarefull inside the cToLua.cpp generated by tolua++, almost at the end there is a special function: /* Open function */ TOLUA_API int tolua_cToLua_open(lua_State* tolua_S) { ... } which is used to bind the class to lua. as a helper (from one of the threads cited on first tut) i adopted to write another header to declare the above function. lua_gluecode.h #pragma once #include "Leadwerks.h" using namespace Leadwerks; /* Exported function */ TOLUA_API int tolua_clasetolua_open(lua_State* tolua_S); Following the class declaration and the implementation class cToLuaTest { public: cToLuaTest(void){}; ~cToLuaTest(void){}; void luaCalling(void); float average(void); float aFloat; int intA, intB, intC; }; #include "cToLuaTest.h" //prototypes #include "Leadwerks.h" //uso System de leadwerks por eso la inclusion using namespace Leadwerks; void cToLuaTest::luaCalling(void){ System::Print("lua is calling me!"); } float cToLuaTest::average(void){ return (float)(intA+intB+intC)/3.0f; } Did you expected something more elaborated? sorry then Now the bind part, in Main.app: 1) include the file lua_gluecode.h 2) the following couple of sentences (before app->start) #include "lua_gluecode.h" ... int main(int argc,const char *argv[]) { ... many many lines away of default main.cpp main function ... else { if (Interpreter::L == NULL) Interpreter::Reset(); //--- this line tolua_cToLua_open(Interpreter::L); // and this line //Execute mobile-style App script App* app = new App; if (app->Start()) { while (app->Loop()) {} ... rest of main.cpp } build and voila!, you have all done cpp side! now, go LUA side. as a test, in App.lua, function Start: function App:Start() ... --Load a map local mapfile = System:GetProperty("map","Maps/start.map") if Map:Load(mapfile)==false then return false end System:Print("app.lua start") -- cToLuaTest object created in lua c2luaTest = cToLuaTest:new() --create an instance of cToLuaTest class object if c2luaTest ~= nil then --test if ok System:Print("c2luaTest not nil") c2luaTest:luaCalling() --use one of it's methods, just print "lua is calling me!" on the cpp side end --set some properties c2luaTest.intA = 10 c2luaTest.intA = 35 c2luaTest.intA = 15 --call average an print out the result System:Print(c2luaTest:average()) return true end --of App:Start so easy, isn't it? the end Home, Previous
  24. have to admit that i learn it that yesterday! now i'm cleaning the app before post the "allincluded" one with tolua++ examples also. i'm very happy with the new knowledge so i decided to post it, before it get lost on my mind... and my machine!
  25. 5) How to receive returned parameters from LUA functions (yes one or more) come on, every time i edit the post, code /code get bad formatted and have to manually (again) correct it (really don't like to see un-indented code). So, with an example will see how to receive parameters from LUA function scripts. The example is basically the same as the one exposed in the previous tut (5/7) the only difference is that the function called has a Return sentence so is sending us something, and following the Invoke method, we have to catch that value. It's good to test if the kind of value received is of the correct type and if so, then we have to convert it from LUA type to Cpp type, here an example: LUA function declared on a script attached to the entity used next function Script:average(intA, intB, intC) System:Print("executing average") return (intA + intB + intC)/3 end float call_average(Entity* e, string funcName, int a, int b, int c) { if (e->component == NULL) return false; bool success = false; //Get the component table int stacksize = Interpreter::GetStackSize(); //Get the global error handler function int errorfunctionindex = 0; #ifdef DEBUG Interpreter::GetGlobal("LuaErrorHandler"); errorfunctionindex = Interpreter::GetStackSize(); #endif e->Push(); Interpreter::GetField("script"); if (Interpreter::IsTable()) { System::Print(" entity has script"); Interpreter::GetField(funcName); if (Interpreter::IsFunction()) { System::Print(" " + funcName + " defined"); Interpreter::PushValue(-2);//Push script table onto stack Interpreter::PushInt(a); Interpreter::PushInt(b); Interpreter::PushInt(c); #ifdef DEBUG errorfunctionindex = -(Interpreter::GetStackSize() - errorfunctionindex + 1); #endif success = Interpreter::Invoke(4, 1, errorfunctionindex); //in=4, out=1 // //---------------------------- here the receiving part ******NEW****** // if (success) { if (Interpreter::IsNumber()) { float retValue = Interpreter::ToNumber(); System::Print(retValue); return retValue; } } /* //how to retrieve more than one returned parameter: //if function returns two or more parameters, they are poped in inverse order //so be careful to ask for them in reverse order (from right to left) Interpreter::Pop(); //pop it if (Interpreter::IsNumber()) { float retValue = Interpreter::ToNumber(); System::Print(retValue); } */ } } Interpreter::SetStackSize(stacksize); } Types that can be tested: Interpreter::isBool, isFunction, isBreakpoint, isNumber, isConnected, isString, isObject, isTable Types that can be converted to: Interpreter::toNumber, toString, toBool o toObject not so easy but with a recipe all things are made easy, no? just in case you missed it on the code... if you like you may return more than one value from LUA LUA admit Return to give a list of comma separated values Return value1, value1, ... they are pushed and when popped, came in reverse order you have to use Interpreter::pop() or retrieving each value and then testing it's type and converting back from lua type to c++ type next tut is more long and perhaps i'll post later... Next, Home, Previous
×
×
  • Create New...