• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=vombatus;37368094]Don't know if it counts but it throws a StackOverflowException[/QUOTE] I dont suppose it says anything about where it originates?
[QUOTE=demoTron;37361851]The movement was grid-like(move by 60px), but now it's not since it's multiplied by the time. What am i missing to make it move like before but slower like there would be a delay between movements ?[/QUOTE] Like Larikang said, you need to move when a timer exceeds a certain value. For instance, only move when the timer exceeds 1 second (The snake would move once per second). You don't need multiple timers for this, here is some psuedo-code which may help. [cpp]void main() { sf::RenderWindow window(sf::VideoMode(800, 600), "Snake"); sf::Clock timer; while (window.isOpen()) { sf::Event ev; while (window.pollEvent(ev)) { // handle events } float dt = timer.restart().asSeconds(); Update(dt); // render } } float ctime = 0.f; void Update(float dt) { ctime += dt; if (ctime >= 1.f) { // move every 1 second ctime -= 1.f; MoveSnake(60); // move snake 60 pixels } MoveSomethingElse(100 * dt); // smooth movements should still be multiplied by dt } [/cpp]
Just need help with a quick question If a program is written correctly using HashSet, would it work correctly if I changed HashSet to TreeSet? And again, if program was written using TreeSets, could I change all TreeSets to HashSets and have it work? I know that TreeSets order in ascending order, but they also have to implement Comparable or something? So I'm not sure if it would work.
.
[QUOTE=Over-Run;37371876]Just need help with a quick question If a program is written correctly using HashSet, would it work correctly if I changed HashSet to TreeSet? And again, if program was written using TreeSets, could I change all TreeSets to HashSets and have it work? I know that TreeSets order in ascending order, but they also have to implement Comparable or something? So I'm not sure if it would work.[/QUOTE] Items being put into a TreeSet must implement Comparable, because the underlying implementation relies on comparing objects to each other to figure out where they should go. This is different from HashSets which use Object.hashCode() to slot the items into buckets. [URL=http://docs.oracle.com/javase/6/docs/api/java/util/TreeSet.html]TreeSet API Definition[/url]
Okay okay, so I've just started playing around with LÖVE (it's awesome!). This is also my first dabble into Lua (though I'm not new to programming). Now I've managed to get a single object springing around off of my cursor and I've done this by creating three tables, each containing the x and y components of the objects position, velocity and acceleration. I was wondering how to go about creating a class to take over these table's roles? I've created such a class before in Java, called Vector2D, which would contain an X and Y component as well as a bunch of useful vector arithmetic functions... But I'm not sure how to get the same kind of functionality in Lua/LÖVE. I do think its possible just to write these functions into some kind of 2d vector math .lua file and use them from that, but I just wanted to ask if its possible to do the above. Thanks!
[url]http://wiki.garrysmod.com/page/Lua/Tutorials/Tables_as_objects[/url]
[QUOTE=calzoneman;37381164]Items being put into a TreeSet must implement Comparable, because the underlying implementation relies on comparing objects to each other to figure out where they should go. This is different from HashSets which use Object.hashCode() to slot the items into buckets. [URL=http://docs.oracle.com/javase/6/docs/api/java/util/TreeSet.html]TreeSet API Definition[/url][/QUOTE] I know that it has to do that but is that only if it is a generic type? Because I made a program that let's you enter words into the console and it will tell you if you the word has occurred previously, it was made with a HashSet and I simply changed HashSet to Tree set and the program still worked so I didn't get any compiler errors so it's confusing me
[QUOTE=ECrownofFire;37384324][url]http://wiki.garrysmod.com/page/Lua/Tutorials/Tables_as_objects[/url][/QUOTE] Why on earth does that tutorial suggest the use table.Copy instead of metatables? table.Copy doesn't even exist in pure Lua. With metatables you can add support for arithmetic operators and such. [code]local vectormeta = {} vectormeta.__index = vectormeta vectormeta.__metatable = "Vector" function vectormeta:__add(v) if type(v) == "number" then return Vector(self.x + v, self.y + v, self.z + v) end if type(v) == "table" and getmetatable(v) == "Vector" then return Vector(self.x + v.x, self.y + v.y, self.z + v.z) end error("attempt to perform vector arithmetic on a " .. type(v) .. " value", 2) end function vectormeta:__unm() return Vector(-self.x, -self.y, -self.z) end function vectormeta:__sub(v) return self + (-v) end function vectormeta:Dot(v) if type(v) == "table" and getmetatable(v) == "Vector" then return self.x*v.x + self.y*v.y + self.z*v.z end error("attempt to perform vector dot product on a " .. type(v) .. " value", 2) end function vectormeta:__mul(v) if type(v) == "number" then return Vector(self.x * v, self.y * v, self.z * v) end if type(v) == "table" and getmetatable(v) == "Vector" then return self:Dot(v) end error("attempt to perform vector arithmetic on a " .. type(v) .. " value", 2) end function vectormeta:__tostring() return "Vector(" .. self.x .. ", " .. self.y .. ", " .. self.x .. ")" end function Vector(x, y, z) return setmetatable({x = x or 0, y = y or 0, z = z or 0}, vectormeta) end[/code]
[QUOTE=MakeR;37384801]Why on earth does that tutorial suggest the use table.Copy instead of metatables?[/QUOTE] Well, the author of it has himself confessed to making [URL="http://wiki.garrysmod.com/page/User:Toneo"]"terrible contributions".[/URL]
[QUOTE=ECrownofFire;37384324][url]http://wiki.garrysmod.com/page/Lua/Tutorials/Tables_as_objects[/url][/QUOTE] [img]http://puu.sh/YkPZ[/img] So much truth in that article.
I have recently been learning Lua and love2d and I have a question :D I am able to use tables to store information and such but I don't understand how to say.. make multiple enemies and why I would use a table to do that. I also don't know why something like this doesn't make multiple copies of the text and increase by 10 on Y each time. [code] stringTable = {"Cheese"} stringY = 0 for i,v in pairs(stringTable) do love.graphics.print(i..v, 0, stringY) stringY = stringY + 10 end[/code] Thanks for any help :)
You are iterating over a table with one value, therefore the loop will only run once.
So for it to work I would need to table.insert?
[QUOTE=Over-Run;37384676]I know that it has to do that but is that only if it is a generic type? Because I made a program that let's you enter words into the console and it will tell you if you the word has occurred previously, it was made with a HashSet and I simply changed HashSet to Tree set and the program still worked so I didn't get any compiler errors so it's confusing me[/QUOTE] The String type (along with most other built-in types) implements Comparable and overrides hashCode(), equals() and other such methods used by containers so that's why they work. In general, if you implement your own type you will need to override hashCode() for Hashtable-based containers and implement Comparable and override equals() and compareTo() for comparison-based containers.
[code]function love.load() enemyNumber = 0 enemies = {} end function love.draw() for i,v in ipairs(enemies) do love.graphics.rectangle("fill", enemy.x, enemy.y, 10, 10) end end function update(dt) x, y = love.mouse.getPosition() if love.keyboard.isDown(" ") then addEnemy() end end function addEnemy() enemyNumber = enemyNumber + 1 enemy.x = x enemy.y = y table.insert(enemy[i]{enemy.x, enemy.y}) end[/code] So I had a guess at it... can anyone help please :( I don't get any errors but it doesn't do anything.
[QUOTE=JakeAM;37392823][code]function love.load() enemyNumber = 0 enemies = {} end function love.draw() for i,v in ipairs(enemies) do love.graphics.rectangle("fill", enemy.x, enemy.y, 10, 10) end end function update(dt) x, y = love.mouse.getPosition() if love.keyboard.isDown(" ") then addEnemy() end end function addEnemy() enemyNumber = enemyNumber + 1 enemy.x = x enemy.y = y table.insert(enemy[i]{enemy.x, enemy.y}) end[/code] So I had a guess at it... can anyone help please :( I don't get any errors but it doesn't do anything.[/QUOTE] You shouldn't be guessing this kind of thing, you need to understand the syntax of Lua and how it works. There is quite a few things wrong with your code: [code]local enemies = {} -- The table should be declared local outside of any function scope function love.draw() for i, v in ipairs(enemies) do love.graphics.rectangle("fill", v.x, v.y, 10, 10) -- 'v' instead of 'enemy' (enemy variable doesn't exists) end end function update(dt) -- Are you callling this function fron anywhere or should this be love.update(dt)? local x, y = love.mouse.getPosition() -- These variables should be local to the update function if love.keyboard.isDown(" ") then addEnemy(x, y) -- Call this function with the x and y position of the enemy end end function addEnemy(x, y) local enemy = {} -- Create a new enemy table enemy.x = x enemy.y = y table.insert(enemies, enemy) -- Insert the enemy table into enemies end[/code]
I am trying to make a FPS camera but I simply cannot get lookat to work. Can someone spot any errors in this code? It should move the camera by the mouse positions but the movement is not right. [code]public void rotateXY(float x, float y) { //x %= 360.0f; Vector3f newLookat = new Vector3f(); if(y > 0 && y > 89.0f) { y = 89.0f; } else if(y < 0 && y < -89.0f) { y = -89.0f; } x = (float)Math.toRadians(x); y = (float)Math.toRadians(y); float radius = 1000.0f; newLookat.x = radius * (float)Math.sin(y) * (float)Math.cos(x); newLookat.y = radius * (float)Math.sin(y) * (float)Math.sin(x); newLookat.z = radius * (float)Math.cos(y); lookat = Vector3f.add(Vector3f.normalize(newLookat), position); }[/code] Basically I am trying to implement this [url]http://en.wikipedia.org/wiki/Spherical_coordinate_system#Coordinate_system_conversions[/url], that I think is used in FPS camera movement. EDIT: Okay I normalized new lookat and add the current position to it, I still got some issues and the movement are swapped again :v:
I am trying to conver this to csharp but it just moves in what ever direction it wants. [url]http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/[/url] [csharp] using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using OpenTK; using OpenTK.Graphics.OpenGL; using OpenTK.Input; using OpenTKGaem.GLUtilities; namespace OpenTKGaem { public class DirectionalCamera { public static DirectionalCamera dc = new DirectionalCamera (); Matrix4 View; Matrix4 Persp; Vector3d position; Vector3d target = new Vector3d (0.0); Vector3d up = new Vector3d (0.0, 1.0, 0.0); float horizontalAngle = (float)Math.PI; float verticalAngle = 0.0f; float initialFoV = OpenTK.MathHelper.PiOver4; float speed = 3.0f; float mouseSpeed = 0.005f; public DirectionalCamera () { } public void Init () { position = new Vector3d(251/2.0f ,10.0f, 251/2.0f); View = Matrix4.LookAt ((Vector3)position, (Vector3)target, (Vector3)up); Persp = Matrix4.CreatePerspectiveFieldOfView (initialFoV, (float)Settings.width / Settings.height, 0.1f, 100.0f); } public void Update (double dt) { Vector2 hSS = new Vector2 (Settings.width / 2, Settings.height / 2); Vector2 mouseP = new Vector2 (((int)Game.g.Mouse.X), ((int)Game.g.Mouse.Y)); Mouse.SetPosition (Game.g.X + hSS.X ,Game.g.Y + hSS.Y); horizontalAngle += mouseSpeed * (float)dt * (hSS.X - mouseP.X); verticalAngle += mouseSpeed * (float)dt * (hSS.Y - mouseP.Y); Vector3d direction = new Vector3d ( (float)(Math.Cos (verticalAngle) * Math.Sin (horizontalAngle)), (float)(Math.Sin (verticalAngle)), (float)(Math.Cos (verticalAngle) * Math.Cos (horizontalAngle)) ); Vector3d right = new Vector3d ( (float)(Math.Sin (horizontalAngle - OpenTK.MathHelper.PiOver2)), 0.0f, (float)(Math.Cos (horizontalAngle - OpenTK.MathHelper.PiOver2)) ); up = Vector3d.Cross (right, direction); Vector3d dts = new Vector3d (dt * speed); if (Keyboard.GetState ().IsKeyDown (Key.W)) { position.X += direction.X * dts.X; position.Y += direction.Y * dts.Y; position.Z += direction.Z * dts.Z; } if (Keyboard.GetState ().IsKeyDown (Key.S)) { position.X -= direction.X * dts.X; position.Y -= direction.Y * dts.Y; position.Z -= direction.Z * dts.Z; } if (Keyboard.GetState ().IsKeyDown (Key.D)) { position.X += right.X * dts.X; position.Y += right.Y * dts.Y; position.Z += right.Z * dts.Z; } if (Keyboard.GetState ().IsKeyDown (Key.A)) { position.X -= right.X * dts.X; position.Y -= right.Y * dts.Y; position.Z -= right.Z * dts.Z; } View = Matrix4.LookAt ((Vector3)position, (Vector3)target, (Vector3)up); } public void getMVP (ref Matrix4 MVP) { MVP = MVP * View * Persp; } public void getVP (out Matrix4 VP) { VP = View * Persp; } } } [/csharp] can someone help me out?
I've been working on getting font rendering working properly usng the FreeType library, but I've ran into some difficulties: [t]http://i.imgur.com/cHNWp.png[/t] what might cause this? Some of the glyphs obviously works correctly but others don't and I'm not quite sure where I'm doing it wrong. Heres the sourcecode of my Font class implementation: [URL]http://pastebin.com/Wkk8ZT6k[/URL] [editline]25th August 2012[/editline] Fixed it thanks to wonderful Naelstrof. I was generating 4x4 vertices for some reason... Maybe I should just sleep instead. [editline]25th August 2012[/editline] [QUOTE=Richy19;37404601]I am trying to conver this to csharp but it just moves in what ever direction it wants. [URL]http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/[/URL] code can someone help me out?[/QUOTE] Richy, you could add me on steam and I could help you out with your issues. It appears you're running into the exact same issues that I've already overcome, so maybe it would be good for both of us if we could talk over steam instead. As for your issue, I must admit that I can't quite help you with that. I'm not even sure how your code is supposed to turn the right way to be honest. It works fundamentally differently from my own.
Looks as though you're not using bitmap_left or bitmap_top which is required to properly offset the glyphs. You can use these as a reference: [url]http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01[/url] [url]http://www.blackpawn.com/texts/lightmaps/[/url] [url]https://github.com/naelstrof/Astrostruct/blob/master/src/NText.cpp[/url] [url]http://farmpolice.com/astrostruct/docs/group__TextSystem.html[/url] The last two are my implementation of text rendering, so you can ask me questions about how I did stuff.
[QUOTE=Capsup;37405736] Richy, you could add me on steam and I could help you out with your issues. It appears you're running into the exact same issues that I've already overcome, so maybe it would be good for both of us if we could talk over steam instead. As for your issue, I must admit that I can't quite help you with that. I'm not even sure how your code is supposed to turn the right way to be honest. It works fundamentally differently from my own.[/QUOTE] Im currently on linux(and wont have access to steam) for the next few weeks. But if you have any other IM PM me.
[QUOTE=Richy19;37406533]Im currently on linux(and wont have access to steam) for the next few weeks. But if you have any other IM PM me.[/QUOTE] Skype .. ? capsup1712 if that's the case. Other than that, I don't really have any others.
added [QUOTE=Capsup;37406552]Skype .. ? capsup1712 if that's the case. Other than that, I don't really have any others.[/QUOTE]
[QUOTE=Naelstrom;37405933]Looks as though you're not using bitmap_left or bitmap_top which is required to properly offset the glyphs.[/QUOTE] Mind expanding on that a little? I'm not sure if it's my vertices of what I'm doing wrong and where I need to add this offset. I took a look on your code but it appears that you're rendering it all to a single texture then rendering that?
[QUOTE=Richy19;37404601]I am trying to conver this to csharp but it just moves in what ever direction it wants.[/QUOTE] Thats almost what happens to me! How come that we both work on almost same thing? :v:
[QUOTE=Richy19;37406533]Im currently on linux(and wont have access to steam) for the next few weeks. But if you have any other IM PM me.[/QUOTE] I call Steam on Linux being released in the next few weeks just to spite you.
[QUOTE=Capsup;37406669]Mind expanding on that a little? I'm not sure if it's my vertices of what I'm doing wrong and where I need to add this offset. I took a look on your code but it appears that you're rendering it all to a single texture then rendering that?[/QUOTE] The first tutorial I pasted tells you the purpose of the offsets and how to apply them to your vertices positions. Basically the bitmap_left and bitmap_top are just the x and y offset of a specific glyph you're drawing. If you want to add me on steam I can set you off in the right direction. It took me about 5 tries to get a good text render-er going so you might have to start from scratch too if you want it to do well. [editline]25th August 2012[/editline] [QUOTE=Richy19;37406533]Im currently on linux(and wont have access to steam) for the next few weeks. But if you have any other IM PM me.[/QUOTE] Steam works fine for me on Wine, what's keeping you from using it?
[QUOTE=Jookia;37407499]I call Steam on Linux being released in the next few weeks just to spite you.[/QUOTE] It doesnt spite me :P I have made do without it for all summer I can make due without it for longer. Tho it will be quite useful :) [editline]25th August 2012[/editline] [QUOTE=Naelstrom;37407570]Steam works fine for me on Wine, what's keeping you from using it?[/QUOTE] using wine opens up to the possibility of viruses, also if i install wine i will end up instaling all sorts of windows programs and i dont want to clutter up my computer
Okay I tried something simpler. I do this in the input manager: [code]int centerX = Display.getWidth() / 2; int centerY = Display.getHeight() / 2; cameraComponent.setXRot(Mouse.getX() - centerX); cameraComponent.setYRot(Mouse.getY() - centerY); [/code] Then in the camera class: [code] public void setYRot(float val) { if(val > 89.0f) { val = 89.0f; } else if(val < -89.0f) { val = -89.0f; } yrot = val; yrot %= 360.0f; } public void setXRot(float val) { xrot = val; xrot %= 360.0f; } public float getXRot() { return xrot; } public float getYRot() { return yrot; }[/code] And then at least I rotate the world: [code]GL11.glLoadIdentity(); GL11.glRotatef(cameraComponent.getXRot(), 0.0f, 1.0f, 0.0f); GL11.glRotatef(cameraComponent.getYRot(), 1.0f, 0.0f, 0.0f);[/code] While this work, the rotation seem very odd, it is hard to describe but the yrotation depends on xrotation while I think that in a FPS game the different rotations occur independently.
Sorry, you need to Log In to post a reply to this thread.