Cheezmeister
|
|
« Reply #280 on: September 26, 2015, 01:35:27 PM » |
|
So this is dumb, but I'm having more trouble than it feels like I should. How in the world do I reflect a moving particle off of a square? Here's what I'm describing: The red arrow is the path of the object, the green is where I want it to go. And yes, I'm using Euler integration because I'm lazy. I know point a (where the red arrow starts), point b (where it ends), and the fact that there's a collision. It seems hella simple to just get the point of intersection and calculate the reflected ray, but there's a lot of corner cases (no pun intended). Halp?
|
|
|
Logged
|
|
|
|
gimymblert
|
|
« Reply #281 on: September 26, 2015, 02:26:57 PM » |
|
Axis aligned boxes? If yes, you just permute the relevant composite, compute the ratio where the intersection happen, inverse the ratio and compute the length along the reflected direction.
|
|
|
Logged
|
|
|
|
DragonDePlatino
|
|
« Reply #282 on: September 26, 2015, 02:30:34 PM » |
|
Yes, on modern hardware (with a modern version of MS Paint =P) there's little reason for color key transparency. Thanks for clearing that up for me. Yeah, it seems like a lot of older programmers insist on keeping old conventions even if they're not necessary anymore (like having to return 0 in main). That section was only written a little over a year ago but it seems a little unnecessary nowadays. No problems. Just save a PNG as usual — you seem to have figured that out already. To get good results when rotating sprites, you might want to set a higher value for this hint. Heh, not even! I'm going to be making a nice crispy pixel art game, so after Lazy Foo insisted I use linear rotation I immediately found that hint page and set it to nearest neighbor instead. Thanks anyways, though.
|
|
|
Logged
|
|
|
|
oahda
|
|
« Reply #283 on: September 26, 2015, 02:39:22 PM » |
|
Well, or a lower value, depending on your needs, of course. But great — you're all set!
|
|
|
Logged
|
|
|
|
Cheezmeister
|
|
« Reply #284 on: September 26, 2015, 02:45:34 PM » |
|
Axis aligned boxes?
Yep. If yes, you just permute the relevant composite, compute the ratio where the intersection happen, inverse the ratio and compute the length along the reflected direction.
? I don't know what any of that means :x Is there something I should be googling here?
|
|
|
Logged
|
|
|
|
ThemsAllTook
|
|
« Reply #285 on: September 26, 2015, 03:32:04 PM » |
|
? I don't know what any of that means :x
I don't either, but here's some vector reflection math: float Vector2f_dot(Vector2f vector1, Vector2f vector2) { return vector1.x * vector2.x + vector1.y * vector2.y; }
Vector2f Vector2f_reflect(Vector2f vector, Vector2f normal) { Vector2f result; float dot; dot = Vector2f_dot(vector, normal); result.x = vector.x - 2.0f * dot * normal.x; result.y = vector.y - 2.0f * dot * normal.y; return result; }
You'll probably want to subtract the point of intersection from point b, reflect that, then add the point of intersection to the result to get the new position. ...or do you also need to figure out how to calculate the point of intersection (which is a much harder problem)?
|
|
|
Logged
|
|
|
|
gimymblert
|
|
« Reply #286 on: September 26, 2015, 03:35:04 PM » |
|
NINJA BY THEMSALLTOOK What I meant is that: - if reflected on vertical, set y to -y, and x to -x horizontally (x and y being the composite ie ~the projection of the vector on the axis) this will give you the same vector but reflected. - compute the point of where the vector intersect with the surface of the box. - Using the new point compute the truncated vector at point of impact (point of impact coordinate - point of origin of the original vector), then find its length, that you will divide by the length of the original vector to obtain the ratio. - Compute the "inverse" of the ratio (1-ratio) then multiply the reflected vector by it. https://www.youtube.com/user/BSVino/videosWell try that if anything fails
|
|
|
Logged
|
|
|
|
Cheezmeister
|
|
« Reply #287 on: September 27, 2015, 01:10:15 PM » |
|
That makes sense, I think. I guess the stumping part for me is calculating the intersection, given that there's four line SEGMENTS, two points, and nine cells of space they could be located in. Lots of permutations, even for the axis-aligned case. I'll take it one step at a time. Thanks guys!
|
|
|
Logged
|
|
|
|
Halogen
|
|
« Reply #288 on: October 05, 2015, 05:38:36 AM » |
|
How sound is this program semantically? I wrote it this morning, as a warmup. It changes a number from fahrenheit to celcius or vice versa, depending on input.
#Fahrenheit to Celsius Calculator #c-->f = temp*1.8-32 #f-->c = temp-32/1.8
print("Convert C to F or F to C?") print() print("Enter a 1 for C-->F or 2 for F-->C") answer = input()
if answer == "1":
tempA = float(input("Enter your temp")) print() conversion1 = tempA*1.8+32 print(conversion1)
else:
tempB = float(input("Enter your temp")) print() tempC = tempB-32 conversion2 = tempC/1.8 '''broken into steps to prevent use of order of ops in the calculation ''' print(conversion2)
print("Thanks for using!")
|
|
|
Logged
|
|
|
|
Dacke
|
|
« Reply #289 on: October 05, 2015, 09:43:53 AM » |
|
If it works, it's fine, really. Don't worry too much about style, you'll figure it out over time. Getting stuff done is more important. Depending on what you want to do, you may want to do error handling for when the user inputs something incorrect (like letters instead of numbers). I don't think you're "supposed" to use multi-line strings as comments, you can use a # on each row instead. It also works better with comment/un-comment commands in programs. When posting code on the forums, you can use [ code ] blocks, to make the code more readable and keep it's formatting intact. You don't need the empty lines before/after if and else. I think this is more readable: if answer == "1": tempA = float(input("Enter your temp")) ... print(conversion1) else: tempB = float(input("Enter your temp")) ...
|
|
|
Logged
|
programming • free software animal liberation • veganism anarcho-communism • intersectionality • feminism
|
|
|
Halogen
|
|
« Reply #290 on: October 05, 2015, 10:04:06 AM » |
|
Ah, thanks! I couldn't figure out which button would give me the code box. xD I'll be sure to use that in the future. I think I'll implement some type of error handling next for the program. It will probably be a bit since I'm literally on day four of using this language, but I appreciate the direction. I'll pop in those spacing edits now. Thanks again
|
|
|
Logged
|
|
|
|
ProgramGamer
|
|
« Reply #291 on: October 07, 2015, 11:50:53 AM » |
|
Hey, just a little techy curious question here: I decided to set up OpenGL on my computer because I want to be able to use polygons in my games. However, I found out that you can't just #include it into your project and that you actually have to install a library to load it's functions. I'm just curious about the technical reasons for this I guess, so if anyone knows the answer, it'd be great to start a discussion on that!
|
|
|
Logged
|
|
|
|
zleub
|
|
« Reply #292 on: October 07, 2015, 12:35:56 PM » |
|
In C/C++, a library (which is a bunch of symbols) need to be linked after the compilation. The #include is just to expand a file with another, such as 'i need this data-structure here, here and there, let's make a header and include it'. You get some flags to discuss with your compiler, such a -l (lower L) which specify the name of a library you want your executable linked to (such as -lzleub for a libzleub.a). If you need a path, there is a -Lpath. Depending an your build structure (command line or ide), you may have to configure that somewhere. The installation part is because a compiler has default path for standard libs, such as libc and libc++. If you use a library really often, it could become a `standard` library of your environment. compiling_c, compilingandlinking.
|
|
|
Logged
|
|
|
|
ThemsAllTook
|
|
« Reply #293 on: October 07, 2015, 01:00:12 PM » |
|
To put it another way, #include gives you the interface, while linking to the library gives you the implementation. The compiler only needs to know "there's a function called glDrawElements that takes these arguments of these types" in order to generate bytecode from your source file, but that bytecode will be generated with a stub that says "there's a call to a function named glDrawElements here that needs to be hooked up to something to actually do anything". Pointing the linker to libgl.a or whatever lets it hook up the unresolved symbol to the glDrawElements implementation that exists inside the library.
|
|
|
Logged
|
|
|
|
ProgramGamer
|
|
« Reply #294 on: October 07, 2015, 01:20:07 PM » |
|
Yes ok that's how you link a library I already knew that, but I meant to ask why you need a separate library than OpenGL to load it's functions into your program. I'm talking about versions of OpenGL above 1.1 btw if that helps.
|
|
|
Logged
|
|
|
|
JWki
|
|
« Reply #295 on: October 07, 2015, 01:46:26 PM » |
|
If you're referring to something like GLEW or the like, these exist because the Windows implementation of OpenGL is... uhm, let's say not quite up to date, and you have to load every OpenGL function from the graphics driver in order to use them. That's what GLEW does for you.
|
|
|
Logged
|
|
|
|
InfiniteStateMachine
|
|
« Reply #296 on: October 07, 2015, 02:25:02 PM » |
|
Yeah windows is a big jerk about keeping opengl up to date If you are doing a standalone project then you can use something like GLFW which will setup all the extensions/GLEW etc for you. If you are integrating you'll most likely want to use GLEW.
|
|
|
Logged
|
|
|
|
ProgramGamer
|
|
« Reply #297 on: October 07, 2015, 03:39:13 PM » |
|
Alright, also, is OpenGL 1.1 fine if I just want to use basic vectors for effects and stuff? Also, how granular is OpenGL with it's functions, and is there an engine somewhere that makes this whole deal way easier?
|
|
|
Logged
|
|
|
|
InfiniteStateMachine
|
|
« Reply #298 on: October 07, 2015, 03:52:06 PM » |
|
Alright, also, is OpenGL 1.1 fine if I just want to use basic vectors for effects and stuff? Also, how granular is OpenGL with it's functions, and is there an engine somewhere that makes this whole deal way easier?
OpenGL 1.1 is generally fine if you are just drawing shapes etc. If you want shaders and that whole pipeline you have to move up to OGL 3+. If you just want an easier way to get started with openGL then GLFW is good for that but it doesn't simplify opengl it merely sets up a window and context for you so you can start calling opengl stuff without all the setup. An engine would abstract the ogl calls away from you. Once you start using an engine then the underlying renderer isn't so much of an issue as you generally won't be interacting with it directly.
|
|
|
Logged
|
|
|
|
ProgramGamer
|
|
« Reply #299 on: October 07, 2015, 04:29:27 PM » |
|
Alright, and where can I find a good SDL-like documentation for it, if there even is a decent doc for that?
|
|
|
Logged
|
|
|
|
|