Probably. Beyond that I'm afraid I'm no help :(
Probably. Beyond that I'm afraid I'm no help :(
Post #522
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.)
Play around with the FoV until you find something you like.
Something confusing that I just can't figure out and I'm probably going to feel stupid once I get this working.
Errors I'm getting: (I'm certain it has something to do with the two headers including eachother)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 */
Output
help most appreciated :buddy: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)
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:
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
Messing with the FoV and distance seemed to help the most. Its not perfect but its a lot better.
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!
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.
How would I get the reader to change the resolution?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(); }
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.
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
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.
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...
Can anyone help me with SFML and OpenGL? for some reason even the example opengl doesn't work
ApparentlyCode://////////////////////////////////////////////////////////// // 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; }
is giving the error...Code:gluPerspective(90.f, 1.f, 1.f, 500.f);
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 ==========
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.
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.
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.
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
How do I call bleh() from a C++ program?Code:function bleh() print( "dicks" ) end
#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
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
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.
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
general.hCode:#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; }
I don't know what the problem is, I'm new to SFML and Box2D so yea.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; }
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.
Post #547
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!
So I'm trying to do integer division that rounds to the nearest integer instead of always flooring. I've come up with this:
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?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
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
Anyone know how to return an enum in C#?
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); }
Can't you just return MyEnum.SomeEnum ?
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?
Solved. Added you on steam for explanation
Please post a summary here for someone who may come across the post later.
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.
Never mind, I fixed my error, it turned out 1 / 60 isn't automatically floating point arithmetic so it just evaluated to zero instead.
Didn't get an invite so I sent one to you instead![]()
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?