HyperHacker

Members
  • Content count

    62
  • Joined

  • Last visited

Community Reputation

136 Neutral

About HyperHacker

  • Rank
    Member
  1. I've been working on a 2D game engine which renders asynchronously from the game logic - that is, the logic runs in one thread, and the rendering core runs in another. The logic is all done in Lua, which is not thread-safe. Lua provides a hook that allows a function to be called once every so-many instructions, which I've used to implement a faux "interrupt handler". The interrupt routine makes a list of references to all objects that are currently visible, and sends them a few at a time to the rendering thread (into a queue which is kept small) until the list is depleted, then refills it. This is working pretty well, until I want to animate an object. Now a problem arises. My animations are terribly choppy. The problem is, the rendering thread is just going as fast as it can, while the game logic thread has a small delay in its main loop to keep things going at a reasonable speed. So the two are rarely if ever in sync. If I update an object's animation frame counter in the game logic, there's no telling how many times each frame gets rendered. It depends how busy the rendering thread is at any given time. Frame 1 might get drawn 3 times, and frame 2 only once. This makes for very choppy animation. If I update the animation frame counter in the interrupt routine, the speed of the animation will depend on how busy the logic thread is, since there's no guarantees as to how often that interrupt actually fires. (Once every N instructions, but who knows how long that takes?) So my animations would be much faster on some machines than others, and vary in speed during play. If I wanted to create another thread solely to update animation frame counters, I'd need to restructure and store the frame counters outside of the Lua state, since it's not safe to modify a running Lua state from another thread. So I'd like to avoid this if possible. I wonder if someone can suggest a method to run animations that will play at the same speed all the time, while using an asynchronous rendering thread?
  2. This seems like a pretty basic thing but I've been looking everywhere and can't seem to find any explanation, save for a few function calls I don't seem to have. I want to display an 8-bit (or less) paletted image and animate its palette. I'm making a 2D game engine in Super NES style. I want to use palettes for animation and because I'd like to try to port to some low-end systems such as the Nintendo DS. The colour index functions look like what I want but I can't find any way to define the table of colours. glColorTable, glColorPointer, glIndexPointer are all doing nothing. All I get is a completely black texture. Some pages suggested using glColorTableEXT but that doesn't seem to be defined on my system. I keep finding pages that say things like palettes are no longer supported by modern drivers (which seems ridiculous to me given how useful they are) and shaders should be used instead, or that GL never supported palettes natively and some extension has to be used, but that leaves me to wonder what GL_COLOR_INDEX and such are for. Have modern systems really just dropped palette support entirely? Am I using the wrong functions? I don't get any errors returned, but no colours either.
  3. Lua Callbacks in C

    Thanks, that looks like it'll do.
  4. Lua Callbacks in C

    I'm writing a program that uses Lua, and I've hit a snag. I want to pass a Lua function to a C function as a callback. Like: someCFunction(function(foo) print(foo) end) Then at some point the script calls another C function, which calls the callback passed above. However I don't see a way to retrieve functions passed as parameters in C. I can call it when it's still on the stack, but I need to retrieve it and store it to call later. Is this possible?
  5. Just some things that bugged me a bit: 1) The Submit button to submit a post requires javascript. Why in the world? 2) Some tags use HTML, but others use BBCode. If I want a link and write [url=http://www.foo.bar]this[/url], it doesn't work; I have to use HTML links. Yet if I want to post some code and write <code>this</code>, it doesn't work; I have to use BBCode. Consistency is a good thing.
  6. OpenGL 3D cursor movement

    Well I figured out why the cursor wasn't moving with the camera. It actually was moving in the opposite direction (e.g. if the camera is at (0, 0, -5) the cursor would be at (0, 0, 5)), and the perspective made it look like it hadn't moved at all. However, moving vertices with the D-pad still doesn't work. It works fine if the camera is not rotated. If I look straight down the Y axis at them and move them, they still fly off in random directions. So, the replacement MoveFromPoint() didn't really fix anything, just caused a lot of headache. [edit] It happens with Y axis rotation as well, which is easier to see. Video demonstration. [edit 2] HA. It's a damn Lua bug. Fails:DX, DY, DZ = MoveFromPoint(0, 0, 0, -RX, -RY, DX, DY, DZ) X, Y, Z = X + DX, Y + DY, Z + DZ Vertex_SetPos(v, X, Y, Z)Works:local RDX, RDY, RDZ RDX, RDY, RDZ = MoveFromPoint(0, 0, 0, -RX, -RY, DX, DY, DZ) X, Y, Z = X + RDX, Y + RDY, Z + RDZ Vertex_SetPos(v, X, Y, Z)Apparently passing a variable as a parameter and also assigning a return value to it doesn't work so well. My zeros were randomly becoming ones or 0.126somethings on return. Figures. -_- It's nearly working now. I also found I needed to use the inverse of the camera rotation (i.e. -RX, -RY), else my controls would get all messed up. However, there's still a control issue when rotating on multiple axes. It works well if rotated on a single axis, or not at all: Up: Move away from camera Down: Move toward camera Left: Move left Right: Move right However, when rotated 90 degrees on both X and Y, there's a bit of a consistency problem: Up: Move up (toward top of screen) Down: Move down (toward bottom of screen) Left: Move away from camera Right: Move toward camera It's even worse at 45 degrees: Up: Move toward upper right corner of screen Down: Move toward lower left corner of screen Left: Same as up Right: Same as down O.o [Edited by - HyperHacker on July 25, 2009 11:16:43 PM]
  7. This isn't really game-related, but it's certainly AI-related. There are a lot of "learning" IRC bots that don't really "learn" anything, so much as just build a big database of responses to phrases. It's more just language analysis; say something similar to what someone else said before, and it'll repeat what someone replied to it. Are there any that really (at least try to) learn and simulate an actual brain? I realize brains are no simple matter and there are pretty severe limits to what computers can do in that regard, but I'd be interested to see how well one could actually perform in the right circumstances. Needs to be open-source so I can tinker with it as well. :)
  8. Timestep issues

    Also make sure your compiler/interpreter obeys the order of operations correctly. It's surprising how many don't.Quote:Original post by wraithseekerset .x = .x + a.x * TIMEThat should be read as ".x = .x + (a.x * TIME)" but some might read it as ".x = (.x + a.x) * TIME". I doubt that's really the problem, but it's worth checking.
  9. I had a similar idea, involving an RC car and a webcam... that probably says enough actually. :P
  10. OpenGL 3D cursor movement

    I'm writing a map editor for a simple, old, closed-source 3D game. This game engine has no concept of objects - the maps are only a lot of display lists, textures, and vertices, with collision meshes generated from the display lists at runtime. While my program is capable of grouping vertices and manipulating them as a whole, it ultimately needs to know the world coordinates of each vertex to export for this engine. I'm using a Wii remote to move the cursor, which is a floating cube. Whenever a vertex is inside the cube it can be dragged around or selected. Dragging also moves all selected vertices; additionally, the D-pad can be used to move them one unit at a time. I also hope to implement rotating all selected vertices around the camera's Z axis. Currently the camera is not able to rotate on the Z axis, because last time I tried to do that it nearly drove me batty. I'd love to get that working though. The actual Wiimote and cursor logic is done in Lua, using LuaGL. (The interface itself, if it matters, is GTK+ with GtkGlExt.) A function in the script is called periodically with a pointer to the window, which contains the cursor (and potentially multiple cursors in the future). It reads the Wiimote's IR/motion sensors to see where it's pointing (which gives you a rough distance-from-screen as well) and uses that to update the cursor position. Originally, I was using this code to do the transformations necessary for moving the camera, cursor, and selected vertices. It worked fine for the first two, but if I pointed my camera straight down the Y axis and moved some vertices they'd all just fly off in various directions.-- Transforms coordinates relative to a point to world coordinates. -- Inputs: -- -FromX, FromY, FromZ: Point which coordinates are relative to. -- -FromRotX, FromRotY: Rotation of this point. -- -MoveX, MoveY, MoveZ: Distance from point. -- Returns: X, Y and Z world coords. -- Notes: -- If distance is not important you can use 0,0,0 for FromX,FromY,FromZ. This -- allows you to move something relative to its current position while -- accounting for camera rotation, e.g: -- DX, DY, DZ = MoveFromPoint(0, 0, 0, RotX, RotY, DX, DY, DZ) function MoveFromPoint(FromX, FromY, FromZ, FromRotX, FromRotY, MoveX, MoveY, MoveZ) --Reset matrices gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() gl.MatrixMode(gl.MODELVIEW) gl.PushMatrix() gl.LoadIdentity() --Rotate gl.Rotate(FromRotX, 1.0, 0.0, 0.0) gl.Rotate(FromRotY, 0.0, 1.0, 0.0) --Get resulting modelview Matrix = gl.GetArray(gl.MODELVIEW_MATRIX) --Restore matrices gl.PopMatrix() gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) --[[How the 1-based 1-dimensional indices of Matrix map to a 4x4 matrix: 0__1__2__3 0|1 2 3 4 1|5 6 7 8 2|9 10 11 12 3|13 14 15 16 ]] --Move local X, Y, Z X = -FromX + (MoveX * Matrix[1]) + (MoveY * Matrix[2]) + (MoveZ * Matrix[3]) Y = -FromY + (MoveX * Matrix[5]) + (MoveY * Matrix[6]) + (MoveZ * Matrix[7]) Z = -FromZ + (MoveX * Matrix[9]) + (MoveY * Matrix[10]) + (MoveZ * Matrix[11]) return X, Y, Z end Someone else suggested this, which looks right to me:function MoveFromPoint(FromX, FromY, FromZ, FromRotX, FromRotY, MoveX, MoveY, MoveZ) --Assume we're in MODELVIEW matrix mode gl.PushMatrix() gl.LoadIdentity() -- Starting point gl.Translate(FromX, FromY, FromZ) -- Apply rotate gl.Rotate(FromRotX, 1.0, 0.0, 0.0) gl.Rotate(FromRotY, 0.0, 1.0, 0.0) -- Apply move gl.Translate(MoveX, MoveY, MoveZ) --Get resulting modelview Matrix = gl.GetArray(gl.MODELVIEW_MATRIX) --Restore matrix gl.PopMatrix() -- The translated point is in the last row of the matrix return Matrix[12], Matrix[13], Matrix[14] endHowever, this isn't working properly either - the cursor is not moving with the camera at all; always moving relative to the origin with no rotation. I know very little about 3D/matrix math but it certainly looks like it should work; I can see it translate to the starting point (in this case, the camera position), rotate, and then move the specified distance, which in my mental visualization should do the job exactly. It seems only the last gl.Translate() is actually having any effect. I have verified that the inputs are correct.
  11. Quote:Original post by pekNow that I am explaining the problem I start thinking of how to solve this.One of the best ways to solve a problem is to ask for help - not necessarily because you'll get it, but because just explaining it will make you realize the solution. :D
  12. OpenGL Mirroring a texture

    Thanks. I looked at a few OpenGL references and didn't see any mention of that.
  13. Is there any way to mirror a texture across a polygon in OpenGL? Like if I have a texture which is just the left half of a tree, I want to apply this texture to a single quad mirrored to draw an entire tree, drawing the texture on the left and a mirror image of it on the right. I can't just use two quads because I'm just rendering pre-defined meshes and textures which do this.
  14. Whenever I try to apply translucency or transparency to an OpenGL window, Windows crashes. I think it worked once, but every other time I'd just get a BSOD.
  15. Alright, well I'm not quite sure how to handle that... When I fetch the modelview for this purpose it's just glLoadIdentity(), a few glRotatef()s and then glGetDoublev() to get the matrix. I'm sure there's probably some way to just make up a matrix rather than reading it from GL but I'm not sure how. Off topic, how do you draw spheres and other round things? Just fake it with a lot of triangles? [edit] May as well include the actual code. /* Retrieves the modelview matrix for the object given its rotation. */ void Object3D::UpdateModelView() { //While we're here, clamp the rotation. if(this-&gt;Rotation.X &gt; 360.0) this-&gt;Rotation.X = fmod(this-&gt;Rotation.X, 360.0); else if(this-&gt;Rotation.X &lt; 0.0) this-&gt;Rotation.X = 360.0 + fmod(this-&gt;Rotation.X, 360.0); //Add because it's negative if(this-&gt;Rotation.Y &gt; 360.0) this-&gt;Rotation.Y = fmod(this-&gt;Rotation.Y, 360.0); else if(this-&gt;Rotation.Y &lt; 0.0) this-&gt;Rotation.Y = 360.0 + fmod(this-&gt;Rotation.Y, 360.0); if(this-&gt;Rotation.Z &gt; 360.0) this-&gt;Rotation.Z = fmod(this-&gt;Rotation.Z, 360.0); else if(this-&gt;Rotation.Z &lt; 0.0) this-&gt;Rotation.Z = 360.0 + fmod(this-&gt;Rotation.Z, 360.0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glRotatef(-this-&gt;Rotation.X, 1.0, 0.0, 0.0); glRotatef(-this-&gt;Rotation.Y, 0.0, 1.0, 0.0); glRotatef(-this-&gt;Rotation.Z, 0.0, 0.0, 1.0); glGetDoublev(GL_MODELVIEW_MATRIX, this-&gt;Modelview[0]); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }