Jump to content

IgorBgz90

Members
  • Posts

    53
  • Joined

  • Last visited

Posts posted by IgorBgz90

  1. Maybe so?

    Pseudocode:

    local distance=self.Object1:GetPosition():DistanceToPoint(self.Object2:GetPosition())
    local distancei=math.floor(pos)--or Math:Round(pos)
    
    context:DrawText("Distance: "..tostring(distancei),2,26)

     

    String format: https://stackoverflow.com/questions/57950030/wow-rounding-to-two-decimal-places-in-lua

     

    Quote

    Here's an example using all the options: string.format("%x6.2f", 2.264)

    From left to right:

    % marks the start
    x tells it to pad right with xs
    6 tells it the whole thing should be 5 characters long
    .2 tells it to round (or pad with 0s) to 2 decimal places
    So, the result would be xx2.26

     

    • Thanks 1
  2. Hi!

    Vehicle Physics

    It would be cool to add Joint:Wheel! Or give the ability to set the speed separately, for each of the wheels (example SetAcceleration(gas,tireIndex)). Аnd to individually rotate each of the wheels (example SetSteering(steering, tireIndex))!

    Sorry for my bad English(

    • Like 1
    • Upvote 1
  3. Hi Josh,

    A couple of years ago I made my dedicated server (app) for minecraft=), there for interception from the console I used pipes. But, this is works only in windows.

    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <stdio.h>
    
    #pragma warning(disable : 4996) // For GetVersionEx
    
    #define bzero(a) memset(a,0,sizeof(a))
    
    char buf[1024];
    STARTUPINFO si;
    SECURITY_ATTRIBUTES sa;
    SECURITY_DESCRIPTOR sd;
    PROCESS_INFORMATION pi;
    HANDLE newstdin, newstdout, read_stdout, write_stdin;
    unsigned long bread;
    unsigned long avail;
    
    bool IsWinNT()
    {
    OSVERSIONINFO osv;
    osv.dwOSVersionInfoSize = sizeof(osv);
    GetVersionEx(&osv);
    return (osv.dwPlatformId == VER_PLATFORM_WIN32_NT);
    }
    std::wstring s2ws(const std::string& s)
    {
    int len;
    int slength = (int)s.length() + 1;
    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
    wchar_t* buf = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
    std::wstring r(buf);
    delete[] buf;
    return r;
    }
    bool CreateAnonymousPipes(std::string procName)
    {
    if (IsWinNT())
    {
    InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(&sd, true, NULL, false);
    sa.lpSecurityDescriptor = &sd;
    }
    else {
    sa.lpSecurityDescriptor = NULL;
    }
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.bInheritHandle = true;
    //CreatePipe(&newstdin, &write_stdin, &sa, 0); //stdin
    CreatePipe(&read_stdout, &newstdout, &sa, 0); //stdout
    GetStartupInfo(&si);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;
    si.hStdOutput = newstdout;
    si.hStdError = newstdout;
    //si.hStdInput = newstdin;
    std::wstring stemp = std::wstring(procName.begin(), procName.end());
    if (CreateProcess(stemp.c_str(), NULL, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, π)) {
    return true;
    }
    bzero(buf);
    return false;
    }
    // Child process stdout
    void ReceiveChild()
    {
    PeekNamedPipe(read_stdout, buf, 1023, &bread, &avail, NULL);
    if (bread != 0)
    {
    bzero(buf);
    if (avail > 1023)
    {
    while (bread >= 1023)
    {
    ReadFile(read_stdout, buf, 1023, &bread, NULL);
    bzero(buf);
    }
    }
    else {
    ReadFile(read_stdout, buf, 1023, &bread, NULL);
    if (buf != "") {
    std::cout << buf << std::endl; // STDOUT
    }
    }
    }
    }
    int main(int argc, char** argv)
    {
    std::string filename;
    if (argc > 1) {
    std::cout << argv[1] << std::endl;
    filename = argv[1];
    }
    
    bool start = CreateAnonymousPipes(filename); // Windowed app start
    while (start) {
    Sleep(1);
    ReceiveChild();
    }
    return 0;
    }
    

  4. Hi Josh! Maybe this will help:

     

    Code from here: http://xopendisplay.hilltopia.ca/2009/Mar/

    int utf8toXChar2b(XChar2b *output_r, int outsize, const char *input, int inlen){
    int j, k;
    for(j =0, k=0; j < inlen && k < outsize; j ++){
    	unsigned char c = input[j];
    	if (c < 128)  {
    		output_r[k].byte1 = 0;
    		output_r[k].byte2 = c; 
    		k++;
    	} else if (c < 0xC0) {
    		/* we're inside a character we don't know  */
    		continue;
    	} else switch(c&0xF0){
    	case 0xC0: case 0xD0: /* two bytes 5+6 = 11 bits */
    		if (inlen < j+1){ return k; }
    		output_r[k].byte1 = (c&0x1C) >> 2;
    		j++;
    		output_r[k].byte2 = ((c&0x3) << 6) + (input[j]&0x3F);
    		k++;
    		break;
    	case 0xE0: /* three bytes 4+6+6 = 16 bits */ 
    		if (inlen < j+2){ return k; }
    		j++;
    		output_r[k].byte1 = ((c&0xF) << 4) + ((input[j]&0x3C) >> 2);
    		c = input[j];
    		j++;
    		output_r[k].byte2 = ((c&0x3) << 6) + (input[j]&0x3F);
    		k++;
    		break;
    	case 0xFF:
    		/* the character uses more than 16 bits */
    		continue;
    	}
    }
    return k;
    }

     

    And convert char* to wchar_t

     

    wchar_t * filename= L"C:\\test";
    char* c = (char*)filename;

  5. Shouldn't it be 4 vertex 2 triangle? You would re-use a couple of vertices.

     

    Looks good btw!

    I'll give it a test

     

    Yes, you are absolutly right. But I do not know for what reason I do not make the indexesph34r.png.

     

    Thanks for test Brutile!

    The error due to lack of microsoft visual c++ 2015 redistributable.

     

    Update:

    Added ebo smile.png

    const float rect[] =
    {
     x, y, 0.0f, 0.0f, 0.0f,
     x + width, y, 0.0f, 1.0f, 0.0f,
     x, y + height, 0.0f, 0.0f, 1.0f,
     //x, y + height, 0.0f, 0.0f, 1.0f,
     //x + width, y, 0.0f, 1.0f, 0.0f,
     x + width, y + height, 0.0f, 1.0f, 1.0f
    };
    GLuint elements[] = {
     0, 1, 2,
     2, 1, 3
    };
    

  6. 2D Karl! Today finished with optimization, should work even Tetris.

    1606 sprites! One sprite 6 vertex 2 triangle.

     

    This is my simple 2D "engine", I may be selling it for $1.000.000, and buy a graphics card for Leadwerks Engine smile.png.

     

    Need your help in testing. I want to make sure that not only works for me.

     

    Camera move:

    Up

    Down

    Left

    Right

     

    Hit Escape key to exit

     

    System requirements:

    Graphic card with support OpenGL 3.3 and shader model 3.0

     

    Download

    Release 2D Engine.zip

    post-13485-0-00127900-1454326895_thumb.png

  7. A simple example of a multiple text.

     

    function App:Start()
      self.maxTextWidth = 128
      self.sourceText = "Text"
      self.tempText = ""
      self.text={}
    
      self.lineCount = 0
    
    
      for w in string.gmatch(self.sourceText, "[%p%a%d]+") do
         if defaultfont:GetTextWidth(self.tempText) < self.maxTextWidth then
            self.tempText = self.tempText.." "..w
         else
            --We need to find the last word, learn length, and delete it.
            local temp1 = string.reverse(self.tempText)
            local temp2 = string.sub(temp1, 1, string.find(temp1," "))
            temp2 = string.reverse(temp2)
            local temp3 = string.sub(self.tempText, 1, string.len(self.tempText)-string.len(temp2))
    
            --Add new line to list.
            self.text[self.lineCount] = temp3
            self.lineCount = self.lineCount + 1
            self.tempText = "" 
    
            --Now we can add the last word to new line.
            self.tempText = self.tempText..temp2.." "..w
         end
      end
      self.text[self.lineCount] = self.tempText
      self.lineCount = self.lineCount + 1 
      self.tempText = ""
    
      return true
    end
    
    function App:Loop()
      --Test text
    
      self.context:SetBlendMode(Blend.Alpha)
      self.context:SetColor(1,1,1,1)
    
      for i=0,self.lineCount,1 do
         self.context:DrawText(self.text[i],150,(150)+15*i);
      end
    
      self.context:SetBlendMode(Blend.Solid)
    
      self.context:Sync(true)
      return true
    end
    

     

    post-13485-0-13920000-1427885120_thumb.png

    • Upvote 3
  8. Hi! I cannot understand how to use your font for button. And then use a standard font.

     

    --Font
    local context = Context:GetCurrent()
    button.font = Font:Load("Fonts/Test.ttf",32) --Custom
    button.defaultfont = context:GetFont() --Arial
    button.color = Vec4(1.0)

     

    Pay attention! I do not release fonts from memory.

     

     

    function Button:Draw()
      local context = Context:GetCurrent()
      local window = Window:GetCurrent()
      if self.enable then
         if self.visible then
            context:SetBlendMode(Blend.Alpha)
    
            --Set user font
            if self.font then context:SetFont(self.font) else self.font = self.defaultfont end
    
            context:DrawText(self.title,25,25)
    
            --Set default font
            context:SetFont(self.defaultfont)
    
            context:SetBlendMode(Blend.Solid)
         end
      end
    end

     

    Log:

    Executing "C:\Users\Igor\Documents\Leadwerks\Projects\MyGame\MyGame.exe"...

    Initializing Lua...

    Lua sandboxing enabled.

    Executing file "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Scripts/Error.lua"

    Executing file "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Scripts/App.lua"

    Initializing OpenGL4 graphics driver...

    OpenGL version 441

    GLSL version 440

    Device: AMD Radeon HD 6320 Graphics

    Loading map "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Maps/start.map"...

    Loading texture "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Materials/Common/bfn.tex"...

    Loading texture "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/materials/sky/skybox_texture.tex"...

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Loading font "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Fonts/test.ttf"...

    Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Editor/skybox.shader"...

    Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Misc/occlusionquery.shader"...

    Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Lighting/ambientlight.shader"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading shader "C:/Users/Igor/Documents/Leadwerks/Projects/MyGame/Shaders/Drawing/drawtext.shader"...

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Loading font "C:/Windows/Fonts/Arial.ttf"...

    Deleting font "C:/Windows/Fonts/Arial.ttf"

    Process Complet

     

    Maybe I'm doing something wrong?

  9. If anyone needs, I'll leave it here smile.png

     

    Timer:

     if Timer~=nil then return end
     Timer={}
    
    function Timer:Create(name, interval,enable)
     local timer={}
     timer.name = name
     timer.interval = interval
     timer.enable = enable
     timer.time = Time:GetCurrent()+timer.interval
     local k,v
     for k,v in pairs(Timer) do
       timer[k] = v
     end  
     return timer
    end
    
    function Timer:Update()
     if self.enable then
       if Time:GetCurrent() > self.time then
      self.time = Time:GetCurrent()+self.interval
      return true
       else
      return false
       end
     end
    end

     

    How to use:

    function App:Start()
     --Timer
     self.time_hours = 0
     self.time_minutes = 0
     self.time_seconds= 0
     self.timer = Timer:Create("timer",1000,true)
    end
    

     

    function App:Loop()
     --Very complex calculation time 
     if self.timer:Update() then
       self.time_seconds= self.time_seconds+1
       if self.time_seconds== 60 then
      self.time_minutes = self.time_minutes+1
      if self.time_minutes == 60 then
        self.time_hours = self.time_hours+1
        self.time_minutes = 0
      end
       self.time_seconds= 0
       end
     end
    
     --Draw current time
     self.context:SetColor(1,1,1,1)
     --Seconds
     local seconds
     if self.time_seconds < 10 then
       seconds = "0"..self.time_seconds
     else
       seconds = self.time_seconds
     end
     --Minutes
     local minutes
     if self.time_minutes < 10 then
       minutes = "0"..self.time_minutes
     else
       minutes = self.time_minutes
     end
     --Hours
     local hours
     if self.time_hours < 10 then
       hours = "0"..self.time_hours
     else
       hours = self.time_hours
     end
     local time_string = hours..":"..minutes..":"..seconds
     self.context:DrawText("Timer: "..time_string,2,2)
    end
    

  10. There is a way to get the texture of the buffer, without a strong drawdown FPS?

     

    Simple code of Monitor:

    function Script:Start()
    --Material
    self.material = Material:Load("Materials/Monitor/monitor.mat")
    self.entity:SetMaterial(self.material)
    
    --Buffer
    self.buffer = Buffer:Create(App.window:GetWidth(),App.window:GetHeight(),1,0);
    self.buffer:SetColorTexture(Texture:Create(App.context:GetWidth(),App.context:GetHeight()))
    self.buffer:Disable();
    end
    
    function Script:UpdateWorld()
    
    self.buffer:Clear()
    self.buffer:Enable()
    self.entity:Hide()
    --self.camera:Show()
    App.world:Render()
    --self.camera:Hide()
    self.buffer:Disable()
    
    self.material:SetTexture(self.buffer:GetColorTexture(),0)
    
    Context:SetCurrent(App.context)
    self.entity:Show()
    end

     

    One monitor, point light and room 4x4

    As a result, the FPS - 5 wacko.png

    If two monitor FPS - 10 etc

     

    Implementation in irrlicht engine:

    ITexture* RTTTex = driver->createRenderTargetTexture(dimension2d<s32>(512,512));

    Result over 75 fps (For me)

     

    Demo, Source code and shaders: irrlicht.zip

    post-13485-0-31451500-1425833048_thumb.png

  11. Thanks. No, texture took from the Internet. Pieces did imposition on the UW texture. (Google Translate smile.png)

    (Спасибо. Нет, текстуру дерева брал из интернета. Затем частично, выборочно вырезал части и накладывал на текстуру UW. Затем, рисовал края.)

    http://pichost.me/1532439/

    • Upvote 1
×
×
  • Create New...