• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=ROBO_DONUT;35464190]1. You appear to have an obsession with using floating-point numbers as divisors in inappropriate places. 2. Your buffer dimensions are off, and you're iterating over the values incorrectly. It's 256 * 256 * 3, not 768 * 768. You should be doing either: [cpp] for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { i = y * 256 + x; point[i*3 + 0] = (float)x; point[i*3 + 1] = (float)y; point[i*3 + 2] = 0.0f; } } [/cpp] or [cpp] for (int i = 0; i < 256*256; i++) { x = i % 256; y = i / 256; point[i*3 + 0] = (float)x; point[i*3 + 1] = (float)y; point[i*3 + 2] = 0.0f; } [/cpp][/QUOTE] I did the first thing :D, im now trying to create the index list. something like this: [IMG]http://i.imgur.com/Ho1Oy.png[/IMG] Would this work? [cpp] std::vector<unsigned int> indices; for (int y = 0; y < 255; y++) { for (int x = 0; x < 255; x++) { int i = y * 256 + x; indices.push_back( i ); i = (y+1) * 256 + x; indices.push_back( i ); i = (y+1) * 256 + x+1; indices.push_back( i ); i = y * 256 + x; indices.push_back( i ); i = (y+1) * 256 + x+1; indices.push_back( i ); i = y * 256 + x+1; * * indices.push_back( i ); } } [/cpp]
[QUOTE=conman420;35467636]Yes, it is just a rough estimate whether or not the sprite should draw.[/QUOTE] Perhaps I'm over-thinking this, but I recall an algorithm that takes a 2D array (of pixels, in your case) and splits them up into the minimal amount of squares. I don't remember what it's called, though. [img_thumb]http://dl.dropbox.com/u/21571661/Pictures/boxes.png[/img_thumb] You could generate these on startup and then check each rectangle's intersection with the screen on Update, and if one hits, draw the whole sprite. But then again, you DID say "rough estimate".
[QUOTE=Richy19;35470663]I did the first thing :D, im now trying to create the index list. something like this: [IMG]http://i.imgur.com/Ho1Oy.png[/IMG] Would this work? [cpp] std::vector<unsigned int> indices; for (int y = 0; y < 255; y++) { for (int x = 0; x < 255; x++) { int i = y * 256 + x; indices.push_back( i ); i = (y+1) * 256 + x; indices.push_back( i ); i = (y+1) * 256 + x+1; indices.push_back( i ); i = y * 256 + x; indices.push_back( i ); i = (y+1) * 256 + x+1; indices.push_back( i ); i = y * 256 + x+1; * * indices.push_back( i ); } } [/cpp][/QUOTE] Looks good to me.
I'm trying to program some basic swarm AI into my game, so each entity needs to be aware of its nearby entities. The only way I can think of doing this so far is by looping through all the entities and calculating the distances between them, but that's O(N^2) and I'd have to do it potentially every frame (if the entities don't all run their AI at the same time). Is there a more efficient algorithm or storage method for the entities that will speed up the process? If it matters, I'm using C++/SFML. Each entity is an object with a sf::RectangleShape member.
Is it completely impossible to define a class and it's functions entirely inside the class and inside a header, in C++? I'm having some trouble with it. [cpp] #ifndef TDG_SCRIPT_HPP #define TDG_SCRIPT_HPP #include <fastcxx/script/luavm.hpp> extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> } #if defined( TDG_SERVER ) #elif defined( TDG_CLIENT ) #include <client/render.hpp> #endif #define SCRIPT_FUNCTION( name ) static int name( lua_State *L ) namespace engine { namespace shared { class script { public: script(); ~script(); void Bind(); private: fastcxx::script::LuaVM *vm; //////////////////////////////////////////// // Console bindings //////////////////////////////////////////// SCRIPT_FUNCTION( io_print ) { return 0; } //////////////////////////////////////////// // I/O bindings //////////////////////////////////////////// SCRIPT_FUNCTION( io_read ) { return 0; } SCRIPT_FUNCTION( io_write ) { return 0; } #if defined( TDG_SERVER ) #elif defined( TDG_CLIENT ) //////////////////////////////////////////// // Render bindings //////////////////////////////////////////// SCRIPT_FUNCTION( render_get_resolution ) { return 0; } SCRIPT_FUNCTION( render_window_settitle ) { return 0; } #endif }; void script::Bind() { #if defined( TDG_SERVER ) #elif defined( TDG_CLIENT ) #endif return; } } } #endif /* TDG_SCRIPT_HPP */ [/cpp] The above code is used in the int main(void) function of my program, but fails to link. Help?
You didn't define the ctor/de-ctor
Also instead of doing: [cpp]extern "C" { ****#include <lua.h> ****#include <lauxlib.h> ****#include <lualib.h> }[/cpp] you can just include lua.hpp
XNA: Why does Viewport.Project() return a Vector3? Shouldn't it be a Vector2? A window is only two-dimensional, after all.
SFML: How do you use sf::rect.(bottom, left, top, right)? I encountered it in a tutorial, and I was thinking of making my own buttons to use it for, but there's only one coordinate to put in.
[QUOTE=Hypershadsy;35473918]XNA: Why does Viewport.Project() return a Vector3? Shouldn't it be a Vector2? A window is only two-dimensional, after all.[/QUOTE] I think the Z value is something to do with the 3D points distance away from you, closer = 0 and farther = 1 possibly. (behind the screen = 0 to -1?) [QUOTE=Gabe Newell;35473990]SFML: How do you use sf::rect.(bottom, left, top, right)? I encountered it in a tutorial, and I was thinking of making my own buttons to use it for, but there's only one coordinate to put in.[/QUOTE] What version of SFML are you using? The latest uses x/y/w/h in its constructor, which sets the left, top, width and height values respectively.
[QUOTE=NovembrDobby;35474211]I think the Z value is something to do with the 3D points distance away from you, closer = 0 and farther = 1 possibly. (behind the screen = 0 to -1?) What version of SFML are you using? The latest uses x/y/w/h in its constructor, which sets the left, top, width and height values respectively.[/QUOTE] 1.6
Im trying to read an image and create a heiht map from it but for some reason it wont do anything. I create and pass the image to the shader as so: [cpp] texture = SOIL_load_OGL_texture ( "img.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glUniform1i(textureID, 0); [/cpp] And these are my shaders: [cpp] #version 120 uniform mat4 MVP; attribute vec4 Position; varying vec3 color; uniform sampler2D myTexture; void main(){ color = vec3(1,0,1); vec3 py = texture2D( myTexture, vec2(Position.x, Position.z) ).rgb; Position.y += ( ( ( py.x + py.y + py.z ) / 3.0f ) * 10.0f ) / 255.0f; ///// if this line is commented then the flat plane displays, if it isnt commented I cant see anything gl_Position = MVP * Position; } #version 120 varying vec3 color; void main(){ gl_FragColor = vec4(color.x,color.y,color.z,1); } [/cpp]
I'm trying to capture mouse input using the Windows API (no SFML, SDL, etc.), and I'm capturing it using Raw Input Devices. Every time I receive WM_INPUT (mouse-movement), I get the delta x/y and I store that in a variable. This works fine, as long as the mouse is moving. However, when the mouse is not moving, the WM_INPUT messages does not get sent to my game, so the stored delta does not change. This created the problem of the mouse 'drifting' when they stop moving - The game will keep reading the last WM_INPUT's delta, even though the new delta is 0,0. I tried to fix this by zeroing out the delta at the end of each game frame (Windows messages are read before each frame, and then logic (which uses the delta) is done during the frame, so resetting the delta to zero at the end should have fixed it. However, this appears to make me lose lots of frames of delta, making all mouse movement skippy. I think it's losing the input data between frames, because if I set a printf on WM_INPUT receiving and a printf when stored x/y delta are not equal to zero, I'll receive lots of detected deltas, but fewer 'stored'. [url=http://img846.imageshack.us/img846/2103/ss20120407185509.png]This shows the situation pretty well.[/url] Does anyone have a better solution for this? [b]Edit:[/b] Code for reading mouse input (inside WndProc) [cpp] //MOUSE - MOVEMENT case WM_INPUT: UINT dwSize = 40; static BYTE lpb[40]; GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)); RAWINPUT *pRaw = (RAWINPUT*)lpb; if(pRaw->header.dwType == RIM_TYPEMOUSE) { int xPosRelative = pRaw->data.mouse.lLastX; int yPosRelative = pRaw->data.mouse.lLastY; g_engineInput.SetMouseDelta(xPosRelative, yPosRelative); } return 0; [/cpp]
It may be better to react to input when it happens rather than having it set something that is always acted on.
[QUOTE=Philly c;35476493]It may be better to react to input when it happens rather than having it set something that is always acted on.[/QUOTE] That would be difficult and interrupt the flow in very odd ways - You'd have all sorts of mouse-like calculations multiple times before a frame and then it'd jump back to the rest of input, and then it'd run the other game logic. Plus it doesn't fit too well into my 'pack values into a command that is then propagated throughout entity logic' [editline]7th April 2012[/editline] At the suggestion of someone from the FP programmers chat, I tried grabbing the mouse position from the window (using the code at the bottom), and manually calculating a delta by taking the position at the start and end of each frame and applying that. This has the same problem as before of being very skippy - I think it's something with how I'm getting the mouse position, because the game updates 60 times a second, but I get messages maybe... 1/6th of the time. (They only print if mouse delta != 0) - I was taking my mouse in circles, there was sure as hell delta between each frame. [cpp] glm::vec2 CVideo::GetMousePosition() { //Get mouse position POINT mousePos; GetCursorPos(&mousePos); ScreenToClient(m_hWindowHandle, &mousePos); glm::vec2 mPos = glm::vec2(mousePos.x, mousePos.y); return mPos; } [/cpp]
I'm trying to export a game to a executable .jar file with Eclipse, and yet for some reason it keeps bugging out on me, the jar file won't execute, or it won't run without the JDK. Can someone give me a reason and detailed link to a description on how to export the damned projects to something runable?
[QUOTE=Larikang;35472202]I'm trying to program some basic swarm AI into my game, so each entity needs to be aware of its nearby entities. The only way I can think of doing this so far is by looping through all the entities and calculating the distances between them, but that's O(N^2) and I'd have to do it potentially every frame (if the entities don't all run their AI at the same time). Is there a more efficient algorithm or storage method for the entities that will speed up the process? If it matters, I'm using C++/SFML. Each entity is an object with a sf::RectangleShape member.[/QUOTE] You could try implementing [URL="http://conkerjo.wordpress.com/2009/06/13/spatial-hashing-implementation-for-fast-2d-collisions/"]spatial hashing[/URL] or a [URL="http://en.wikipedia.org/wiki/Quadtree"]quadtree[/URL].
Im getting a stupid error: Too many vertex shader texture samplers with this shader: [cpp] /////frag #version 120 varying vec3 color; void main(){ gl_FragColor = vec4(1,0,0,1);//vec4(color.x,color.y,color.z,1); } /////vertex #version 120 uniform mat4 MVP; attribute vec4 Position; varying vec3 color; uniform sampler2D myTexture; void main(){ color = texture2D( myTexture, vec2(Position.x, Position.z) ).rgb; float height = ((( color.x + color.y + color.z ) / 3.0f ) * 10.0f ) / 255.0f; vec4 pos = vec4(Position.x, height, Position.z, Position.w); gl_Position = MVP * pos; } [/cpp]
[QUOTE=Hypershadsy;35471916]Perhaps I'm over-thinking this, but I recall an algorithm that takes a 2D array (of pixels, in your case) and splits them up into the minimal amount of squares. I don't remember what it's called, though. [img_thumb]http://dl.dropbox.com/u/21571661/Pictures/boxes.png[/img_thumb] You could generate these on startup and then check each rectangle's intersection with the screen on Update, and if one hits, draw the whole sprite. But then again, you DID say "rough estimate".[/QUOTE] Erm, I don't know what you mean, I know what I need to do now I think. Just get the AABB of the sprite in screenspace and check if it intersects the rectangle with top, left, width, height of (0,0,ScreenWidth, ScreenHeight) Also anyone know if there's a shorter way of writing this? [cpp] BasePhysics* plan = dynamic_cast<BasePhysics*>(CreateEntity("ent_test")); [/cpp] CreateEntity("classname") returns a pointer to a a BaseObject*, however a lot of the time I want to call functions that are only available in BasePhysics*, for example BaseObject does not have an option for SetVelocity() or SetMass(). This is a cast I keep having to do so having a simple way of writing it out would be really appreciated. Maybe some kind of macro would work?
[QUOTE=conman420;35480953]Erm, I don't know what you mean, I know what I need to do now I think. Just get the AABB of the sprite in screenspace and check if it intersects the rectangle with top, left, width, height of (0,0,ScreenWidth, ScreenHeight) Also anyone know if there's a shorter way of writing this? BasePhysics* plan = dynamic_cast<BasePhysics*>(CreateEntity("ent_test")); CreateEntity("classname") returns a pointer to a a BaseObject*, however a lot of the time I want to call functions that are only available in BasePhysics*, for example BaseObject does not have an option for SetVelocity() or SetMass(). This is a cast I keep having to do so having a simple way of writing it out would be really appreciated. Maybe some kind of macro would work?[/QUOTE] You could use a template if you have other types too, something like: [code] template <typename T> T* CreateEntity(const std::string& name) { BaseObject* b = new BaseObject(); return dynamic_cast<T*>(b); } ... BasePhysics* plan = CreateEntity<BasePhysics>("ent_test"); [/code] or if you have objects already and just want an single easier cast: [code] BasePhysics* asPhysics(BaseObject* obj) { return dynamic_cast<BasePhysics*>(obj); } ... BasePhysics* phys = asPhysics(a_base_object); [/code] although you should think about structuring your classes so you don't need to do these kind of workarounds.
[QUOTE=Richy19;35480529]Im getting a stupid error: Too many vertex shader texture samplers with this shader: [cpp] /////frag #version 120 varying vec3 color; void main(){ gl_FragColor = vec4(1,0,0,1);//vec4(color.x,color.y,color.z,1); } /////vertex #version 120 uniform mat4 MVP; attribute vec4 Position; varying vec3 color; uniform sampler2D myTexture; void main(){ color = texture2D( myTexture, vec2(Position.x, Position.z) ).rgb; float height = ((( color.x + color.y + color.z ) / 3.0f ) * 10.0f ) / 255.0f; vec4 pos = vec4(Position.x, height, Position.z, Position.w); gl_Position = MVP * pos; } [/cpp][/QUOTE] Mentioned this in waywo, but I figure I'll post it here, too. This varies by hardware. Check GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS.
[QUOTE=Gabe Newell;35473990]SFML: How do you use sf::rect.(bottom, left, top, right)? I encountered it in a tutorial, and I was thinking of making my own buttons to use it for, but there's only one coordinate to put in.[/QUOTE]
[CODE] for(int x = 0; x < Width; x++) { for(int y = 0; y < Height; y++) { int i = (x * Width + y); std::cout << i <<" Hello" << std::endl; col = displayMap.find(i)->second; image.SetPixel(x,y,col); std::cout << i <<"Hello" << std::endl; } }[/CODE] That was all fine until I make the width bigger than the height, for example 32 and 24 respectively, at which point a get an assert with "map/set iterator not dereferencable". Not sure what the problem is. Also with 32 and 24, i will go from 759 to 768.
[QUOTE=Gabe Newell;35483565][/QUOTE] Like this: [cpp] sf::Rect<float> a = sf::Rect<float>(5,5, 10, 10); [/cpp] It is a template so you can have any numerical type in between the angular brackets. Also its (left,top, width, height) for the argument order. [QUOTE=NovembrDobby;35481222] although you should think about structuring your classes so you don't need to do these kind of workarounds.[/QUOTE] Judging by this I would say the way I have my classes set out is not ideal, I think what you say is best, I will move all the physics related functions to the actual physics object class and just throw in GetPhysObj() to the base obejct.
[QUOTE=conman420;35483954]Like this: [cpp] sf::Rect<float> a = sf::Rect<float>(5,5, 10, 10); [/cpp] It is a template so you can have any numerical type in between the angular brackets. Also its (left,top, width, height) for the argument order. [/QUOTE] I don't understand what the coordinates are doing.
[QUOTE=Gabe Newell;35484450]I don't understand what the coordinates are doing.[/QUOTE] Top and Left are for defining the position of the rectangle (where the top left hand corner will be) Width and Height are for defining the dimensions. If you were to do Rect(0,0,ScreenWidth, ScreenHeight) you would be defining a rectangle where the top left hand corner is at the top left hand corner of the render window and extents all the way to the bottom right hand corner of the renderwindow. If you want to make a rectangle where it is centred at a particular position you would do this: [cpp] int width = 100, height = 100; int x_pos = 40, y_pos = 80; sf::IntRect box = sf::IntRect(x - width / 2, y - height / 2, width, height) [/cpp]
I don't understand. How can a coordinate be one number?
[QUOTE=Gabe Newell;35485382]I don't understand. How can a coordinate be one number?[/QUOTE] There is 4 arguments: position on the x axis, position on the y axis, the width , and the height of the rectangle.
[QUOTE=Gabe Newell;35485382]I don't understand. How can a coordinate be one number?[/QUOTE] The single argument you're seeing is the type for the template sf::Rect, you should use sf::IntRect or sf::FloatRect unless you want one with values of a weird type. [editline]8th April 2012[/editline] [img]http://i.imgur.com/R6wNb.png[/img] [editline]8th April 2012[/editline] so do: sf::IntRect rectangle(left, top, width, height);
When an OpenGL context gets deleted, do all the buffers/textures/shaders/etc. created with that context also get deleted? [editline]8th April 2012[/editline] Never mind, after enough searching I got the answer I wanted: [url]http://www.opengl.org/wiki/Common_Mistakes#The_Object_Oriented_Language_Problem[/url]
Sorry, you need to Log In to post a reply to this thread.