• What do you need help with? Version 5
    5,752 replies, posted
This might help you: [url]http://devmag.org.za/2009/04/25/perlin-noise/[/url]
[QUOTE=trotskygrad;35245689]Need a bit of help coding a java GUI I want to make a button that when clicked, a menu shows up to change the color of that button.[/QUOTE] Do something like: [cpp] public class myClass implements ActionListener { // stuff here public void actionPerformed(ActionEvent e) { // ActionListener if (e.getSource() == button) { button.setBackground(Color.white); } } } [/cpp] You have to add an ActionListener to the button in question too. There are some good tutorials around. I'm not sure about the menu though. Do you want a context menu? [editline]22nd March 2012[/editline] [url=http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html]This might help.[/url]
So, hit another problem I'm having in lua. How do I check to see if a variable has changed in a table? Here is all my code so far. mouse detection works, however I don't know how I would check to see if a certain button has been pressed and how to do something after that specific button has been clicked [CODE]-- Initialize function love.load() menuFont = love.graphics.newFont("fnt/font1.ttf", 15) titleFont = love.graphics.newFont("fnt/font1.ttf", 46) -- Create a table to hold images in img = {} -- Create the images inside the table img.startbtn = love.graphics.newImage('img/startbtn.png') img.controlsbtn = love.graphics.newImage('img/controlsbtn.png') -- Create a table to hold buttons in btn = {} -- Create the buttons inside the table btn.start = { img = img.startbtn, x = 350, y = 400, w = img.startbtn:getWidth(), h = img.startbtn:getHeight(), clicked = false, } btn.controls = { img = img.controlsbtn, x = 350, y = 500, w = img.controlsbtn:getWidth(), h = img.controlsbtn:getHeight(), clicked = false, } end function love.draw() -- Format the title then print love.graphics.setColor(255,255,255) love.graphics.setFont(titleFont) love.graphics.print("LUAInvaders", 150, 100) love.graphics.setFont(menuFont) -- Draw the buttons onto the screen for k,v in pairs(btn) do love.graphics.draw(v.img, v.x, v.y, 0, 1, 1, v.w/2, v.h/2) love.graphics.print(tostring(v.clicked), v.x, v.y) end end function love.update() -- If the start button is clicked, go to game.lua if btn.startbtn.clicked = true then love.filesystem.load("game.lua")() love.load() end end function love.mousepressed(x, y, click) -- Check if LMB is pressed if click == 'l' then -- Check if LMB is pressed over a button for k,v in pairs(btn) do if x > v.x - v.w/2 and x < v.x + v.w/2 and y > v.y - v.w/2 and y < v.y + v.h/2 then -- alternate the clicked variable of the button v.clicked = not v.clicked end end end end[/CODE] The love.update function is where I have placed an If to check the variable, it doesn't work, however it shows what I'd like it to do.
[QUOTE=Plastical;35242003]You want to use the value over 100, not in percentage. montlyInterestRate (why isn't this called yearly investment rate if you're using an annual input) would be divided by 100. Your investment formula was slightly off. [/QUOTE] Hm. So I did that and simplified it, but it returns a [I]slightly [/I]inaccurate number. [csharp]// Calculate double futureValue = amount * Math.pow(1 + (interest / 100), years); futureValue= (double)(Math.round(futureValue*100))/100; JOptionPane.showMessageDialog(null, "Future value is: " + futureValue);[/csharp] I think it may be because I used 'double' instead of 'int'. Also it returns the same value of 1066.06 (I tried your code as well, same thing) [quote]Future Value Calculator Enter the investment amount: 1000 Enter the annual interest rate as a percent (2.75): 3.25 Enter the number of years: 2 The future value is: 1066.06 (Instead of 1067.07)[/quote]
Are you sure the answer is supposed to be 1067.07, because even some online calculators give 1066.06 instead. I'm pretty sure the logic is right if you're wondering about that.
[QUOTE=Plastical;35252861]Are you sure the answer is supposed to be 1067.07, because even some online calculators give 1066.06 instead. I'm pretty sure the logic is right if you're wondering about that. Also, I don't see why you're type casting futureValue if it has already been declared as a double. You should take out (double).[/QUOTE] Hmmm. That's pretty weird. I'll ask the guy tomorrow. Alright, I'll get rid of that. Thanks.
[QUOTE=Sickle;35252951]Hmmm. That's pretty weird. I'll ask the guy tomorrow. Alright, I'll get rid of that. Thanks.[/QUOTE] I made a mistake, the double type cast needs to be there because Math.round() returns a value to the nearest whole number. My apologies.
[QUOTE=Plastical;35252973]I made a mistake, the double type cast needs to be there because Math.round() returns a value to the nearest whole number. My apologies.[/QUOTE] Fixed and ran smoothly.
[QUOTE=Mikeyspike;35249322]So, hit another problem I'm having in lua. How do I check to see if a variable has changed in a table? Here is all my code so far. mouse detection works, however I don't know how I would check to see if a certain button has been pressed and how to do something after that specific button has been clicked [CODE]-- Initialize function love.load() menuFont = love.graphics.newFont("fnt/font1.ttf", 15) titleFont = love.graphics.newFont("fnt/font1.ttf", 46) -- Create a table to hold images in img = {} -- Create the images inside the table img.startbtn = love.graphics.newImage('img/startbtn.png') img.controlsbtn = love.graphics.newImage('img/controlsbtn.png') -- Create a table to hold buttons in btn = {} -- Create the buttons inside the table btn.start = { img = img.startbtn, x = 350, y = 400, w = img.startbtn:getWidth(), h = img.startbtn:getHeight(), clicked = false, } btn.controls = { img = img.controlsbtn, x = 350, y = 500, w = img.controlsbtn:getWidth(), h = img.controlsbtn:getHeight(), clicked = false, } end function love.draw() -- Format the title then print love.graphics.setColor(255,255,255) love.graphics.setFont(titleFont) love.graphics.print("LUAInvaders", 150, 100) love.graphics.setFont(menuFont) -- Draw the buttons onto the screen for k,v in pairs(btn) do love.graphics.draw(v.img, v.x, v.y, 0, 1, 1, v.w/2, v.h/2) love.graphics.print(tostring(v.clicked), v.x, v.y) end end function love.update() -- If the start button is clicked, go to game.lua if btn.startbtn.clicked = true then love.filesystem.load("game.lua")() love.load() end end function love.mousepressed(x, y, click) -- Check if LMB is pressed if click == 'l' then -- Check if LMB is pressed over a button for k,v in pairs(btn) do if x > v.x - v.w/2 and x < v.x + v.w/2 and y > v.y - v.w/2 and y < v.y + v.h/2 then -- alternate the clicked variable of the button v.clicked = not v.clicked end end end end[/CODE] The love.update function is where I have placed an If to check the variable, it doesn't work, however it shows what I'd like it to do.[/QUOTE] if btn.startbtn.clicked == true then = sets a value == compares values
[QUOTE=Funley;35248146]How can i simply generate perlin noise in XNA? I have looked up some tutorials but each one would take a long long time to implement. I simply want to generate perlin noise, then edit it so it only has 2 colors. Its kinda hard to explain, but i think you'll understand. Im using it for 2D tilemap terrain generation by the way.[/QUOTE] [url]http://berfenfeldt.com/2011/generate-worms-style-terrain-perlin-noise-in-xna/[/url]
[QUOTE=Kopimi;35253267]if btn.startbtn.clicked == true then = sets a value == compares values[/QUOTE] Ahh, I see, Thankyou. Also realised I called the index with an incorrect name. Should of been btn.start not btn.startbtn. I'm an idiot :)
I'm compiling SDL 1.3/2.0 using my own build system. What libraries do I need to link against, for the latest SDL to function? I've been linking the following: [code]dl, GL, X11, pulse[/code] But I keep getting 'undefined reference to SDL_*' when linking SDL statically to a program of mine. [editline]23rd March 2012[/editline] If it's of any help, here's the premake4 file I've been using: [url]http://pastebin.sabayon.org/pastie/8764[/url]
[QUOTE=MrTilepy;35249232]Do something like: [cpp] public class myClass implements ActionListener { // stuff here public void actionPerformed(ActionEvent e) { // ActionListener if (e.getSource() == button) { button.setBackground(Color.white); } } } [/cpp] You have to add an ActionListener to the button in question too. There are some good tutorials around. I'm not sure about the menu though. Do you want a context menu? [editline]22nd March 2012[/editline] [url=http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html]This might help.[/url][/QUOTE] I finished that, haha, ended up using icons in the buttons through the JButton(Icon icon) contructor and the setIcon method for JButton. Was relatively easy... until the nullPointerExceptions came around. I'm done now, haha [editline]23rd March 2012[/editline] [QUOTE=Sickle;35250917]Hm. So I did that and simplified it, but it returns a [I]slightly [/I]inaccurate number. [csharp]// Calculate double futureValue = amount * Math.pow(1 + (interest / 100), years); futureValue= (double)(Math.round(futureValue*100))/100; JOptionPane.showMessageDialog(null, "Future value is: " + futureValue);[/csharp] I think it may be because I used 'double' instead of 'int'. Also it returns the same value of 1066.06 (I tried your code as well, same thing)[/QUOTE] using an integer would simply truncate the number, double should definitely be precise enough.
[QUOTE=ryandaniels;35246919]That error actually autocompletes (even the 0x000007b part) when I type it into google, I'd try that.[/QUOTE] Mostly suggests getting a new version of a Microsoft DLL, switching runtime libraries, etc. I restarted and the problem went away and everything was working great, and then it came back. I'm going to think it's Awsomium causing problems. I looked at the DLL's being loaded, and here's what it does: [code] ... 'luxeloperation_d.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file 'luxeloperation_d.exe': Loaded 'F:\Dropbox\LuxelOperation\build\bin\debug\Awesomium_d.dll', Cannot find or open the PDB file 'luxeloperation_d.exe': Unloaded 'F:\Dropbox\LuxelOperation\build\bin\debug\Awesomium_d.dll' The program '[4888] luxeloperation_d.exe: Native' has exited with code -1073741701 (0xc000007b). [/code] (Dropbox isn't actually running when I work on it, so I don't think it's an issue caused by Dropbox) When it does start successfully, the log looks like: [code] ... 'luxeloperation_d.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file 'luxeloperation_d.exe': Loaded 'F:\Dropbox\LuxelOperation\build\bin\debug\Awesomium_d.dll', Cannot find or open the PDB file 'luxeloperation_d.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file 'luxeloperation_d.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file 'luxeloperation_d.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file ... [/code] I'm wondering if it's something in Awesomium that is causing problems and taking down everything with it. I don't actually have Awesomium calls being made (undid them to test), it's just being linked. Going to totally unlink the DLL's from the project and see if that stops the crashing, at which point I can take it up with Awesomium's support forums.' [b]Edit:[/b] Unlinking the Awesomium library seems to have fixed it. I'm gonna go hit up their support forums.
Would anybody like to help me create a HUD for a Half-Life 2 mod?
[QUOTE=T3hGamerDK;35257583]I'm compiling SDL 1.3/2.0 using my own build system. What libraries do I need to link against, for the latest SDL to function? I've been linking the following: [code]dl, GL, X11, pulse[/code] But I keep getting 'undefined reference to SDL_*' when linking SDL statically to a program of mine. [editline]23rd March 2012[/editline] If it's of any help, here's the premake4 file I've been using: [url]http://pastebin.sabayon.org/pastie/8764[/url][/QUOTE] 'dl' is the dynamic loading library (dlfcn.h), you need -lsdl, I think.
[QUOTE=Eudoxia;35261768]'dl' is the dynamic loading library (dlfcn.h), you need -lsdl, I think.[/QUOTE] I'm building my library myself, and linking to it as well, as can be seen in the pastebin I posted.
There is a way to change the Console Font in c or c++? I want to use a font that will be in the same folder of the executable, not a common font. Also I dont want to use a windows function since im using ubuntu. Thanks in advance.
Hey guys, I have a problem with Haskell. I want to create a variable called squares4 that returns squares who's last digit is 4. ex: “take 5 squares4” should return [4,64,144,324,484]. I created this variable which returns n amount of squares in a infinite list using lazy evaluation: squares4 = [ x^2 | x <- [4 ..] ] I know I'll have to use mod 4, but I am at a lost on how to implement it.
[QUOTE=Mete;35263050]There is a way to change the Console Font in c or c++?[/QUOTE] No. Obviously. [editline]23rd March 2012[/editline] And if it's not obvious, it's because the I/O system hasn't got shit to do with the terminal font. (How do you think you could, for example, make a VT100 support this custom font of yours? Terminal emulators emulate actual physical serial terminals, hence the name.)
[QUOTE=newbz;35264237]Hey guys, I have a problem with Haskell. I want to create a variable called squares4 that returns squares who's last digit is 4. ex: &#8220;take 5 squares4&#8221; should return [4,64,144,324,484]. I created this variable which returns n amount of squares in a infinite list using lazy evaluation: squares4 = [ x^2 | x <- [4 ..] ] I know I'll have to use mod 4, but I am at a lost on how to implement it.[/QUOTE] Ok this now returns only squares divisible by 4, but I need it to only return ones with the last digit as 4. squares4 = filter p [ x^2 | x <- [1 ..] ] where p x = x `mod` 4 == 0 NVM I got it! squares4 = filter p [ x^2 | x <- [1 ..] ] where p x = x `mod` 10 == 4
-snipe- Figured it out, Origin was messing with me wasting hours of work.
I've got some problems understanding the Google Maps API.. Getting the images at the correct position works fine and stuff, but I still need to figure out how to define the zoom level. I've only got some coordinates and I need to place a map behind them, and I can't hardcode them. Can anybody help me with this?
I'm trying to get [CODE]public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); try { SharedPreferences sharedPrefs = PreferenceManager .getDefaultSharedPreferences(this); } catch (Exception e) { // Preferences Intent prefsIntent = new Intent(LiveStreamsActivity.this, Preferences.class); startActivity(prefsIntent); } finally { Intent loginIntent = new Intent(LiveStreamsActivity.this, LoginForm.class); startActivity(loginIntent); } }[/CODE] to display my preferences screen if it cant find the saved preferences but it keeps erroring out with a Null Pointer Exception on the try line. Any idea's what's wrong?
[QUOTE=Darkwater124;35265571]I've got some problems understanding the Google Maps API.. Getting the images at the correct position works fine and stuff, but I still need to figure out how to define the zoom level. I've only got some coordinates and I need to place a map behind them, and I can't hardcode them. Can anybody help me with this?[/QUOTE] You're much better off just using [url=http://www.openstreetmap.org/]OpenStreetMap[/url].
Anyone have experience with OpenGL 4.0? or non-deprecated, anyway. I know I can draw strips of triangles or sets of individual triangles or whatever by using glDrawArrays with various data, I've got that working. But now I want to draw GL_LINE_LOOPs using sets of four points - my vertex buffer objects are going to have more than 4 points in them, but it'll be a multiple of 4 so there'll always be exactly enough to make a full set. I thought glDrawElements or something might be the right task for this but I'm not sure now and the gl docs and opengl superbible aren't really much help. having said that, my real problem is i'd like to draw lots of rectangles on the screen.
This is really weird; I tried to compile my application (uses opencl and sdl), and I got conflicts with a Polygon template defined in "wingdi.h". Is there any way to fix this without having to stick my math classes in their own namespace? Why would it work yesterday, and not today? [editline]24th March 2012[/editline] Did some poking around in windows.h, and found I could define "NOGDI" to stop it from including that. For some reason, though, I just noticed that another new thing that's happening (with or without me defining NOGDI), is that I get a warning when I compile, and this warning refers to cl.h... I don't remember getting compiler warnings from library headers before, and definitely didn't happen with this project until now.
[QUOTE=mechanarchy;35272985]Anyone have experience with OpenGL 4.0? or non-deprecated, anyway. I know I can draw strips of triangles or sets of individual triangles or whatever by using glDrawArrays with various data, I've got that working. But now I want to draw GL_LINE_LOOPs using sets of four points - my vertex buffer objects are going to have more than 4 points in them, but it'll be a multiple of 4 so there'll always be exactly enough to make a full set. I thought glDrawElements or something might be the right task for this but I'm not sure now and the gl docs and opengl superbible aren't really much help. having said that, my real problem is i'd like to draw lots of rectangles on the screen.[/QUOTE] Either glDrawArrays or glDrawElements would work, it is just a matter of specifying the order in which the vertices are drawn. With glDrawArrays, each vertex is drawn in the order which it stored in the array, from 1-3, 3-6, etc. With glDrawElements, you specify that order in an index buffer object, which usually contains an array of unsigned ints specifying the order which the vertices are drawn.
-snip, fixed-
[QUOTE=mlbfan560;35274875]Either glDrawArrays or glDrawElements would work, it is just a matter of specifying the order in which the vertices are drawn. With glDrawArrays, each vertex is drawn in the order which it stored in the array, from 1-3, 3-6, etc. With glDrawElements, you specify that order in an index buffer object, which usually contains an array of unsigned ints specifying the order which the vertices are drawn.[/QUOTE] Oh, hang on. I just reread the spec for glDrawArrays. If I want to draw separate, non-connected rectangles from the same buffers I can just do [cpp] glBindVertexArray(handle); for(int i = 0; i < numRects; i++) { glDrawArrays(GL_LINE_LOOP, i*4, 4); } [/cpp] But i'm under the impression opengl hates you doing shit like that because there's usually functions that do the same thing and only need one call to opengl instead of many like i'm doing here
Sorry, you need to Log In to post a reply to this thread.