• What do you need help with? V4 (January 2012)
    966 replies, posted
  • Avatar of NovembrDobby
  • Need help with something? Post it here! [url=http://www.facepunch.com/threads/1092921]V3[/url] [url=http://www.facepunch.com/threads/1053117]V2[/url] [url=http://www.facepunch.com/threads/910202]V1[/url]
  • Avatar of Exosel
  • How would I go about making a sprite rotate depending on the location of the mouse? Could someone give me a general idea on how to do it.(I'm using SFML and C++)
  • Avatar of robmaister12
  • What type of rotation are you talking about? Do you want the angle to change as you move the mouse in along the X axis or do you want to have the sprite point towards the cursor?
  • Avatar of Exosel
  • [QUOTE=robmaister12;34013215]What type of rotation are you talking about? Do you want the angle to change as you move the mouse in along the X axis or do you want to have the sprite point towards the cursor?[/QUOTE] I want the sprite to point towards the cursor.
  • Avatar of Funley
  • [QUOTE=Exosel;34013443]I want the sprite to point towards the cursor.[/QUOTE] Use Atan2. In pseudocde: [code]rotation = Atan2(mouse.Y - object.Y, mouse.X - object.Y)[/code] If that doesnt work, try flipping the arguments as in mouse.X - object.X and mouse.Y - object.Y. The returned angle will be in radians.
  • Avatar of robmaister12
  • Additionally, here's something I recently learned relating to atan2: [code]angleBetween = atan2(cross(v1, v2), dot(v1, v2))[/code] can also be done with 2d vectors by using the [url=http://mathworld.wolfram.com/PerpDotProduct.html]perpendicular dot product[/url]: [code]angleBetween = atan2(perpDot(v1, v2), dot(v1, v2))[/code] [editline]2nd January 2012[/editline] where v1 and v2 are 3d vectors in the first code example, and 2d vectors in the second.
  • Avatar of raBBish
  • [QUOTE=robmaister12;34014540]Additionally, here's something I recently learned relating to atan2: [code]angleBetween = atan2(cross(v1, v2), dot(v1, v2))[/code] can also be done with 2d vectors by using the [url=http://mathworld.wolfram.com/PerpDotProduct.html]perpendicular dot product[/url]: [code]angleBetween = atan2(perpDot(v1, v2), dot(v1, v2))[/code] [editline]2nd January 2012[/editline] where v1 and v2 are 3d vectors in the first code example, and 2d vectors in the second.[/QUOTE] Isn't that the same as acos(dot(v1, v2))? vvvvvv Completely forgot about that.
  • Avatar of robmaister12
  • [QUOTE=raBBish;34014610]Isn't that the same as acos(dot(v1, v2))?[/QUOTE] Yes, but atan2 is prefered over acos because of inaccuracies when nearing 0 and pi. Also atan2 gives the direction of rotation from v1 to v2 where acos does not, because the range of atan2 is [-pi, pi) where the range of acos is (0, pi)
  • Avatar of flayne
  • I'm getting strange compiler errors with VC++ :'( [url]http://www.facepunch.com/threads/1152160[/url] Resolved thanks guys! :D
  • Avatar of Exosel
  • [QUOTE=Funley;34013503]Use Atan2. In pseudocde: [code]rotation = Atan2(mouse.Y - object.Y, mouse.X - object.Y)[/code] If that doesnt work, try flipping the arguments as in mouse.X - object.X and mouse.Y - object.Y. The returned angle will be in radians.[/QUOTE] I did this but it still doesn't work properly: [cpp] MouseRad = atan2(sf::Mouse::GetPosition().x - shipSpr.GetPosition().x, sf::Mouse::GetPosition().y - shipSpr.GetPosition().y); MouseDeg = (MouseRad) * (180/PI); shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2); shipSpr.Rotate(MouseDeg); [/cpp]
  • Avatar of Nigey Nige
  • Quoting from last thread because Garry closed it on me, the bellend. [quote=Nigey Nige]I'm making a top-down 2D exploration game (using Slick), and I want to continuously reveal more of the map through fog as the player explores. I can't think of a good way to do this. Ideas?[/quote] [quote=reevezy67]I know one of the more common/efficient methods is called shadow casting and I would actually know how to do this too.[/quote] Shadow casting sounds interesting, but I want the map to slowly turn from grey fog into explored regions [I]and[/I] stay that way once uncovered. Is that the best way of doing it?
  • Avatar of Chuushajou
  • Ever had one of those days where everything is going perfect- and you get loads done? Well mine's just gone to shit. The problem is that Google Maps isn't unloading(?) when another scene is being selected- thus giving the end result of this; [T]http://i.imgur.com/ZSsXH.png[/T]
  • Avatar of flayne
  • I need help with VC++ 2010 express. I need to set up my additional include directories from an environment variable so my entire team can use the same directories. How would I do this?
  • Avatar of Mr. Smartass
  • There's an issue with what I assume is either my installation of XNA, or visual studio. Whenever I save a project, the content folder for said project instantly thinks it's corrupt, even though it can still access the content within it. This prevents me from adding any new resources, and is very frustrating. What can I do to fix this? The content folder is doing this: [img]http://dl.dropbox.com/u/12024286/Wasd%20awasrd.PNG[/img] Help would really be appreciated, I've been locked from programming for almost two weeks because of this.
  • Avatar of sim642
  • [QUOTE=Exosel;34016983]I did this but it still doesn't work properly: [cpp] MouseRad = atan2(sf::Mouse::GetPosition().x - shipSpr.GetPosition().x, sf::Mouse::GetPosition().y - shipSpr.GetPosition().y); MouseDeg = (MouseRad) * (180/PI); shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2); shipSpr.Rotate(MouseDeg); [/cpp][/QUOTE] .Rotate() does it relative to current rotation if you want to set rotation you should use .SetRotation() instead.
  • Avatar of Lord Ned
  • [QUOTE=Mr. Smartass;34017952]There's an issue with what I assume is either my installation of XNA, or visual studio. Whenever I save a project, the content folder for said project instantly thinks it's corrupt, even though it can still access the content within it. This prevents me from adding any new resources, and is very frustrating. What can I do to fix this? The content folder is doing this: [img]http://dl.dropbox.com/u/12024286/Wasd%20awasrd.PNG[/img] Help would really be appreciated, I've been locked from programming for almost two weeks because of this.[/QUOTE] Reinstall XNA/Visual Studio? Or see if you can edit the content-project manually. It won't be fun but it might work.
  • Avatar of NovembrDobby
  • [QUOTE=Exosel;34016983]I did this but it still doesn't work properly[/QUOTE] You got the X and Y backwards in atan2, it seems weird but it's Y then X. Try this: [code] MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x); [/code]
  • Avatar of Mr. Smartass
  • [QUOTE=Lord Ned;34018040]Reinstall XNA/Visual Studio? Or see if you can edit the content-project manually. It won't be fun but it might work.[/QUOTE] Edit it how so? As in edit the actual folder's contents?
  • Avatar of Exosel
  • [QUOTE=NovembrDobby;34018064]You got the X and Y backwards in atan2, it seems weird but it's Y then X. Try this: [code] MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x); [/code][/QUOTE] Okay, I changed my code to this but it seems that the sprite is not rotating on its own center even though I made the sprite's origin in the center of the sprite: [cpp] MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x); MouseDeg = (MouseRad) * (180/PI); shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2); shipSpr.SetRotation(MouseDeg); [/cpp] I think I found the problem, I'm setting the origin to the position where the sprite is, not on the sprite.
  • Avatar of Lord Ned
  • [QUOTE=Mr. Smartass;34018158]Edit it how so? As in edit the actual folder's contents?[/QUOTE] The Reference Content is set up as it's own visual-studio project inside it's folder correct? See if you can muck around with just that (and not your big project that includes it).
  • Avatar of BlkDucky
  • [QUOTE=Hypershadsy;34018851]How come math.random() in LOVE isn't random.[/QUOTE] Because you're not seeding it, presumably. try putting math.randomseed(os.time()) in love.load(). Only call it once.
  • [QUOTE=Hypershadsy;34018851]How come math.random() in LOVE isn't random.[/QUOTE] Because the seed doesn't change(but does when you call random). Just put math.random() in the update function to get better random numbers. [editline]2nd January 2012[/editline] And that
  • [QUOTE=Exosel;34018294]Okay, I changed my code to this but it seems that the sprite is not rotating on its own center even though I made the sprite's origin in the center of the sprite: [cpp] MouseRad = atan2(sf::Mouse::GetPosition().y - shipSpr.GetPosition().y, sf::Mouse::GetPosition().x - shipSpr.GetPosition().x); MouseDeg = (MouseRad) * (180/PI); shipSpr.SetOrigin(shipSpr.GetPosition().x/2, shipSpr.GetPosition().y/2); shipSpr.SetRotation(MouseDeg); [/cpp] Instead it's rotating around a certain point on the window and it's rotation is a bit wonky: [/QUOTE] SetOrigin() is relative to the top left corner of the object, so instead you should use something like that : [cpp] shipSpr.SetOrigin(shipSpr.GetTexture().GetWidth()/2, shipSpr.GetTexture().GetHeight()/2); [/cpp]
  • Avatar of Exosel
  • [QUOTE=Cyril;34019054]SetOrigin() is relative to the top left corner of the object, so instead you should use something like that : [cpp] shipSpr.SetOrigin(shipSpr.GetTexture().GetWidth()/2, shipSpr.GetTexture().GetHeight()/2); [/cpp][/QUOTE] I tried this and it worked, it put the origin on the sprite. Now just to fix the rotation.
  • Avatar of subenji99
  • [QUOTE=Map in a box;34018992]Because the seed doesn't change(but does when you call random). Just put math.random() in the update function to get better random numbers.[/QUOTE] That's not how a psuedo-RNG works. For the same seed, the order of 'random' numbers will be the same each time. Each seed value gives a different order of random numbers. This is how any procedural game with map seeds work - that seed is given to the RNG, which spits out the same 'random' numbers in the same order on any machine. You are just describing calling the RNG constantly - both a waste of cpu cycles and unfit for purpose - if the program runs at peak speed every time your numbers would still not be random each execution. Seeding to the current system clock guarantees that the numbers will be a different sequence each time.
  • Avatar of LuaGuy
  • well i stuck for a while, i wanna make a program with 5 column of numbers and wanna increase them whenever the user input's a number from 1 to 5 for example if the user enters 2 it will increase all of the numbers by 2. but im stuck at returning from queryFunc to main function. and without it program cant keep working. if i can do this i will add the else statement and finish my job. hope you guys can help me im a little bit beginner in C++ [cpp]#include <iostream> using namespace std; void drawFunc(); void askFunc(); void queryFunc(); int main() { int x = 1; drawFunc(); askFunc(); queryFunc(); return 0; } void drawFunc() { int x = 1; while(x <= 5) { cout << x << "|" << x << "|" << x << "|" << x << "|" << x << endl; x = x++; } } void askFunc() { int x = 1; cout << "Enter a number from 1 to 5: "; cin >> x; } void queryFunc() { int x = 1; if(x == 2 | 3 | 4 | 5) { /* i wanna return to the main function from here but i cant as i said above. */ } }[/cpp] also defining same variable in all functions is weird i dont know how i can shorten it also is there a way to make the columns dynamic without need for go down ?
  • [QUOTE=Hypershadsy;34025011]Except they still aren't even after I seed it in love.load().[/QUOTE] What OS?
  • Avatar of Second-gear-of-
  • Does anyone know how I'd make a certain date show up in a timer for Android? [code]Calendar c = Calendar.getInstance(); int seconds = c.get(Calendar.SECOND)[/code] That is what I read to do, but I have no idea where to put this. Would I put it under strings.xml or layout.xml? I'm confused as hell. This is what I have currently: [code]<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="30dp"> <TextView android:id="@+id/day" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Day " android:textSize="36sp" /> <TextView android:id="@+id/hour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="00" android:textSize="36sp" /> <TextView android:id="@+id/min" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=":00" android:textSize="36sp" /> <TextView android:id="@+id/sec" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text=":00" android:textSize="36sp" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enter End Time : " /> <EditText android:id="@+id/end" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="5dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enter Start Time : " /> <EditText android:id="@+id/start" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="40dp" > <Button android:id="@+id/btnstart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start Counter" /> <Button android:id="@+id/btnstop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop" /> </LinearLayout> </LinearLayout>[/code]