• What do you need help with? Version 1
    5,001 replies, posted
Get the difference of x of the point and x of the object, get the same for y. (I'll call them deltaX and deltaY) Then get the angle from the object to the point using angle=atan(deltaY/deltaX). Add cos(angle)*speed to the x coordinate of your object and sin(angle)*speed to the y. That's how you do it with trigonometry at least. I'm sorry if this doesn't answer your question or if I made any mistakes. I just wrote that from my head. [editline]10:08PM[/editline] Hmmm, there might be a way to do it without trig. Get the distance from the object to the point. Do speed/distance (let's call it percent) Then add (point.x-object.x) * percent to the x of the object and (point.y-object.y) * percent to the y. This also should work but I can never be sure. [editline]10:16PM[/editline] Both methods work, I changed the first one a bit.
[QUOTE=quincy18;21447139][url]http://www.tomshane.cz/neoforce/License/tabid/58/Default.aspx[/url] Does this mean I can use this in my XNA game and if I want sell it on xbox ?[/QUOTE] [quote]NEOFORCE in its binary form is free for non-commercial and commercial use[/quote] Yes, but you have to pay for source code access.
[QUOTE=Darwin226;21509078]Get the difference of x of the point and x of the object, get the same for y. (I'll call them deltaX and deltaY) Then get the angle from the object to the point using angle=atan(deltaY/deltaX). Add cos(angle)*speed to the x coordinate of your object and sin(angle)*speed to the y. That's how you do it with trigonometry at least. I'm sorry if this doesn't answer your question or if I made any mistakes. I just wrote that from my head. [editline]10:08PM[/editline] Hmmm, there might be a way to do it without trig. Get the distance from the object to the point. Do speed/distance (let's call it percent) Then add (point.x-object.x) * percent to the x of the object and (point.y-object.y) * percent to the y. This also should work but I can never be sure. [editline]10:16PM[/editline] Both methods work, I changed the first one a bit.[/QUOTE] Thanks for replying. I've imported java.lang.math.*, but I still get "cannot find symbol atan(double a)" when I try to find the angle. Do I need to import something else too? [code] /* Called on mouse release to fire a missile. */ private void fire(int x, int y) { if (y <= TURRET_POS_Y) { return; } else { fireball = new GOval(FIREBALL_SIZE, FIREBALL_SIZE); fireball.setColor(Color.ORANGE); fireball.setFillColor(Color.ORANGE); fireball.setFilled(true); double dX = TURRET_POS_X - x; double dY = TURRET_POS_Y - y; double tanValue = (dY/dX); double angle = atan(tanValue); //<--------------------------PROBLEM add (fireball, TURRET_POS_X - (FIREBALL_SIZE / 2), TURRET_POS_Y - (FIREBALL_SIZE / 2)); } }[/code]
[URL="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html"]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html[/URL] Use atan2 and then instead of deltay/deltax, pass deltay, deltax as arguments. [editline]11:07PM[/editline] Oh, and I think you should use Math.atan2, not just atan2 but I'm not sure since I don't know java.
Can anyone educate me on 2D Sweep & Prune a bit? I can't really understand the difference between a simple AABB overlap test and S&P, as all the info I've managed to gather so far is "store their upper and lower bounds and check if they overlap". There's some sort of sorting algorithm jiggery pokery surrounding it but I can't find anywhere that explains it clearly enough.
[QUOTE=Darwin226;21510736][URL="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html"]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html[/URL] Use atan2 and then instead of deltay/deltax, pass deltay, deltax as arguments. [editline]11:07PM[/editline] Oh, and I think you should use Math.atan2, not just atan2 but I'm not sure since I don't know java.[/QUOTE] okay, thanks. I'll keep dicking around with it until it works, hopefully.
I want to make a prompt with several text input boxes pop up when someone presses a button in my C# Mandelbrot plotter. I have not been able to figure it out, or find anything on Google. Thanks for your help.
How can I convert a 24-bit colour into a 4-bit colour (RGBI, 16 possible values)?
Take the most significant bit of red green and blue and use that for the RGB. The last bit should be something like if the sum of the colors is more than 128*3. That's what I would do, anyway.
[QUOTE=noctune9;21518724]Take the most significant bit of red green and blue and use that for the RGB. The last bit should be something like if the sum of the colors is more than 128*3. That's what I would do, anyway.[/QUOTE] Checking if the sum of all colours is > 128 * 3 doesn't always give proper results, but the rest was good advice: [img]http://i40.tinypic.com/16bgimr.png[/img] (Loaded from a 24-bit bitmap)
i'm trying to make a variable that is dynamically changeable, the first part being "v" then having a variable v that counts up every time a "v" variable is made. heres my code for a new "v" variable... [QUOTE]var ["v"+v]:objectArray = new objectArray(pX, pY, vX, vY);[/QUOTE]for some annoying reason it returns "Identifier expected" on that line. i have done stuff like this before but with the attachMovie(); method. but not a custom method. (which is in an .as file if it makes a difference)
Yeah, you either make a thread or make a post. Not both.
Can't find what is wrong with a bit of code for sorting a vector of strings by length: [code] // this function is used with the sort function as a binary comparison bool comparelength(const string& a, const string& b){ return (a.length() < b.length());} int main() vector<string> result; //.... fill 'result' with strings sort(result.begin(), result.end(), comparelength); // =========== finished ========== for(vector<string>::iterator iter = result.begin(); iter != result.end(); ++iter) { cout<< (*iter) << endl; } [/code] But for some reason the outputted data is always in the order that it was added to the vector, and not sorted. I found [URL="http://www.java2s.com/Tutorial/Cpp/0540__STL-Algorithms-Sorting/Usecustomfunctionandsorttosortstringsbylength.htm"]this[/URL] page that has identical code (I've not tested it), so what could be wrong with mine?
Have you tried changing (a.length() < b.length()) to (a.length() > b.length())?
[QUOTE=Darwin226;21521389]Have you tried changing (a.length() < b.length()) to (a.length() > b.length())?[/QUOTE] Fixed it, wasn't anything to do with the code. During testing one of the exes crashed but never terminated. When I was using compile+run it was running the old exe since it couldn't overwrite file, and I wasn't paying attention to the compile logs.
Is there a way to group methods in a static class? For example. Class Math has methods like Abs, Max and so on. Would it be possible to make a Class that has 2 groups of methods (one is basic and one is advanced) and when you want to call those methods you use Class.Basic.Method() or Class.Advanced.Method() One way would be to instance another class (Basic and Advanced) inside the static class and then call methods from them but I don't want to be able to instance the Basic and Advanced classes outside of that specific static class. Thanks for the help. [editline]04:36PM[/editline] Almost forgot to mention. It's C#
[QUOTE=Darwin226;21522332]Is there a way to group methods in a static class? For example. Class Math has methods like Abs, Max and so on. Would it be possible to make a Class that has 2 groups of methods (one is basic and one is advanced) and when you want to call those methods you use Class.Basic.Method() or Class.Advanced.Method() One way would be to instance another class (Basic and Advanced) inside the static class and then call methods from them but I don't want to be able to instance the Basic and Advanced classes outside of that specific static class. Thanks for the help. [editline]04:36PM[/editline] Almost forgot to mention. It's C#[/QUOTE] I don't know if you can do this in C#, but can't you make the constructor private and make the math class a friend of basic and advanced?
[QUOTE=Darwin226;21522332]Is there a way to group methods in a static class? For example. Class Math has methods like Abs, Max and so on. Would it be possible to make a Class that has 2 groups of methods (one is basic and one is advanced) and when you want to call those methods you use Class.Basic.Method() or Class.Advanced.Method() One way would be to instance another class (Basic and Advanced) inside the static class and then call methods from them but I don't want to be able to instance the Basic and Advanced classes outside of that specific static class. Thanks for the help. [editline]04:36PM[/editline] Almost forgot to mention. It's C#[/QUOTE] I've never used c# before, but if it has namespaces you could use those.
C# apparently doesn't have friend classes (alternative?) and I think you can only seperate classes with namespaces, not the methods in them. I thought about using nested classes but that wouldn't be good as a method from the nested class would have to access some variables from it's parent class and to do that I would have to pass references and whatnot. Any other ideas?
[QUOTE=Darwin226;21522763]C# apparently doesn't have friend classes (alternative?) and I think you can only seperate classes with namespaces, not the methods in them. I thought about using nested classes but that wouldn't be good as a method from the nested class would have to access some variables from it's parent class and to do that I would have to pass references and whatnot. Any other ideas?[/QUOTE] Put class Basic and class Advanced in the Math namespace
I don't really think that would solve my issue (which isn't really an issue but it would be convenient if it were possible). I have a Liner class that is in charge of drawing vector graphics. It has a var Image that is the image it draws on. If I have nested classes they would all have to draw on the SAME image (meaning I would have to pass references to that image) and as far as I know you can't have variables in namespaces alone, only classes.
It looks like you're doing the whole OOP thing wrong.
Hey, how can I make a picturebox's location the same as the mouses position? C# btw
Does anyone know how to run a method in one class in a different class in C#? I have not been able to get it to work.
[QUOTE=SamPerson123;21536360]Does anyone know how to run a method in one class in a different class in C#? I have not been able to get it to work.[/QUOTE] What the fuck are you trying to do?
[QUOTE=Chad Mobile;21534666]Hey, how can I make a picturebox's location the same as the mouses position? C# btw[/QUOTE] [url]http://www.geekpedia.com/tutorial55_Mouse-coordinates.html[/url] Enjoy, no one is giving you code. Work it out yourself via google. Since that's where I pulled that from. Searching "How to get mouse position in C#"
[QUOTE=turb_;21532189]It looks like you're doing the whole OOP thing wrong.[/QUOTE] That was really helpful. What's wrong with trying to organize my methods so I don't have to scroll through IntelliSense to find the method I want? Sure you can understand that.
[QUOTE=turb_;21536855]What the fuck are you trying to do?[/QUOTE] I need to change some values in the other class, and I thought a method was the way I was supposed to do it.
[QUOTE=Darwin226;21540941]That was really helpful. What's wrong with trying to organize my methods so I don't have to scroll through IntelliSense to find the method I want? Sure you can understand that.[/QUOTE] If you were doing it properly, there should be no need for a global variable (you were describing it was 'variables in namespaces')
Oh. Sorry then, I didn't know what I was talking about. When that guy said namespaces that was the first thing that came to mind when I tried to apply them to my problem. As far as I know you can only put classes into separate namespaces, not the methods in them.
Sorry, you need to Log In to post a reply to this thread.