• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=esalaka;26039174]No, exactly the other way around.[/QUOTE] [url]http://en.wikipedia.org/wiki/Endianness#Little-endian[/url] "The least significant byte (LSB) value, 0Dh, is at the lowest address."
How do I cap a value to make sure it doesn't go over 255 without using ifs or fors or whiles?
uint8
[QUOTE=yngndrw;26039821][url]http://en.wikipedia.org/wiki/Endianness#Little-endian[/url] "The least significant byte (LSB) value, 0Dh, is at the lowest address."[/QUOTE] Well, fuck. I still think that makes no sense at all. Why is it low-[B]endian[/B] if the least significant byte is at the [B]lowest[/B] address?
[QUOTE=esalaka;26041906]Well, fuck. I still think that makes no sense at all. Why is it low-[B]endian[/B] if the least significant byte is at the [B]lowest[/B] address?[/QUOTE] They just wanted to annoy you. It's like the right-handed coordinate system - Why would you use it when it's opposite from what the near / far clip planes use ? It really annoys me. :c (Right-handed coordinate system says that the Z axis increases as it comes out of the screen, however the far clip plane which goes into the screen always has a larger value than the near clip plane.)
[QUOTE=esalaka;26041906]Well, fuck. I still think that makes no sense at all. Why is it low-[B]endian[/B] if the least significant byte is at the [B]lowest[/B] address?[/QUOTE] If you think of address space as not bottom to top, but left to right, it makes sense the the end of a region is higher than the beginning of a region.
[b]EDIT:[/b] Problem magically solved itself.... I don't know how I need a bit of help here. I'm trying to take a class name (that I will later parse from a text file) and create a new instance of it. What I'm doing is this: [cpp]Class cls = Class.forName("ClassNameGoesHere"); Puzzle currentPuzzle = (Puzzle)cls.newInstance(); currentPuzzle.init();[/cpp] Puzzle is an interface, ClassNameGoesHere is the name of a class which implements Puzzle. Immediately after I type in the cls.newInstance(); line, it returns two errors, the first for Class.forName("ClassNameGoesHere"); with the exception being ClassNotFoundException, and the other being on cls.newInstance();, being IllegalAccessException. I know the first error is causing the second, but what's causing the first one? I already have an import statement at the top for the package the puzzle is supposed to be contained in, and when that didn't work, I just copied the class over to the same package and commented out the import statement, same issue. I spelled the class name right, and I even copy/pasted it over to be sure. There's also a warning over the first word, Class, saying "Class is a raw type. References to generic type Class<T> should be parameterized"
If it is C# then: [csharp] private void RegisterFunctions(Assembly program, string space) { foreach (Module item in program.GetModules()) { foreach (Type item2 in item.GetTypes()) { if (item2.Namespace == space && item2.GetInterface("CodeGame.FunctionTable") != null) { object instance = Activator.CreateInstance(item2); string table = (string)item2.GetMethod("GetName").Invoke(instance, null); foreach (MethodBase item3 in item2.GetMethods()) { if (item3.IsStatic == true) { } } } } } } [/csharp]
It's Java I believe. I have no experience of it, however I found this snip-it which may or may not help you: [url]http://radio-weblogs.com/0112098/stories/2003/02/12/classfornameIsEvil.html[/url]
It is Java, and I'll give yngndrw's link a try... [editline]13th November 2010[/editline] it's still returing a ClassNotFoundException and an InstantiationException :saddowns: [editline]13th November 2010[/editline] The only thing that's strange is that it seems to fair well until I write cls.newInstance(), then it returns 2 errors...
Hi there people! I'll add my problem the list (?) I am trying to make smooth movement. Basicly, there is a window, you click in the window, a grey square goes from its current position to where you clicked, smoothly and relativly slowly. I wrote some code that I think should work, and I really have no idea why its not working. Could someone help me? This is in java. [code] import java.applet.*; import java.awt.*; import java.awt.event.*; public class Test extends Applet implements MouseListener, MouseMotionListener { int width, height; int cx, cy, tx, ty; // the mouse coordinates boolean isButtonPressed = false; boolean isMoving = false; public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); cx = width/2; cy = height/2; addMouseListener( this ); addMouseMotionListener( this ); } public synchronized void MoveIt() throws InterruptedException{ if(isMoving != true){ isMoving = true; int i = 0; double interval = 0.1; while(cx!=tx&cy!=ty){ if(cx>tx){ System.out.println("cx>tx"); cx-=interval; } else if(cx<tx){ System.out.println("cx<tx"); cx+=interval; } else if(java.lang.Math.abs(cx-tx)<interval){ System.out.println("java.lang.Math.abs(cx-tx)<interval"); cx=tx; break; } if(cy>ty){ System.out.println("cy>ty"); cy-=interval; } else if(cy<ty){ System.out.println("cy<ty"); cy+=interval; } else if(java.lang.Math.abs(cy-ty)<interval){ System.out.println("java.lang.Math.abs(cy-ty)<interval"); cy=ty; break; } repaint(); System.out.println("Repainted. X:"+cx+" Y: "+cy); this.wait(50); } isMoving = false; } } public void mouseEntered( MouseEvent e ) { // called when the pointer enters the applet's rectangular area } public void mouseExited( MouseEvent e ) { // called when the pointer leaves the applet's rectangular area } public void mouseClicked( MouseEvent e ) { this.tx = e.getX(); this.ty = e.getY(); try { this.MoveIt(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public void mousePressed( MouseEvent e ) { // called after a button is pressed down } public void mouseReleased( MouseEvent e ) { // called after a button is released } public void mouseMoved( MouseEvent e ) { // called during motion when no buttons are down } public void mouseDragged( MouseEvent e ) { // called during motion with buttons down } public void paint( Graphics g ) { g.fillRect( cx-20, cy-20, 40, 40 ); } } [/code]
Try setting interval to an int of value 1, I don't know if it being a double bring any issues, but it's worth a try.
Okay... Ehm heres the updated code, for some reason it only opens a black applet window, it dosent even draw the rectangle.... [code] import java.applet.*; import java.awt.*; import java.awt.event.*; public class Test extends Applet implements MouseListener, MouseMotionListener { int width, height; int cx, cy, tx, ty; // the mouse coordinates boolean isButtonPressed = false; boolean isMoving = false; public void init() { width = 200; height = 200; setBackground( Color.black ); cx = width/2; cy = height/2; addMouseListener( this ); addMouseMotionListener( this ); } public synchronized void MoveIt() throws InterruptedException{ if(isMoving != true){ isMoving = true; int i = 0; int interval = 1; while(cx!=tx&cy!=ty){ if(cx>tx){ System.out.println("cx>tx"); cx-=interval; } else if(cx<tx){ System.out.println("cx<tx"); cx+=interval; } else if(java.lang.Math.abs(cx-tx)<interval){ System.out.println("java.lang.Math.abs(cx-tx)<interval"); cx=tx; break; } if(cy>ty){ System.out.println("cy>ty"); cy-=interval; } else if(cy<ty){ System.out.println("cy<ty"); cy+=interval; } else if(java.lang.Math.abs(cy-ty)<interval){ System.out.println("java.lang.Math.abs(cy-ty)<interval"); cy=ty; break; } repaint(); System.out.println("Repainted. X:"+cx+" Y: "+cy); this.wait(50); } isMoving = false; } } public void mouseEntered( MouseEvent e ) { // called when the pointer enters the applet's rectangular area } public void mouseExited( MouseEvent e ) { // called when the pointer leaves the applet's rectangular area } public void mouseClicked( MouseEvent e ) { this.tx = e.getX(); this.ty = e.getY(); try { this.MoveIt(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public void mousePressed( MouseEvent e ) { // called after a button is pressed down } public void mouseReleased( MouseEvent e ) { // called after a button is released } public void mouseMoved( MouseEvent e ) { // called during motion when no buttons are down } public void mouseDragged( MouseEvent e ) { // called during motion with buttons down } public void paint( Graphics g ) { g.fillRect( cx-20, cy-20, 40, 40 ); } } [/code]
oh yeah, and my updated code, which is still returning an error. I have 2 .java files in one package, CircuitPuzzle.java and TestGame.java. Both of them have a package line at the top referencing the same package, no errors with CircuitPuzzle, it's public, etc. Works fine if I make an instance of CircuitPuzzle. I've tried adding an import to CircuitPuzzle, doesn't work. I've tried writing out the full path to the class as the class name, still doesn't work. [code]public class TestGame { public static void main(String[] args) { String className = "CircuitPuzzle"; IPuzzle currentPuzzle = (IPuzzle)( [highlight]Class.forName(className).newInstance()[/highlight] ); currentPuzzle.init(); currentPuzzle.run(); System.out.println(currentPuzzle.end()); } }[/code] That's just this class, I have the imports and package line above it. I highlighted where eclipse gave me an error...
Okay, I fixed my problem. I had it drawing a black cube on a black background. Here is the updated code that works sort of correctly, but it dosent move smoothly, it jumps. Here: [code] import java.applet.*; import java.awt.*; import java.awt.event.*; public class Test extends Applet implements MouseListener, MouseMotionListener { int width, height; int cx, cy, tx, ty; // the mouse coordinates boolean isButtonPressed = false; boolean isMoving = false; public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); cx = 100; cy = 100; addMouseListener( this ); addMouseMotionListener( this ); } public synchronized void MoveIt() throws InterruptedException{ if(isMoving != true){ isMoving = true; int i = 0; double interval = 0.1; while(cx!=tx&cy!=ty){ if(cx>tx){ System.out.println("cx>tx"); cx-=interval; } else if(cx<tx){ System.out.println("cx<tx"); cx+=interval; } else if(java.lang.Math.abs(cx-tx)<interval){ System.out.println("java.lang.Math.abs(cx-tx)<interval"); cx=tx; break; } if(cy>ty){ System.out.println("cy>ty"); cy-=interval; } else if(cy<ty){ System.out.println("cy<ty"); cy+=interval; } else if(java.lang.Math.abs(cy-ty)<interval){ System.out.println("java.lang.Math.abs(cy-ty)<interval"); cy=ty; break; } repaint(); System.out.println("Repainted. X:"+cx+" Y: "+cy); this.wait(50); } isMoving = false; } } public void mouseEntered( MouseEvent e ) { // called when the pointer enters the applet's rectangular area } public void mouseExited( MouseEvent e ) { // called when the pointer leaves the applet's rectangular area } public void mouseClicked( MouseEvent e ) { this.tx = e.getX(); this.ty = e.getY(); try { this.MoveIt(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public void mousePressed( MouseEvent e ) { // called after a button is pressed down } public void mouseReleased( MouseEvent e ) { // called after a button is released } public void mouseMoved( MouseEvent e ) { // called during motion when no buttons are down } public void mouseDragged( MouseEvent e ) { // called during motion with buttons down } public void paint( Graphics g ) { g.setColor(Color.RED); g.fillRect( cx-20, cy-20, 40, 40 ); } } [/code]
-snip- nevermind
[QUOTE=esalaka;26041906]Why is it low-[B]endian[/B] if the least significant byte is at the [B]lowest[/B] address?[/QUOTE] I think the terms "little-endian" and "big-endian" are references to the [url=http://ukrainetoday.wordpress.com/2007/04/28/big-enders-and-little-enders-idelogical-difference/]little-enders and big-enders[/url] from Gulliver's Travels.
[QUOTE=bobthe2lol;26045685]Okay, I fixed my problem. I had it drawing a black cube on a black background. Here is the updated code that works sort of correctly, but it dosent move smoothly, it jumps.[/QUOTE] I'm not entirely sure what the issue is, but here are a few things I've noticed: [list=1][*]Your position coordinates are integers, but your interval is a double. I'd suggest either making the interval an integer or increasing the scale of the coordinate sysem. [*]You're missing an ampersand in the conditional statement for the while loop - it should be "cx!=tx&[b]&[/b]cy!=ty". [*]Your break statements will kill the loop as soon as either cx or cy is close enough, not both. Remove them and let the while's condition take care of stopping. [*]Do the check for the positions being close enough [i]before[/i] you add/subtract the interval value. [*]Assuming everything's working, then that's 0.1 px per 50 ms or 2 px/s, which seems a bit slow. An interval of 1 would get you 20px/s, which is more reasonable. [/list] So I'd say, start by changing the interval to an int value 1 and move on to the other corrections. [b]Edit:[/b] Is i ever used? I see the declaration and assume it was meant as a limit for iterations, but can't see its usage.
Okay. I'm trying to implement 2D Dynamic Shadows to my engine, but I can't for the life of me figure this article out: [url]http://www.gamedev.net/reference/articles/article2032.asp[/url] . And it seems to be the only article on the subject, without any source code to follow. Yeah, I'm pathetic for needing source code to work from, but whatever. I have the light geometry down, but I just don't understand what I'm supposed to putting down when he gives me the code: [code]for (int lightIndex=0; lightIndex<visibleLights.size(); lightIndex++) { Light currentLight = (Light)visibleLights.get(lightIndex); // Clear current alpha clearFramebufferAlpha(scene, currentLight, canvas); // Load new alpha writeFramebufferAlpha(currentLight, canvas); // Mask off shadow regions mergeShadowHulls(scene, currentLight, canvas); // Draw geometry pass drawGeometryPass(currentLight, canvas); } [/code] I have no idea how I'm supposed to go about any of that. It's like, the entire article I'm reading words, but I'm not actually learning how to do anything. Some help or someones source code that implements this would be wonderful beyond belief. I'm using SFML/OpenGL and C++, btw.
In Lua, I just do the following: [lua]function GAME:Draw() -- Draw geometry and shadows render.SetRenderTarget( self.RT ) render.SetTexture() render.SetShader() render.Clear( Color( 255, 255, 255 ) ) render.Start2D() -- Draw shapes render.SetDrawColor( Color( 255, 0, 0 ) ) for i = 1, #self.Shapes do self:DrawShape( self.Shapes[i] ) end -- Draw shadow volumes render.SetDrawColor( Color( 0, 0, 0 ) ) for i = 1, #self.Shapes do self:DrawShape( self:CalculateShadowVolume( self.Shapes[i], self.Sides[i] ) ) end render.End2D() -- Draw light sphere based on light position render.SetRenderTarget() render.SetTexture( self.RT:GetTexture() ) render.SetShader( self.LightShader ) render.SetDepthEnabled( false ) self.LightShader:SetFloat( "lightPos", self.LightPos.x / 800, 1 - self.LightPos.y / 600 ) self.LightShader:SetFloat( "lightColor", 0.8, 0.8, 1, 0.6 ) render.Start2D() render.SetDrawColor( Color( 255, 255, 255 ) ) render.DrawRect( 0, 0, 800, 600 ) render.End2D() end[/lua]
[QUOTE=NorthernGate;26050062]Okay. I'm trying to implement 2D Dynamic Shadows to my engine, but I can't for the life of me figure this article out: [url]http://www.gamedev.net/reference/articles/article2032.asp[/url] . And it seems to be the only article on the subject, without any source code to follow. Yeah, I'm pathetic for needing source code to work from, but whatever. I have the light geometry down, but I just don't understand what I'm supposed to putting down when he gives me the code: [code]for (int lightIndex=0; lightIndex<visibleLights.size(); lightIndex++) { Light currentLight = (Light)visibleLights.get(lightIndex); // Clear current alpha clearFramebufferAlpha(scene, currentLight, canvas); // Load new alpha writeFramebufferAlpha(currentLight, canvas); // Mask off shadow regions mergeShadowHulls(scene, currentLight, canvas); // Draw geometry pass drawGeometryPass(currentLight, canvas); } [/code] I have no idea how I'm supposed to go about any of that. It's like, the entire article I'm reading words, but I'm not actually learning how to do anything. Some help or someones source code that implements this would be wonderful beyond belief. I'm using SFML/OpenGL and C++, btw.[/QUOTE] Here's the explanation for the code (it's actually in the article): [code]For every light: Clear alpha buffer Load alpha buffer with light intensity Mask away shadow regions with shadow geometry Render geometry with full detail (colours, textures etc.) modulated by the light intensity.[/code] If I am not mistaken, in OpenGL you'd use a Stencil Mask. Overvs version draws normal geometry without regard to light and shadow, then overlays the shadow and then overlays the light via a custom shader. Using a mask has the advantage of the renderer not needing to draw geometry where there is shadow.
[QUOTE=Metroid48;26048148]I'm not entirely sure what the issue is, but here are a few things I've noticed: [list=1][*]Your position coordinates are integers, but your interval is a double. I'd suggest either making the interval an integer or increasing the scale of the coordinate sysem. [*]You're missing an ampersand in the conditional statement for the while loop - it should be "cx!=tx&[b]&[/b]cy!=ty". [*]Your break statements will kill the loop as soon as either cx or cy is close enough, not both. Remove them and let the while's condition take care of stopping. [*]Do the check for the positions being close enough [i]before[/i] you add/subtract the interval value. [*]Assuming everything's working, then that's 0.1 px per 50 ms or 2 px/s, which seems a bit slow. An interval of 1 would get you 20px/s, which is more reasonable. [/list] So I'd say, start by changing the interval to an int value 1 and move on to the other corrections. [b]Edit:[/b] Is i ever used? I see the declaration and assume it was meant as a limit for iterations, but can't see its usage.[/QUOTE] Thank you for you help :) Sorry, I probably should clarify... What I am trying to do is, when a person clicks somewhere on the canvas, the cube moves from its current position to the clicked position smoothly. As in it dosent jump there, it smoothly transitions there. No, I is never used. I should remove that. Edit: Okay, a much simplified version draws a line between the target and the cube, and it only moves on the x axis. It's wierd, because I added a debug to the paint() method, and even though I am calling repaint every 50 ms, its telling me its only painting when the while loop is over... Why? [code] import java.applet.*; import java.awt.*; import java.awt.event.*; public class Test extends Applet implements MouseListener, MouseMotionListener { int width, height; int cx, cy, tx, ty; // the mouse coordinates public void init() { width = getSize().width; height = getSize().height; setBackground( Color.black ); addMouseListener( this ); addMouseMotionListener( this ); } public synchronized void MoveIt() throws InterruptedException{ while(cx!=tx){ if(cx>tx){ cx--; } if(cx<tx){ cx++; } if(java.lang.Math.abs(cx-tx)<1){ cx=tx; } repaint(); wait(200); } } public void mouseEntered( MouseEvent e ) { // called when the pointer enters the applet's rectangular area } public void mouseExited( MouseEvent e ) { // called when the pointer leaves the applet's rectangular area } public void mouseClicked( MouseEvent e ) { tx = e.getX(); ty = e.getY(); try { MoveIt(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public void mousePressed( MouseEvent e ) { // called after a button is pressed down } public void mouseReleased( MouseEvent e ) { // called after a button is released } public void mouseMoved( MouseEvent e ) { // called during motion when no buttons are down } public void mouseDragged( MouseEvent e ) { // called during motion with buttons down } public void paint( Graphics g ) { System.out.println("Painting!"); g.setColor(Color.RED); g.fillRect( cx, cy, 5, 5 ); g.drawLine(tx, ty, cx, cy); } } [/code]
I'm looking for relatively good learning resources for the newer OpenGL bits (that is, non-deprecated OGL) I have found [url=http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html]this website[/url] but I'm finding it a bit hard to read and follow, for some reason.
I'm trying to make a for loop to add numbers to an array in Java, but my program doesn't work. I'm fairly new to Java and programming in general, so please help me with this. I also suck at math [cpp]public class Main{ public static void main(String[] args){ int count = 0; int numbers[] = {5}; for(count = 0; count<=10; count++){ if(count>0){ numbers[count] = numbers[count - 1] + 5; }else{ numbers[count] = numbers[count]; } } System.out.println(numbers); } }[/cpp]
You're trying to resize an array, which can't be done in Java afaik. Arrays are of fixed size. here numbers's size is 1, that means you can only call it with numbers[0]. numbers[-1] will crash (and anayways negative indexes for arrays is out of the question). [editline]14th November 2010[/editline] and you can throw away your else, count will always be greater than 0; [editline]14th November 2010[/editline] and you can throw away your else, count will always be greater than 0; [editline]14th November 2010[/editline] forget what I said about the array. [editline]14th November 2010[/editline] forget what I said about the array. [editline]14th November 2010[/editline] You must print numbers[0], not numbers. [editline]14th November 2010[/editline] You must print numbers[0], not numbers.
[QUOTE=Overv;26051287]In Lua, I just do the following: [lua]function GAME:Draw() -- Draw geometry and shadows render.SetRenderTarget( self.RT ) render.SetTexture() render.SetShader() render.Clear( Color( 255, 255, 255 ) ) render.Start2D() -- Draw shapes render.SetDrawColor( Color( 255, 0, 0 ) ) for i = 1, #self.Shapes do self:DrawShape( self.Shapes[i] ) end -- Draw shadow volumes render.SetDrawColor( Color( 0, 0, 0 ) ) for i = 1, #self.Shapes do self:DrawShape( self:CalculateShadowVolume( self.Shapes[i], self.Sides[i] ) ) end render.End2D() -- Draw light sphere based on light position render.SetRenderTarget() render.SetTexture( self.RT:GetTexture() ) render.SetShader( self.LightShader ) render.SetDepthEnabled( false ) self.LightShader:SetFloat( "lightPos", self.LightPos.x / 800, 1 - self.LightPos.y / 600 ) self.LightShader:SetFloat( "lightColor", 0.8, 0.8, 1, 0.6 ) render.Start2D() render.SetDrawColor( Color( 255, 255, 255 ) ) render.DrawRect( 0, 0, 800, 600 ) render.End2D() end[/lua][/QUOTE] Haha! Thank you! This is what I needed.
[QUOTE=pikzen;26061358]You're trying to resize an array, which can't be done in Java afaik. Arrays are of fixed size. here numbers's size is 1, that means you can only call it with numbers[0]. numbers[-1] will crash (and anayways negative indexes for arrays is out of the question). [editline]14th November 2010[/editline] and you can throw away your else, count will always be greater than 0; [editline]14th November 2010[/editline] and you can throw away your else, count will always be greater than 0; [editline]14th November 2010[/editline] forget what I said about the array. [editline]14th November 2010[/editline] forget what I said about the array. [editline]14th November 2010[/editline] You must print numbers[0], not numbers. [editline]14th November 2010[/editline] You must print numbers[0], not numbers.[/QUOTE] Arrays cant be resized ? Well fuck [editline]14th November 2010[/editline] And I want to print the entire array, not just numbers[0] [editline]14th November 2010[/editline] And I want to print the entire array, not just numbers[0] [editline]14th November 2010[/editline] What the hell is wrong with facepunch today [editline]14th November 2010[/editline] What the hell is wrong with facepunch today
when you declare [cpp] int numbers[] = {5}[/cpp] you're implicitly declaring [cpp] int numbers[1] = {5} [/cpp] For resizable array-like objects, you can use java.util.Vector ([url]http://download.oracle.com/javase/1.4.2/docs/api/java/util/Vector.html[/url])
Oh, thanks, i'll try it later
[QUOTE=ZeekyHBomb;26054072]Here's the explanation for the code (it's actually in the article): [code]For every light: Clear alpha buffer Load alpha buffer with light intensity Mask away shadow regions with shadow geometry Render geometry with full detail (colours, textures etc.) modulated by the light intensity.[/code] If I am not mistaken, in OpenGL you'd use a Stencil Mask. Overvs version draws normal geometry without regard to light and shadow, then overlays the shadow and then overlays the light via a custom shader. Using a mask has the advantage of the renderer not needing to draw geometry where there is shadow.[/QUOTE] The problem is I have no idea how to go about clearing and loading the alpha buffer and then loading it with the light intensity. The article doesn't actually go about telling me how to do that. Where as Overv's method is pretty clear.
Sorry, you need to Log In to post a reply to this thread.