Jump to content

Charrua

Developers
  • Posts

    230
  • Joined

  • Last visited

Posts posted by Charrua

  1. 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?

  2. 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)

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

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

    • Upvote 5
  5. 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)

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

  7. 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 smile.png

     

    i should read the previous post...! sorry

  8. Did you save map file before quit and restart ?

     

    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?

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

     

    cube1.pngcube2.png

     

    cube3.png

  10. the following script fragment, were working ok,

    today i update LE3 and logFile is nil, and the file isn;t created

     

    (this fragment is just for testing that the entities table has the correct ones)

     

    local logFile
    logFile = FileSystem:WriteFile("log.txt")
    if logFile ~= nil then
     for key,value in pairs(entities) do
      logFile:WriteLine(key)
      local pos = value:GetPosition() 
      logFile:WriteLine(pos.x)
     end
     logFile:Release()
    end
    

     

    does any one why?

  11. is it good practice to mix both?

     

    does cpp can call lua functions, use lua variables?

     

    does lua scripts get access to cpp variables, objects, methods

     

    for example, if i made an scene in the editor, attach some scripts to some objects, create and place the camera, etc

     

    how can i get the reference to the editor's camera from cpp

     

    the other way, if i create the camera with cpp, how can i reach it from a lua script.

     

    thank's in advance

     

    Juan

  12. hi

     

    you have to define a Vec3 variable to hold the position, then you can set/test/change individual values

     

    Vec3 Position

     

    Position = Entity:GetPosition()

     

    Then.... Position.x = Position.x+1

     

    i wrote a simple script using Sin and Cos to simulate a Circular movement, you may change speedFactor on x and y coords

     

    Script.xVel=1.0--float x_velocity
    Script.yVel=1.0--float y_velocity
    Script.entPos=Vec3
    Script.initialPos=Vec3
    
    function Script:Start()
     --store initial position
     initialPos = self.entity:GetPosition(false)
    end
    
    function Script:UpdateWorld()
     --read current position
     entPos = self.entity:GetPosition(false)
     --calc new position, relative to the initial one
     entPos.y =  initialPos.y + Math:Sin(Time:GetCurrent()/10.0) * self.yVel
     entPos.x =  initialPos.x + Math:Cos(Time:GetCurrent()/10.0) * self.xVel
     --update new position
     self.entity:SetPosition(entPos.x, entPos.y, entPos.z)
    end
    

     

    create or use a map with one box, and attach this script to the box

     

    to create and attach a script (start form zero) read:

    http://www.leadwerks.com/werkspace/page/tutorials/_/script/creating-your-first-object-script-r110

  13. i realize that 2 worlds aren't needed.

     

    i already have an image for background, so i don't need a background world to render.

     

    i simplify the code above (with no mouse look) and with only one world

     

    basically what is needed is a buffer to render 3d objects and a background image, the magic is done combining the 2 images with

     

    //Draw image, then foreground
    context->Enable();
    context->SetBlendMode(Blend::Alpha);
    context->DrawImage(backImg, 0, 0);
    context->DrawImage(foreground->GetColorTexture(), 0, 0);
    context->SetBlendMode(Blend::Solid);
    

     

    here the code:

    #include "App.h"
    using namespace Leadwerks;
    App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
    App::~App() { delete world; delete window; }
    
    Buffer* foreground = NULL;
    Texture* backImg = NULL;
    bool App::Start()
    {
    //Create a window
    window = Leadwerks::Window::Create("cpp_worlds");
    //Create a context
    context = Context::Create(window);
    //Create a world
    world = World::Create();
    //create buffer for foreground
    foreground = Buffer::Create(context->GetWidth(), context->GetHeight(), 1, 1, 0);
    //create camera for the foreground
    World::SetCurrent(world);
    camera = Camera::Create();
    camera->Move(0, 2, -5);
    //Hide the mouse cursor
    //window->HideMouse();
    //Load the map
    std::string mapname = System::GetProperty("map", "Maps/start.map");
    Map::Load(mapname);
    //Move the mouse to the center of the screen
    window->SetMousePosition(context->GetWidth() / 2, context->GetHeight() / 2);
    
    //load the background image
    backImg = Texture::Load("Materials/backgrounds/backImg.tex");
    return true;
    }
    bool App::Loop()
    {
    //Close the window to end the program
    if (window->Closed()) return false;
    
    //Render foreground
    foreground->Enable();
    world->Update();
    world->Render();
    foreground->Disable();
    //Draw image, then foreground
    context->Enable();
    context->SetBlendMode(Blend::Alpha);
    context->DrawImage(backImg, 0, 0);
    context->DrawImage(foreground->GetColorTexture(), 0, 0);
    context->SetBlendMode(Blend::Solid);
    context->Sync(false);
    return true;
    }
    

     

    btw, where is the buffer documentation?

     

    i understand what is happening but i wish to read/know wich other functions/methods are available for buffers

    • Upvote 1
×
×
  • Create New...