1. Post #521
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Probably. Beyond that I'm afraid I'm no help :(
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  2. Post #522
    Wyzard's Avatar
    June 2008
    1,243 Posts
    Anyone know how to fix the perceptive so it doesn't stretch the geometry at the edges of the screen?
    If you want to reduce the perspective effect, move the camera back and narrow its field of view. Read about dolly zoom to understand why.

    (If you dolly-zoomed the camera back to an infinite distance, that'd be an orthographic view.)
    Reply With Quote Edit / Delete Linux United States Show Events

  3. Post #523
    Gold Member
    WeltEnSTurm's Avatar
    December 2007
    1,874 Posts
    Play around with the FoV until you find something you like.
    Reply With Quote Edit / Delete Windows 7 Austria Show Events

  4. Post #524
    HQRSE FUCKER
    ief014's Avatar
    September 2009
    3,054 Posts
    Something confusing that I just can't figure out and I'm probably going to feel stupid once I get this working.

    Code:
    /***********************************************************/
    /************************* State.h *************************/
    /***********************************************************/
    
    #ifndef __SYS_STATE_H__
    #define __SYS_STATE_H__
    
    #include <vector>
    
    #include <sys/Component.h>
    
    namespace sys
    {
    	
    	class State
    	{
    	public:
    		State(void);
    		~State(void);
    
    		bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds
    
    		virtual void Initialized();
    		virtual void Exit();
    		virtual void Tick(float dt);
    		virtual void Draw();
    
    		virtual void OnMouseMove(int x, int y);
    		virtual void OnMouseDown(int x, int y, unsigned int button);
    		virtual void OnMouseUp(int x, int y, unsigned int button);
    		virtual void OnMouseWheel(int x, int y, int d);
    		virtual void OnKeyPress(char key);
    		virtual void OnKeyUnpress(char key);
    
    		inline bool IsFocused(const Component &c);
    
    	protected:
    		std::vector<Component*> Components;
    
    	private:
    		Component* focusedComponent_;
    	};
    
    }
    
    #endif // __SYS_STATE_H__
    
    /***********************************************************/
    /*********************** Component.h ***********************/
    /***********************************************************/
    
    #ifndef __SYS_COMPONENT_H__
    #define __SYS_COMPONENT_H__
    
    #include "Point.h"
    #include "State.h"
    
    namespace sys
    {	
    	
    	class Component  
    	{
    	public:
    		Component(State* s);
    		~Component();
    
    		Point Position;
    		Point Size;
    		bool Locked;
    		bool Visible;
    
    		virtual void Tick(float dt);
    		virtual void Draw();
    
    		virtual void OnMouseHover(int localx, int localy);
    		virtual void OnMouseMoved(int localx, int localy);
    		virtual void OnMouseMovedInside(int localx, int localy);
    		virtual void OnMouseDown(int x, int y, unsigned int button);
    		virtual void OnMouseUp(int x, int y, unsigned int button);
    		virtual void OnMouseClick(int localx, int localy, unsigned int button);
    		virtual void OnMouseUnclick(int localx, int localy, unsigned int button);
    		virtual void OnMouseWheel(int localx, int localy, unsigned int button);
    		virtual void OnKeyPress(char key);
    		virtual void OnKeyUnpress(char key);
    
    	private:
    		State* parent_;
    		
    	};
    }
    
    #endif // __SYS_COMPONENT_H__
    
    /***********************************************************/
    /********************** Component.cpp **********************/
    /***********************************************************/
    
    #include "Point.h"
    #include "State.h"
    
    #include "Component.h"
    
    using namespace sys;
    
    Component::Component(State* s)
    :
    parent_(s),
    Position(Point(0,0)),
    Size(Point(0,0))
    {
    }
    
    Component::~Component()
    {
    }
    
    /* 
    	Removed bunch of empty voids from header for this paste
    */
    Errors I'm getting: (I'm certain it has something to do with the two headers including eachother)

    Output
    Code:
     Compiling...
    Engine.cpp
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(13) : error C2061: syntax error : identifier 'State'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C2143: syntax error : missing ';' before '*'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    main.cpp
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(13) : error C2061: syntax error : identifier 'State'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C2143: syntax error : missing ';' before '*'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    State.cpp
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(13) : error C2061: syntax error : identifier 'State'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C2143: syntax error : missing ';' before '*'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\state.cpp(31) : warning C4018: '<' : signed/unsigned mismatch
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\state.cpp(49) : warning C4018: '<' : signed/unsigned mismatch
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\state.cpp(59) : warning C4018: '<' : signed/unsigned mismatch
    Component.cpp
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(13) : error C2061: syntax error : identifier 'State'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C2143: syntax error : missing ';' before '*'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.cpp(9) : error C2511: 'sys::Component::Component(sys::State *)' : overloaded member function not found in 'sys::Component'
            c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.h(11) : see declaration of 'sys::Component'
    c:\users\ief015\documents\visual studio 2008\projects\mitosis\mitosis\sys\component.cpp(67) : fatal error C1004: unexpected end-of-file found
    Generating Code...
    
    Results
    Build log was saved at "file://c:\Users\ief015\Documents\Visual Studio 2008\Projects\mitosis\mitosis\Debug\BuildLog.htm"
    mitosis - 18 error(s), 3 warning(s)
    help most appreciated :buddy:
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  5. Post #525
    Wyzard's Avatar
    June 2008
    1,243 Posts
    You have circular includes: State.h includes Component.h, and Component.h includes State.h. The #include "State.h" in Component.h does nothing because __SYS_STATE_H__ is already defined, because line 5 in State.h is the reason why Component.h is being read in the first place.
    Reply With Quote Edit / Delete Linux United States Show Events

  6. Post #526
    HQRSE FUCKER
    ief014's Avatar
    September 2009
    3,054 Posts
    You have circular includes: State.h includes Component.h, and Component.h includes State.h. The #include "State.h" in Component.h does nothing because __SYS_STATE_H__ is already defined, because line 5 in State.h is the reason why Component.h is being read in the first place.
    Ugh, I knew it was something like that. I've been on a programming hiatus for a couple months and I'm trying to get back at it. ;D Thanks

    Edited:

    You have circular includes: State.h includes Component.h, and Component.h includes State.h. The #include "State.h" in Component.h does nothing because __SYS_STATE_H__ is already defined, because line 5 in State.h is the reason why Component.h is being read in the first place.
    Interesting

    I have removed Component(State* s); in Component.cpp and replaced it with a blank constructor and modified the .cpp as necessary, and the same with State* parent_; and now it seems to be compiling without errors.

    This is basically what I'm trying to do http://pastebin.com/7qNJw6Rt
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  7. Post #527
    Gold Member
    foszor's Avatar
    April 2005
    919 Posts
    Messing with the FoV and distance seemed to help the most. Its not perfect but its a lot better.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  8. Post #528
    HQRSE FUCKER
    ief014's Avatar
    September 2009
    3,054 Posts
    Oh god :doh:, I just realised I could define the other class as "class State;" in Components.h and "class Component;" in State.h

    Woohoo!
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  9. Post #529
    SirCrest Sexual Enthusiast
    wingless's Avatar
    August 2008
    14,687 Posts
    Hey guys, I've been working on a small game in XNA and I want to use XML files for config, you know, screen res, fullscreen. shit like that.
    So I want it to read then use what it's read to control the engine size. Right now it's basically this.
    Code:
            public void Read()
            {
                XmlTextReader textReader = new XmlTextReader("%USERPROFILE%\\Saved Games\\Saturn\\settings.config");
                textReader.Read();
            }
    
            public void Size()
            {
                graphics.PreferredBackBufferWidth = 800;
                graphics.PreferredBackBufferHeight = 600;
                graphics.IsFullScreen = false;
                graphics.ApplyChanges();
            }
    How would I get the reader to change the resolution?
    Reply With Quote Edit / Delete Windows 7 Australia Show Events

  10. Post #530
    SourBree's Avatar
    June 2010
    239 Posts
    I made a thread about this but I might as well also ask here. Does anyone know of any useful tutorials or of any open source program written in Python 3 with Pygame (it must be 3) that deal with map making? I mean just simple 2D map making btw. I want to have something to base my map maker off of so I don't start coding it super horribly. I'm just trying to make a simple platformer.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  11. Post #531
    mutated's Avatar
    October 2010
    1,514 Posts
    Messing with the FoV and distance seemed to help the most. Its not perfect but its a lot better.
    Taking an easy example like Minecraft - resize the window to an extremely wide window and you get stretching like this, that really can't be avoided.

    Normal shot of a house:
    I moved forward a bit to get a better example of stretching, but here you go:
    check out that fuggin' torch
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  12. Post #532
    Reply With Quote Edit / Delete Linux Germany Show Events Useful Useful x 1 (list)

  13. Post #533
    Nigey Nige's Avatar
    June 2010
    1,340 Posts
    You know how GET puts the parametres in the URL?

    Well, POST sends them separately.
    Just... Look up HTTP documentation somewhere.
    Install Wireshark and have it capture traffic while you upload a file to a website somewhere. Looking at some valid HTTP traffic will probably help more than just reading specs.
    So I did both of these, but everything I know about programming is in Java, and I can't figure out how all this information translates. I don't know the syntax for all the stuff that's being explained, and nowhere seems to have the info in a format I can understand. All I want to do is make an app that uploads images to tumblr! :smith:

    Edited:



    I'm just gonna go bang my head against a wall for a while.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Funny Funny x 1 (list)

  14. Post #534
    RyanDv3's Avatar
    May 2008
    999 Posts
    Right. I am using a Timer, to increase an int value, which determines the rotation of my rectangle, the code for that:
    		rectrotation = new Timer(100, new RectRotationHandler());
    
    	class RectRotationHandler implements ActionListener{
    		public void actionPerformed(ActionEvent e){
    			rotation += 5;
    		}
    	}
    
    

    Now, for the drawing, I use a BufferedImage, like this:

    		public void drawRectangle(){
    		Graphics2D b = buffer.createGraphics();
    		if(b instanceof Graphics2D){
    			b.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    			b.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    		}
    		int rectx = 80;
    		int recty = 80;
    		b.rotate(rotation * Math.PI / 180);
    		b.setColor(Color.RED);
    		b.drawRect(rectx,recty,40,40);
    	}

    The rectangle is drawn with a simple drawRect(), and the rotation is done by doing b.rotate(), with as parameter the rotation int, which is being increased by the timer, so it rotates automatically. Now, I need to mess with the b.translate, so it doesn't rotate around the 0,0 axis of my level, but I have no idea how.

    Edited:



    Look at post #506
    You are drawing your rectangle with an offset: don't do that.

    Instead, b.translate() to rectx and recty, b.rotate(), and then b.drawRect(-20, -20, 20, 20).


    This is of course assuming whatever library you are using works how I think it works...
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  15. Post #535
    Gold Member
    Bambo.'s Avatar
    April 2011
    486 Posts
    Can anyone help me with SFML and OpenGL? for some reason even the example opengl doesn't work

    Code:
    ////////////////////////////////////////////////////////////
    // Headers
    ////////////////////////////////////////////////////////////
    #include <SFML/Window.hpp>
    
    
    ////////////////////////////////////////////////////////////
    /// Entry point of application
    ///
    /// \return Application exit code
    ///
    ////////////////////////////////////////////////////////////
    int main()
    {
        // Create the main window
        sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL");
    
        // Create a clock for measuring time elapsed
        sf::Clock Clock;
    
        // Set color and depth clear value
        glClearDepth(1.f);
        glClearColor(0.f, 0.f, 0.f, 0.f);
    
        // Enable Z-buffer read and write
        glEnable(GL_DEPTH_TEST);
        glDepthMask(GL_TRUE);
    
        // Setup a perspective projection
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(90.f, 1.f, 1.f, 500.f);
    
        // Start game loop
        while (App.IsOpened())
        {
            // Process events
            sf::Event Event;
            while (App.GetEvent(Event))
            {
                // Close window : exit
                if (Event.Type == sf::Event::Closed)
                    App.Close();
    
                // Escape key : exit
                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                    App.Close();
    
                // Resize event : adjust viewport
                if (Event.Type == sf::Event::Resized)
                    glViewport(0, 0, Event.Size.Width, Event.Size.Height);
            }
    
            // Set the active window before using OpenGL commands
            // It's useless here because active window is always the same,
            // but don't forget it if you use multiple windows or controls
            App.SetActive();
    
            // Clear color and depth buffer
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
            // Apply some transformations
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            glTranslatef(0.f, 0.f, -200.f);
            glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
            glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
            glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
    
            // Draw a cube
            glBegin(GL_QUADS);
    
                glVertex3f(-50.f, -50.f, -50.f);
                glVertex3f(-50.f,  50.f, -50.f);
                glVertex3f( 50.f,  50.f, -50.f);
                glVertex3f( 50.f, -50.f, -50.f);
    
                glVertex3f(-50.f, -50.f, 50.f);
                glVertex3f(-50.f,  50.f, 50.f);
                glVertex3f( 50.f,  50.f, 50.f);
                glVertex3f( 50.f, -50.f, 50.f);
    
                glVertex3f(-50.f, -50.f, -50.f);
                glVertex3f(-50.f,  50.f, -50.f);
                glVertex3f(-50.f,  50.f,  50.f);
                glVertex3f(-50.f, -50.f,  50.f);
    
                glVertex3f(50.f, -50.f, -50.f);
                glVertex3f(50.f,  50.f, -50.f);
                glVertex3f(50.f,  50.f,  50.f);
                glVertex3f(50.f, -50.f,  50.f);
    
                glVertex3f(-50.f, -50.f,  50.f);
                glVertex3f(-50.f, -50.f, -50.f);
                glVertex3f( 50.f, -50.f, -50.f);
                glVertex3f( 50.f, -50.f,  50.f);
    
                glVertex3f(-50.f, 50.f,  50.f);
                glVertex3f(-50.f, 50.f, -50.f);
                glVertex3f( 50.f, 50.f, -50.f);
                glVertex3f( 50.f, 50.f,  50.f);
    
            glEnd();
    
            // Finally, display rendered frame on screen
            App.Display();
        }
    
        return EXIT_SUCCESS;
    }
    Apparently
    Code:
     gluPerspective(90.f, 1.f, 1.f, 500.f);
    is giving the error...

    Code:
    1>------ Build started: Project: SFML-TEST, Configuration: Debug Win32 ------
    1>  main.cpp
    1>main.obj : error LNK2001: unresolved external symbol _gluPerspective@32
    1>C:\Users\Bamford\documents\visual studio 2010\Projects\SFML-TEST\Debug\SFML-TEST.exe : fatal error LNK1120: 1 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events Agree Agree x 1 (list)

  16. Post #536
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    Can anyone help me with SFML and OpenGL? for some reason even the example opengl doesn't work
    Make sure you link with glu32.lib.
    Reply With Quote Edit / Delete Windows XP Norway Show Events Friendly Friendly x 1 (list)

  17. Post #537
    Gold Member
    Bambo.'s Avatar
    April 2011
    486 Posts
    Make sure you link with glu32.lib.
    Ah ok, i'll give that a shot.

    It doesn't say anything about that in the tutorials, i dont think?

    Edited:

    Ah fantastic, it works!

    Thanks alot.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  18. Post #538
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,451 Posts
    I guess it assumes you already know something on how to use OpenGL with your compiler, so I doesn't bother tell you which libraries to link to and so on.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  19. Post #539
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    It doesn't say anything about that in the tutorials, i dont think?
    The answer depends entirely on your programming environment, which the error message you posted gave away. And as Chris220 said, it's probably not in the scope of the tutorial anyway.
    Reply With Quote Edit / Delete Windows XP Norway Show Events

  20. Post #540
    T3hGamerDK's Avatar
    January 2011
    2,551 Posts
    I've been working on a simple game engine project for a few of my friends to use, and even though I'm not very experienced with much programming at all in C++, and it's QUITE a big step, it's something I'm all up for.
    BUT, I've run into a dead end. I can't for the love of all that is sacred figure out how to use lua 5.1 to, when embedded, load a script, and then execute only a function from that script. How is it possible?

    tl;rd
    Call lua function from c++ code
    Code:
    function bleh()
        print( "dicks" )
    end
    How do I call bleh() from a C++ program?
    Reply With Quote Edit / Delete Linux Denmark Show Events

  21. Post #541
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    I've been working on a simple game engine project for a few of my friends to use, and even though I'm not very experienced with much programming at all in C++, and it's QUITE a big step, it's something I'm all up for.
    BUT, I've run into a dead end. I can't for the love of all that is sacred figure out how to use lua 5.1 to, when embedded, load a script, and then execute only a function from that script. How is it possible?

    tl;rd
    Call lua function from c++ code
    Code:
    function bleh()
        print( "dicks" )
    end
    How do I call bleh() from a C++ program?
    #include <iostream>
    #include <lua.hpp>
    
    int main()
    {
        lua_State* L = luaL_newstate();
        luaL_openlibs(L); // for the print function
    
        if(luaL_dofile(L, "myscript.lua") != 0)
        {
            std::cerr << lua_tostring(L, -1) << std::endl;
            return 1;
        }
    
        lua_getglobal(L, "bleh");
        lua_call(L, 0, 0);
    }
    
    Reply With Quote Edit / Delete Windows XP Norway Show Events

  22. Post #542
    T3hGamerDK's Avatar
    January 2011
    2,551 Posts
    #include <iostream>
    #include <lua.hpp>
    
    int main()
    {
        lua_State* L = luaL_newstate();
        luaL_openlibs(L); // for the print function
    
        if(luaL_dofile(L, "myscript.lua") != 0)
        {
            std::cerr << lua_tostring(L, -1) << std::endl;
            return 1;
        }
    
        lua_getglobal(L, "bleh");
        lua_call(L, 0, 0);
    }
    
    I just tried the above code, but the value seems to be nil for some reason.
    (Reason: PANIC: unprotected error in call to Lua API (attempt to call a nil value))
    And nothing happens when doing a pcall instead of call.
    It may be worth noting the following though, as I forgot to mention them earlier:
    I've already done a lua_pcall on the script, to run some whatever is NOT a function.
    Do I need to somehow "empty" the lua state and reload the script and THEN load the functions, or should I be able to do it straight forward? To help you with this, I'll link to my code (the important part) below.
    main.cpp: http://codepaste.net/o4qji4
    log.lua http://codepaste.net/gaf8dr
    Reply With Quote Edit / Delete Linux Denmark Show Events

  23. Post #543
    Richy19's Avatar
    May 2010
    5,384 Posts
    Is it possible to get information from a minecraft server without needing a minecraft user?
    Just stuff like the amount of players it allows and stuff like that?

    Should also say that this would be over the internet so not locally
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  24. Post #544
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,685 Posts
    I just tried the above code, but the value seems to be nil for some reason.
    I just tested it as well. It works fine.

    (Using my code for the C++ program, and your example Lua code for myscript.lua)

    (Reason: PANIC: unprotected error in call to Lua API (attempt to call a nil value))
    If there is no global variable named "bleh" (case-sensitive) by the end of myscript.lua, this error would occur. Either the function "bleh" was never defined, or the value of "bleh" was later set to nil before the end of the script.

    And nothing happens when doing a pcall instead of call.
    lua_pcall returns non-zero and pushes an error to the stack if an error occurs while calling the supplied function. lua_call raises an error; if no error handler (like a call to pcall or lua_pcall) is currently present somewhere up the stack, the panic function is called and the program aborted. That means with lua_pcall, the burden of handling the error is on you - don't use it unless you're planning on handling the error then and there.

    It may be worth noting the following though, as I forgot to mention them earlier:
    I've already done a lua_pcall on the script, to run some whatever is NOT a function. (What do you mean?)
    Do I need to somehow "empty" the lua state and reload the script and THEN load the functions, or should I be able to do it straight forward?
    There is no need to reset the Lua state (BTW, you would have to create a new one for that), everything that needs to be present for the last bit of your C++ code is a global variable named "onExit", such as the one defined in log.lua.

    It's important to note that you're not actually handling any error that might have occurred if luaL_loadfile failed: you're just ignoring it, and to make it worse, you're not actually calling the loaded function (your script) if an error did occur (which is bad because lua_pcall would in some way hint at the error). My guess is that loading log.lua somehow failed and that's why onExit doesn't exist. In your case you should be using luaL_dofile and handling errors in a similar fashion to my example.

    Others things to note: use luaL_newstate instead of the deprecated lua_open, and don't use LUA_MULTRET unless you're actually expecting a variable number of return values.

    edit:

    Looking at the log.lua paste again; the first line is not actually there, right? Single-line comments in Lua are done with --, not #. luaL_loadfile would fail on such input.
    Reply With Quote Edit / Delete Windows XP Norway Show Events Informative Informative x 1 (list)

  25. Post #545
    awfa3's Avatar
    April 2007
    185 Posts
    Can someone help me get this box2d thing to simulate? I made a quick prototype program to try to implement SFML and box2d together with a class but the problem is, the box that is suppose to be falling on the ground plane isn't moving.

    main.cpp
    Code:
    #include <SFML/Graphics.hpp>
    #include <Box2d/Box2D.h>
    #include "general.h"
    
    int main() {
        //Create the SFML Window
        sf::RenderWindow Game(sf::VideoMode(800, 600, 32), "SFML Window");
    
        //Make a Reference to the Input Handler
        const sf::Input& input = Game.GetInput();
    
        //Create SFML Event Handler
        sf::Event Event;
    
        //Make View
        sf::View cam = Game.GetDefaultView();
    
        //Box2D World Settings
        b2Vec2 gravity(0.0f, -9.81f);
        bool doSleep = true;
        int32 iterations = 10;
        float timeStep = 1/60;
        
        b2World world(gravity, doSleep);
    
        //Ground Box Color
        sf::Color groundC[4];
        for (int i = 0; i < 4; ++i) {
            groundC[i] = sf::Color(255, 0, 0);
        }
    
        //Dynamic Box Color
        sf::Color boxC[4];
        for (int i = 0; i < 4; ++i) {
            boxC[i] = sf::Color(0, 0, 255);
        }
    
        //Make the boxes
        shape groundBox(b2_staticBody, world, 0.0f, -10.f, 0, 0, makeBox(50, 10), groundC, sf::Color(), 0.0f, 4);
        shape dynamicBox(b2_dynamicBody, world, 0.0f, 4.0f, 1.0f, 0.3f, makeBox(1, 1), boxC, sf::Color(), 0.0f, 4);
    
        //Center view on the dynamic box, rotate view, and zoom in
        cam.SetCenter(dynamicBox.getBody()->GetWorldCenter().x, dynamicBox.getBody()->GetWorldCenter().y);
        cam.Rotate(180.f);
        cam.Zoom(0.12f);
        Game.SetView(cam);
    
        //Game Loop
        while (Game.IsOpened()) {
            //Event Handler Loop
            while (Game.PollEvent(Event)) {
                //If 'X'd out, close the game window
                if (Event.Type == sf::Event::Closed) {
                    Game.Close();
                }
            }
            //If escape is pressed, then close the game window
            if (input.IsKeyDown(sf::Key::Escape)) {
                Game.Close();
            }
    
            //Clear the Game Window
            Game.Clear(sf::Color(100, 149, 237));
    
            //Calculate the positions and stuff
            world.Step((1/60), 10, 10);
            world.ClearForces();
    
            //Update the position and angles of the SFML shapes
            groundBox.update();
            dynamicBox.update();
    
            //Draw the shapes
            Game.Draw(groundBox.getShape());
            Game.Draw(dynamicBox.getShape());
            
            //Display SFML graphics to the window
            Game.Display();
        }
    
        return EXIT_SUCCESS;
    }
    general.h
    Code:
    static const double PI = 2*acos(0.0);
    
    class shape {
    public:
        shape(b2BodyType bodyType, b2World &world, float x, float y, float density, float friction, b2Vec2 *verticies, sf::Color *colors, sf::Color outline, float outlineWidth, int vCount);
        ~shape() {}
    
        void update();
        sf::Shape getShape() const { return polygon; }
        b2Body* getBody() const { return body; }
    private:
        //Box2D
        b2BodyDef bodyDef;
        b2Body* body;
        b2PolygonShape b2Polygon;
        b2FixtureDef fixtureDef;
    
        //SFML
        sf::Shape polygon;
    };
    
    shape::shape(b2BodyType bodyType, b2World &world, float x, float y, float density, float friction, b2Vec2 *verticies, sf::Color *colors, sf::Color outline, float outlineWidth, int vCount) {
        //Box2D
        bodyDef.type = bodyType;
        bodyDef.position.Set(x, y);
        body = world.CreateBody(&bodyDef);
    
        b2Polygon.Set(verticies, vCount);
    
        fixtureDef.shape = &b2Polygon;
        fixtureDef.density = density;
        fixtureDef.friction = friction;
    
        body->CreateFixture(&fixtureDef);
        
        //SFML
        for (int i = 0; i < vCount; ++i) {
            polygon.AddPoint(verticies[i].x, verticies[i].y, colors[i], outline);
        }
    
        polygon.SetOutlineThickness(outlineWidth);
        polygon.SetPosition(x, y);
    }
    
    void shape::update() {
        polygon.SetPosition(body->GetPosition().x, body->GetPosition().y);
        polygon.SetRotation(body->GetAngle() * (180.f/PI));
    }
    
    b2Vec2 *makeBox(float x, float y) {
        b2Vec2 temp[4];
        temp[0].Set(-x, y);
        temp[1].Set(-x, -y);
        temp[2].Set(x, -y);
        temp[3].Set(x, y);
        return temp;
    }
    I don't know what the problem is, I'm new to SFML and Box2D so yea.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  26. Post #546
    Gold Member
    vexx21322's Avatar
    December 2008
    10,581 Posts
    C#

    I am using .AddRange to add a bunch of filenames, to a list, from different locations. Then I want to sort them for easy searching and whatnot, but list.sort sorts the individual ranges and not all of them as one big list.

    Now, I'm new to C# so I don't exactly know what's going on.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  27. Post #547
    T3hGamerDK's Avatar
    January 2011
    2,551 Posts
    I just tested it as well. It works fine.

    (Using my code for the C++ program, and your example Lua code for myscript.lua)

    If there is no global variable named "bleh" (case-sensitive) by the end of myscript.lua, this error would occur. Either the function "bleh" was never defined, or the value of "bleh" was later set to nil before the end of the script.

    lua_pcall returns non-zero and pushes an error to the stack if an error occurs while calling the supplied function. lua_call raises an error; if no error handler (like a call to pcall or lua_pcall) is currently present somewhere up the stack, the panic function is called and the program aborted. That means with lua_pcall, the burden of handling the error is on you - don't use it unless you're planning on handling the error then and there.

    There is no need to reset the Lua state (BTW, you would have to create a new one for that), everything that needs to be present for the last bit of your C++ code is a global variable named "onExit", such as the one defined in log.lua.

    It's important to note that you're not actually handling any error that might have occurred if luaL_loadfile failed: you're just ignoring it, and to make it worse, you're not actually calling the loaded function (your script) if an error did occur (which is bad because lua_pcall would in some way hint at the error). My guess is that loading log.lua somehow failed and that's why onExit doesn't exist. In your case you should be using luaL_dofile and handling errors in a similar fashion to my example.

    Others things to note: use luaL_newstate instead of the deprecated lua_open, and don't use LUA_MULTRET unless you're actually expecting a variable number of return values.

    edit:

    Looking at the log.lua paste again; the first line is not actually there, right? Single-line comments in Lua are done with --, not #. luaL_loadfile would fail on such input.
    Thanks a bunch! I tried doing the code the same way you did yours (which really does seem more logical as well), and I double-checked the code in the log.lua file and you were right. I had it print all the errors, and it closes the script as soon as it reaches anything past "LOG =", since I was doing the lua coding wrong.
    Seems I need to re-learn lua again.

    Thanks!
    Reply With Quote Edit / Delete Linux Denmark Show Events Friendly Friendly x 1 (list)

  28. Post #548
    Gold Member
    pebkac's Avatar
    January 2009
    2,617 Posts
    So I'm trying to do integer division that rounds to the nearest integer instead of always flooring. I've come up with this:
    Code:
    def int_div(a,b):
    	""" Properly rounded integer division. """
    	if b < 0: 
    		a,b = -a,-b
    	if (a % b) * 2 >= b:
    		return a // b + 1
    	else:
    		return a // b
    The problem is, it's 2.5x slower than regular int division, which seems a bit pointless for such a small improvement of results. Is there any faster algorithm for doing it?
    Reply With Quote Edit / Delete Windows Vista Slovenia Show Events

  29. Post #549
    SupahVee's Avatar
    December 2007
    1,113 Posts
    http://stackoverflow.com/questions/6...abb-collisions

    Can anyone help? I can't figure out a way to solve this
    Reply With Quote Edit / Delete Windows 7 Italy Show Events

  30. Post #550
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,451 Posts
    http://stackoverflow.com/questions/6...abb-collisions

    Can anyone help? I can't figure out a way to solve this
    I've had this exact same problem before, please tell me if you find a solution, I couldn't think of anything to fix it
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  31. Post #551
    Jimmylaw's Avatar
    November 2007
    506 Posts
    Anyone know how to return an enum in C#?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  32. Post #552
    Gold Member
    robmaister12's Avatar
    January 2008
    4,969 Posts
    do you mean the enum type itself or a value of a specific enum?

    If you mean a specific value (say you have a "public enum MyEnum { option1, option2 }")

    public MyEnum DoSomething(int i)
    {
        if (i > 5)
            return MyEnum.option1;
        return MyEnum.option2;
    }

    if you want it to return the enum type,

    public Type GetEnumType()
    {
        return typeof(MyEnum);
    }
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  33. Post #553
    Gold Member
    Darwin226's Avatar
    January 2009
    4,080 Posts
    Can't you just return MyEnum.SomeEnum ?
    Reply With Quote Edit / Delete Windows 7 Croatia Show Events

  34. Post #554
    Gold Member
    ThePuska's Avatar
    October 2005
    3,418 Posts
    So I'm trying to do integer division that rounds to the nearest integer instead of always flooring. I've come up with this:
    Code:
    def int_div(a,b):
    	""" Properly rounded integer division. """
    	if b < 0: 
    		a,b = -a,-b
    	if (a % b) * 2 >= b:
    		return a // b + 1
    	else:
    		return a // b
    The problem is, it's 2.5x slower than regular int division, which seems a bit pointless for such a small improvement of results. Is there any faster algorithm for doing it?
    If there's no function for calculating the quotient and modulus of a division simultaneously, you can't really get faster than that in the language itself.

    I don't know how Python works but I'd assume that you can write and compile an extension for it in C. In that case one would just use subsequent division and modulus operations and trust that the compiler knows how to optimize it into an idiv, assuming the architecture supports it.

    In short, is the speed gain worth the trouble?
    Reply With Quote Edit / Delete Windows 7 Finland Show Events

  35. Post #555
    SupahVee's Avatar
    December 2007
    1,113 Posts
    I've had this exact same problem before, please tell me if you find a solution, I couldn't think of anything to fix it
    Solved. Added you on steam for explanation
    Reply With Quote Edit / Delete Windows 7 Italy Show Events

  36. Post #556
    Gold Member
    Lord Ned's Avatar
    April 2006
    3,702 Posts
    Solved. Added you on steam for explanation
    Please post a summary here for someone who may come across the post later.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Agree Agree x 2 (list)

  37. Post #557
    Gold Member
    pebkac's Avatar
    January 2009
    2,617 Posts
    If there's no function for calculating the quotient and modulus of a division simultaneously, you can't really get faster than that in the language itself.

    I don't know how Python works but I'd assume that you can write and compile an extension for it in C. In that case one would just use subsequent division and modulus operations and trust that the compiler knows how to optimize it into an idiv, assuming the architecture supports it.

    In short, is the speed gain worth the trouble?
    I've actually heard from someone a while ago that the CPU calculates the modulo and quotient simultaneously, so naturally I checked if there's a built-in function that does that. Turns out that there is, it's divmod(), but for some reason it's slower than doing them separately. I guess the implementation just sucks.

    Anyway, I'll probably keep using my way of doing it, and if it turns out to be too slow for my purposes, I'll just use normal integer division as the extra precision isn't that important.
    Reply With Quote Edit / Delete Windows Vista Slovenia Show Events

  38. Post #558
    awfa3's Avatar
    April 2007
    185 Posts
    Never mind, I fixed my error, it turned out 1 / 60 isn't automatically floating point arithmetic so it just evaluated to zero instead.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  39. Post #559
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,451 Posts
    Solved. Added you on steam for explanation
    Didn't get an invite so I sent one to you instead
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  40. Post #560
    SupahVee's Avatar
    December 2007
    1,113 Posts
    Please post a summary here for someone who may come across the post later.
    http://forums.tigsource.com/index.php?topic=20157.0
    second post is the technique I used

    Here's the source code
    http://pastebin.com/bU6FE6BG

    Edited:

    Why does 128.1 - 128.0 gives me a stupid number with a lot of digits after the floating point? (both numbers are floats)

    How do I prevent this?
    Reply With Quote Edit / Delete Windows 7 Italy Show Events