[QUOTE=Sickle;35420952]Oooohh.
[csharp]
public static double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
double area = Math.sqrt(num);
}
else
{
System.out.println("Invalid triangle!");
}
return area;
}
[/csharp]
So I initialized it, gave it a value of 0, that worked, and then it gave me a 'Duplicate area local variable area'
And also, would it really be necessary to give it a negative value in the else statement if it isn't even printing it?[/QUOTE]
Remove the type declaration (double) from the assignment statement of "area" within the if statement. It thinks you are trying to declare a second variable of type double, also named area; this is not allowed because there would be no way to distinguish between the two variables, making it ambiguous. As for the negatives, I suppose a triangle of area 0 is impossible, so what you have there should work perfectly.
Well I have a couple questions, anything you could answer would be great.
Actually come to think of it I'll edit this post with another question if someone answers my first one.
(This is in C#/XNA by the way)
I have a class (GameObject), with a method to create objects from the main class.(something like GameObject lava1).
How can I add multiple objects without creating every single tile?
If you need me to ask a little more specifically just tell me.
Thanks.
[QUOTE=Rayjingstorm;35421005]Remove the type declaration (double) from the assignment statement of "area" within the if statement. It thinks you are trying to declare a second variable of type double, also named area; this is not allowed because there would be no way to distinguish between the two variables, making it ambiguous. As for the negatives, I suppose a triangle of area 0 is impossible, so what you have there should work perfectly.[/QUOTE]
Sweeeet! It worked!
Thanks again, man!
:v:
Right now I feel like blowing my brains out.. I just do not understand ActionScript 3 as well as I thought I would.
I'm trying to get my collisions to work so they aren't choppy and so that they actually work properly. I have butchered my code so many times the past 4 days its just ridiculous - all because of collisions. (Cleaned it up for facepunch [soon for myself also])
This is a top view kind of game, so everytime a player collides with a wall (from top, left, right, bottom) I want the 'Player' to stop moving. Thats all..
Maybe I am writing my code wrong - maybe I'm thinking to linearly - maybe my prof really shouldn't be a prof..
Most of the code was written by me applying logic from Java/C#.. Everything else Google was there for me!
Anyways I tried everything I could think off.. Placing Flags, putting everything in a for loop (:S), and tried stopping the speedX/Y on multiple different occasions.
If you can please help me out I will be grateful! I included the part of the code I found most important to my problem. (And yes all of this is written inside Frame)
[code]addEventListener(Event.ENTER_FRAME, entered);
function entered(event:Event)
{
playerRec = new Rectangle(Player.x, Player.y, Player.width, Player.height); //Where I initialize Player rectangle (constantly for he does move)
for(var o:uint = 0; o < wallsRec.length; o++) //I have an array off Rectangles for all the walls in my level.
{
if(playerRec.intersects(wallsRec[o])) //I check if the players rectangle intersects with any wall rectangle
{ //Without it the player might take the x or y from anyother wall inside the array (top down game)
//trace("HIT :: " + Player.x +" :: "+ wallsRec[o].x);
if(rightH) //rightH is if I am holding the right arrow key down... (if I am rightH is set to true) (on key up it goes back to false)
{
trace(Player.x + " " + Player.width);
Player.x = wallsRec[o].x - Player.width;
trace(Player.x + " " + Player.width);
}
//else if(leftH)
//{
//}
//else if(upH)
//{
//}
//else if(downH)
//{
//}
//return;
}
}
if(leftH)
{
Player.x -= speedX;
//Player.gotoAndStop("left");
}
else if(rightH)
{
Player.x += speedX;
//Player.gotoAndStop("right");
}
else if(upH)
{
Player.y -= speedY;
//Player.gotoAndStop("up");
}
else if(downH)
{
Player.y += speedY;
//Player.gotoAndStop("down");
}
this.y = -Player.y + (stage.stageHeight / 2); //This sets the where the stage is looking at..
this.x = -Player.x + (stage.stageWidth / 2); //I don't know how else to word it.. Basically Player will always remain in the center of the screen.
}[/code]
By the way when I said I butchered my code because of collisions.. I mean it.. Like the playerRec is being updated BEFORE the Player even moved.. Like that's how badly I butchered it..
Anyways gonna go get some coffee. Don't think I will sleep anytime soon
Wait a sec;
[QUOTE][csharp]
public class MyTriangle
{
double s1 = 1;
double s2 = 2;
double s3 = 2;
public static boolean isValid(double s1, double s2, double s3)
{
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public static double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp][/QUOTE]
Is there a problem on line 7?
The variables declared don't seem to correspond with the variables in the method().
Does anyone know how to fix this?
[editline]4th April 2012[/editline]
Actually, I'm a fucking idiot, I solved it.
[editline]4th April 2012[/editline]
Oh look;
[csharp]
public class MyTriangle
{
public static boolean isValid(double s1, double s2, double s3)
{
s1 = 5;
s2 = 20;
s3 = 20;
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public static double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp]
It doesn't want to output the area properly though. Can someone help?
[QUOTE=Sickle;35421456]Wait a sec;
[csharp]
public class MyTriangle
{
double s1 = 1;
double s2 = 2;
double s3 = 2;
public static boolean isValid(double s1, double s2, double s3)
{
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public static double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp]
Is there a problem on line 7?
The variables declared don't seem to correspond with the variables in the method().
Does anyone know how to fix this?[/QUOTE]
The method is static, the variables in the body of the class are not. When you refer to the variables inside of the method, you are referring to those passed to it in the main class, not the ones defined above it as they only exist as part of an object. In order to refer to them you must remove the "static" modifiers on lines 7 and 16.
[QUOTE=Rayjingstorm;35421679]The method is static, the variables in the body of the class are not. When you refer to the variables inside of the method, you are referring to those passed to it in the main class, not the ones defined above it as they only exist as part of an object. In order to refer to them you must remove the "static" modifiers on lines 7 and 16.[/QUOTE]
I did what you said;
[csharp]
public class MyTriangle
{
double s1 = 2;
double s2 = 1;
double s3 = 2;
public boolean isValid(double s1, double s2, double s3)
{
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp]
But now I'm back to square one where it won't output a proper validity for the triangle.
I think this;
[csharp]
public class MyTriangle
{
public static boolean isValid(double s1, double s2, double s3)
{
s1 = 5;
s2 = 20;
s3 = 20;
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public static double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp]
Was a proper alternative, though.
[editline]4th April 2012[/editline]
:o fixed it.
[QUOTE=Sickle;35421736]I did what you said;
[csharp]
public class MyTriangle
{
double s1 = 2;
double s2 = 1;
double s3 = 2;
public boolean isValid(double s1, double s2, double s3)
{
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp]
But now I'm back to square one where it won't output a proper validity for the triangle.
I think this;
[csharp]
public class MyTriangle
{
public static boolean isValid(double s1, double s2, double s3)
{
s1 = 5;
s2 = 20;
s3 = 20;
if((s1 < (s2 + s3)) && (s2 < (s1 + s3)) && (s3 < (s1 + s2)))
return true;
else
return false;
}
public static double area(double s1, double s2, double s3)
{
boolean valid = isValid(s1, s2, s3);
double area = 0;
if (valid == true)
{
double s = (s1 + s2 + s3)/2;
double num = s*((s-s1)*(s-s2)*(s-s3));
area = Math.sqrt(num);
}
return area;
}
}
[/csharp]
Was a proper alternative, though.
[editline]4th April 2012[/editline]
:o fixed it.[/QUOTE]
Sorry, you also needed to remove the argument list from the method, or use the "this" keyword to refer to the instance variables directly. WHat you did works but is rather confusing. By providing a formal set of paramets you imply the function will use them. In your implementation, however, you disregard the parameters and use constant values. For what you are doing a static method would be best and you could forego the creation of a new object, instead simply passing th correct values to the area function from the main. im on mh tablet, if you still need help I can try whan Im at my pc.
[QUOTE=Rayjingstorm;35422463]Sorry, you also needed to remove the argument list from the method, or use the "this" keyword to refer to the instance variables directly. WHat you did works but is rather confusing. By providing a formal set of paramets you imply the function will use them. In your implementation, however, you disregard the parameters and use constant values. For what you are doing a static method would be best and you could forego the creation of a new object, instead simply passing th correct values to the area function from the main. im on mh tablet, if you still need help I can try whan Im at my pc.[/QUOTE]
I got it down;
[csharp]
public class MyTriangleTest
{
public static void main(String[] args)
{
double s1 = 0;
double s2 = 0;
double s3 = 0;
boolean valid = MyTriangle.isValid(s1, s2, s3);
if (valid == true)
{
double area = MyTriangle.area(s1, s2, s3);
System.out.printf("Input values: %.2f, %.2f, %.2f\n", s1, s2, s3);
System.out.println("The triangle is valid!");
System.out.printf("The area of the triangle is: %.2f", area);
}
else
{
System.out.printf("Input values: %.2f, %.2f, %.2f\n", s1, s2, s3);
System.out.println("The triangle is invalid!");
}
}
}
/* OUTPUT
Input values: 20.00, 20.00, 10.00
The triangle is valid!
The area of the triangle is: 96.82
Input values: 4.00, 4.00, 2.00
The triangle is valid!
The area of the triangle is: 3.87
Input values: 6.00, 4.00, 2.00
The triangle is invalid!
Input values: 0.00, 0.00, 0.00
The triangle is invalid!
cvd
*/
[/csharp]
And this;
[csharp]
public class MyTriangle
{
public static boolean isValid(double s1, double s2, double s3)
{
boolean valid = true;
if (s1 + s2 <= s3)
{
valid = false;
return valid;
}
else if (s1 + s3 <= s2)
{
valid = false;
return valid;
}
else if (s2 + s3 <= s1)
{
valid = false;
return valid;
}
else
{
return valid;
}
}
public static double area(double s1, double s2, double s3)
{
double s = (s1 + s2 + s3)/2;
double theArea = Math.sqrt(s*((s-s1)*(s-s2)*(s-s3)));
if (theArea <= 0)
{
theArea = 0;
return theArea;
}
else
{
return theArea;
}
}
}
[/csharp]
Work's pretty well.
I have wanted to do this for a few years, and have no idea where to begin. Oh well, here goes.
I want to make an application/engine that reads and renders files from World of Warcraft.
I want to start out with basic terrain rendering from WoW's [url=http://www.pxr.dk/wowdev/wiki/index.php?title=ADT]ADT[/url] files.
Would anyone have any idea where to start? Or which base graphics engine to use? I have basic Java and C# knowledge.
[QUOTE=Marlamin;35423869]I have wanted to do this for a few years, and have no idea where to begin. Oh well, here goes.
I want to make an application/engine that reads and renders files from World of Warcraft.
I want to start out with basic terrain rendering from WoW's [url=http://www.pxr.dk/wowdev/wiki/index.php?title=ADT]ADT[/url] files.
Would anyone have any idea where to start? Or which base graphics engine to use? I have basic Java and C# knowledge.[/QUOTE]
If you wanna go with Java have a look at JOGL or LWGL (different OpenGL libraries for Java, JOGL is a bit more advanced in terms of capabilities) but I think it'd be easier for you to pick up XNA with C#.
As for the ADT file format itself: [url]http://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-model-editing/wow-me-tools-guides/60300-basic-introduction-structure-of-wows-files-hexediting.html[/url]
If you've never done any binary access file saving/loading stuff you'll need to research that too, and I'm guessing that the maps don't store the models themselves, just the model position, rotation, etc. As for the terrain information you can get that from the map files for sure.
Bounding box collision detection / AABBs.
Specifically, how do you detect if certain sides of a box is colliding with other sides. For things like top-down games where you need to disable one direction the player can move in if they collide with something.
[url]https://github.com/niobium93/Booru-Viewer/blob/master/booruViewer/Form1.cs[/url]
Trying to download and display thumbnails from a website into a listView using C#. Having a few problems:
Sometimes my ThumbSetter function sets all/most of the thumbnails as the same image.
[thumb]http://www.1337upload.net/files/64Capture.PNG[/thumb]
Other times it works perfectly. The most common thing people assume is that it somehow gets a list of identical thumbs, but that's not the case - I've viewed the thumbs list in the debugger countless times and all the thumb urls are always different. Also the image that gets repeated is always the last thumb on the site.
Another problem is that listViews use ImageLists for storing images and those only let me have a single global size for all the images that it then stretches all the images to. To make things even worse, this size is restricted to the maximum of 256x256. Is there any way I can change this or even some other control/container I can use for displaying thumbs?
Hey guys,
[csharp]
public static void main(String[] args)
{
int array [] = new int[50];
Random num = new Random();
int number = 0;
for (int i = 0; i < array.length; i++)
{
array[i] = (int)((Math.random() * 100) + 1);
number = num.nextInt(100) + 1;
System.out.print(array[i] + " ");
if (i % 10 == 0)
{
System.out.println();
i = 0;
}
}
}
[/csharp]
How can I get this to stop printing after it's printed 5 lines?
At the moment it goes on forever.
[QUOTE=Sickle;35430933]Hey guys,
[csharp]
public static void main(String[] args)
{
int array [] = new int[50];
Random num = new Random();
int number = 0;
for (int i = 0; i < array.length; i++)
{
array[i] = (int)((Math.random() * 100) + 1);
number = num.nextInt(100) + 1;
System.out.print(array[i] + " ");
if (i % 10 == 0)
{
System.out.println();
i = 0;
}
}
}
[/csharp]
How can I get this to stop printing after it's printed 5 lines?
At the moment it goes on forever.[/QUOTE]
Why were you making an array of 50 ints if you're only going to use the first 10?
[QUOTE=Hypershadsy;35431313]You're setting i = 0 when i == 10, which means you're constantly overwriting the first 11 numbers in your array.[/QUOTE]
When I don't set i = 0 I get this;
[B]48 [/B]
92 88 91 46 23 44 34 33 35 76
74 63 13 31 99 98 46 38 11 45
30 27 35 97 92 53 31 9 57 30
87 28 40 49 17 28 68 17 54 25
15 32 89 10 73 34 89 61 37
That looks better, but how do I get that stray [B]element [/B]into the whole block again?
[QUOTE=Sickle;35431265]I made an array of 50 ints so that I could use 10 for every line. And I need only 5 lines.
Therefore I'd have 50.
The output is currently;
'90 23 81 75 25 23 3 82 26 64
83 26 61 53 43 52 75 1 74 52
86 65 64 87 30 67 53 73 32 35
34 1 82 11 5 98 23 26 30 88
54 59 7 37 22 48 43 2 31 70
29 60 4 18 98 41 98 20 32 4
60 87 15 33 4 88 97 45 81 5
55 59 3 28 52 89 81 31 4 79
49 48 54 50 35 14 20 38 47 36
58 16 72 6 32 66 77 95 96 18
28 71 47 11 58 86 6 57 49 11
47 50 3 86 31 61 17 19 40 85
98 11 47 57 16 35 18 11 90 60
93 2 79 54 39 7 77 80 35 1
68 27 18 4 37 63 55 89 93 40
19 12 28 19 68 85 66 68 54 22
61 88 3 23 33 48 59 8 13 84
1 21 57 93 85 7 39 84 8 56
21 73 24 34 100 11 88 40 79 10
77 73 27 68 53 17 89 73 10 55
58 13 10 42 88 72 62 89 48 7
65 93 100 84 13 41 28 54 23 35
87 54 18 56 58 12 97 39 84 66
57 69 14 70 87 21 79 70 63 56
77 91 18 56 26 12 39 17 49 78
28 77 6 98 66 98 98 20 55 82
69 97 47 83 85 13 69 78 25 56
73 23 64 70 34 62 73 91 83 83
42 64 3 13 69 73 54 16 25 59
84 29 91 7 58 94 3 44 30 52
41 12 52 75 52 53 32 57 94 11
6 60 54 44 32 98 92 1 72 85
45 85 65 34 18 74 58 46 70 34
24 88 37 100 56 52 89 46 84 1
57 87 35 62 58 37 35 89 54 84
6 38 4 71 20 16 79 5 8 28
30 61 62 37 18 63 91 60 51 5
46 80 93 67 70 13 41 98 61 67
...........................................'
So I'm on to something. But I have no clue how to get it to shut up after 5 lines of 10 ints.[/QUOTE]
If you want a array with lines and columns, you should make a bidimensional vector.
will be something like int array [] = new int[10][5]; (?)
then you will use 2 for
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
//and you will print array[i][j]
}
}
It's cool I fixed it.
When it comes to integrating Lua with C++, is it possible to make it so that in the lua script I have something like:
[code]
w1 = new Wall(0,0,500,32)
w1.color = new color(255, 255, 255)
new Wall(0,500, 32, 32)
new Wall(0,520, 32, 32)
...
[/code]
Not really.
[editline]5th April 2012[/editline]
One thing you [B]could[/B] do is something like new.Wall and give new a metatable __index that makes it construct shit. Somehow.
[QUOTE=esalaka;35432146]Not really.
[editline]5th April 2012[/editline]
One thing you [B]could[/B] do is something like new.Wall and give new a metatable __index that makes it construct shit. Somehow.[/QUOTE]
Well its more a case of atm I only know how to do [b]lua_getglobal(L, "Width");[/b]
But if I were to have say 20 different wall objects how would I differentiate between them, or how would I get them?
I mean having a table of say:
[code]
wall{
int posX
int posY
int width
int height
color col
...
}
[/code]
And then having to specify each parameter individually isnt a problem
[csharp]
boolean inArray = false;
for (int m = 0; m < array.length; m++)
{
if (array[m] == target)
{
int index = m;
System.out.println(target + " is at index " + index + " in the array.");
}
if (inArray = false)
{
System.out.println(target + " is not in the array!");
}
}
[/csharp]
Hey guys, why does my if (inArray = false) never execute, even when I have the target?
(There's more code if you guys need it)
[QUOTE=Sickle;35432500][csharp]
boolean inArray = false;
for (int m = 0; m < array.length; m++)
{
if (array[m] == target)
{
int index = m;
System.out.println(target + " is at index " + index + " in the array.");
}
if (inArray = false)
{
System.out.println(target + " is not in the array!");
}
}
[/csharp]
Hey guys, why does my if (inArray = false) never execute, even when I have the target?
(There's more code if you guys need it)[/QUOTE]
you need double =
change it to (inArray == false)
[QUOTE=Richy19;35432613]you need double =
change it to (inArray == false)[/QUOTE]
Ooohhh, thanks, man!
Oh wow, no matter what I do, the thing outputs, 'x is not in the array!'
[csharp]
target = (int)((Math.random() * 100) + 1);
System.out.println("The target is " + target);
boolean inArray = false;
for (int m = 0; m < array.length; m++)
{
if (array[m] == target)
{
int index = m;
inArray = true;
System.out.println(target + " is at index " + index + " in the array.");
}
else
{
inArray = false;
}
}
if (inArray == false)
{
System.out.println(target + " is not in the array!");
}
[/csharp]
Anyone know what I'm doing wrong with my if statements?
I want to have a mini console in my game, where I can output stuff or input stuff, but I want to also display all the cout stuff in it, now I managed to find out how to cnage the cout to be a different fstream to for example write it to a file, but I was wondering how can I access what is stored in the cout's stream?
my idea was to say during the init stages or update stages have stuff output to cout, then have the console class read all the stream of the cout in the update stage and just print it to screen
Is this possible?
[QUOTE=Richy19;35433089]I want to have a mini console in my game, where I can output stuff or input stuff, but I want to also display all the cout stuff in it, now I managed to find out how to cnage the cout to be a different fstream to for example write it to a file, but I was wondering how can I access what is stored in the cout's stream?
my idea was to say during the init stages or update stages have stuff output to cout, then have the console class read all the stream of the cout in the update stage and just print it to screen
Is this possible?[/QUOTE]
I also need to know this! :D
How do i go about turning a floating point number into an integer? And i dont mean by rounding, i mean by scaling the floating point number so that float_max and float_min map to int_max and int_min.
Unfortunately opencl only allows for an integer depth buffer due to stupid atomic functions. So i need to convert my floating point numbers to integers while retaining precision, and then back again
Currently im just times-ing them by a large constant, but i get the feeling there is a proper way to do it out there somewhere. Or at the very least, a much better way of doing it
Edit:
Or, if anyone has any solutions as to how to work an integer depth buffer, i'd love to here it
[QUOTE=Icedshot;35434605]How do i go about turning a floating point number into an integer? And i dont mean by rounding, i mean by scaling the floating point number so that float_max and float_min map to int_max and int_min.[/QUOTE]
That's not going to work well for you at all.
You might be able to get [i]something[/i] out of it if you map logarithmically.
Like:
int y = sign(x) * (float)INT_MAX * (128.0 + log2(abs(x))) / 256.0
...and whatever the reverse process of that is.
Edit:
The reverse process is:
float x = sign(x) * exp2(256.0 * (float)abs(x) / (float)INT_MAX - 128.0)
[QUOTE=Icedshot;35434605]Unfortunately opencl only allows for an integer depth buffer due to stupid atomic functions. So i need to convert my floating point numbers to integers while retaining precision, and then back again[/QUOTE]
Don't try to map the entire range of values. That's a bad idea. Choose a 'near plane' and a 'far plane' and scale that range to the range of integers. Look at how OpenGL handles projection. It uses integer depth buffers for most things.
[QUOTE=Icedshot;35434605]Currently im just times-ing them by a large constant, but i get the feeling there is a proper way to do it out there somewhere. Or at the very least, a much better way of doing it[/QUOTE]
[url]http://www.songho.ca/opengl/gl_projectionmatrix.html[/url]
And after you've got depth in the [-1, 1] range, it's trivial to remap to the range of integers.
Sorry, you need to Log In to post a reply to this thread.