I think this is probably how they approximated bouncing in analog computer games from the ancient times like Tennis for Two.
@TheArtofCodeIsCool2 жыл бұрын
If you can keep a state (store values between frames) then you can do bounces with simple multiplies and adds, so I would expect that almost all bounces are implemented like that.
@Shamysoza922 жыл бұрын
Man! Using desmos for explaining math concepts totally blew it out of the water. These are the sort of things that are not seen everywhere. Totally love your content.
@TheArtofCodeIsCool2 жыл бұрын
Yeah Desmos is a great tool for that. :)
@realcygnus2 жыл бұрын
ALL such things are absolute staples imo & you're quite good at them & just as good at explaining them clearly. Priceless content, as always. 👍 Its mostly math that separates the script kiddies from the Sr. software engineers. I'm really digging this "series".
@GrinyaPLAY2 жыл бұрын
Thank you! Waiting for splines!
@kappasphere2 жыл бұрын
I can't really test right now because I'm on mobile, but iirc Desmos does subscript using underscore. (So just what you would type in latex) As an example, log base 2 of x would be "log_2(x)"
@TheArtofCodeIsCool2 жыл бұрын
Works! Thank you :)
@blaxxun752 жыл бұрын
I love the videos. The name of the channel nails it. I would be very interested in 2 things since i would love to create VR environments and apply the knowledge to something practical. How to get a dynamic shader onto a skybox without distortions in Unity (For example the starfield shader)? How to render raymarched "geometry" for VR in Unity? I know you showed something similar on a cube with a raymarched torus but not in a whole VR scene. That would be awesome to gather some insights and starting points on this 2 topics
@TheArtofCodeIsCool2 жыл бұрын
Noted!
@blaxxun752 жыл бұрын
@@TheArtofCodeIsCool Hi Martijn, thats great! Thank you! Cant wait!
@marcelliino2 жыл бұрын
Great video as always! Detailed explanation and straight forward.
@metalmastery54602 жыл бұрын
Cool video, thanks! The bonus time somehow reminded me of an attempt to implement accelerated turning of a spaceship. PID controller oversteered badly and was wiggling the nose of the ship like that all the way to the target point. Ideas and topics: celtic patterns (personal kink, yeah), reaction diffusion, cellular automata and practical application beyond the game of life, raymarching in 2D (generation of distance field for non-sdf objects is a mess), height field in 2D and generated normals (or even shadows?), parallax mapping, particles with attractors, celtic patterns again
@TheArtofCodeIsCool2 жыл бұрын
Keltic Patterns eh? I could get into that ;)
@GrinyaPLAY2 жыл бұрын
Thank you! Can you explain more useful math optimisations for coders as you presented in this video for reducing loops with plain math function!
@CompositeNation2 жыл бұрын
Thank you very much! I love to understand how I could use other functions!
@SellusionStar2 жыл бұрын
would be interesting to do this with trigonometric functions. something like abs(cos(x)) * 0.8^(floor((x-π/2)/π)+1) where 0.8 is an arbitrary damping factor.
@TheArtofCodeIsCool2 жыл бұрын
That would look a look like a bounce but since its not based on a parabola, the ball will not accelerate all the way to the ground and will therefore look 'off'. I suggest you try it.
@SellusionStar2 жыл бұрын
@@TheArtofCodeIsCool Good point... btw I love your videos! all of them :)
@tidatida41452 жыл бұрын
The abs(cos(x) has it's mayor weekness when it comes to resolution and calculation. The calculation of the inflection point is not precise enough, that it results to exactly "0". Hence you will always receive an unpredictable drifting at the turning point. This method ist very fast and robust when it comes to this issue...
@66nos2 жыл бұрын
That's a great video. I love to see how we can use the math that we learnt in school, even tho I've probably forgot most of it. I didn't try it myself yet, but I think the two functions did the opposite of what were supposed to do because the variable i (the integer part of the number) had negative values, so it could have worked as intended if we did i = abs(i).
@djmips2 жыл бұрын
Not this method is only needed if you want to do a pure function / analytical bounce as a function of time. If you don't have that requirement, ie not a shader or can at least keep state around from a previous frame, you can use some simple code that needs nothing more than adds / subtracts and a compare. It will give you a nice looking bounce.
@djmips2 жыл бұрын
My code looks something like this (400 x 400 screen) . The gravity constant is dn which I initialized to 0.16. xs is initialized to some constant horizontal speed and the rest can be initialized to some other reasonable position on the screen and initial state. bx = bx + xs; if (bx < 90){ bx = bx - xs; xs = -xs; } if (bx > 310){ bx =bx - xs; xs = -xs; } by = by + n; n = n + dn; if (by > 310 ){ n = n - dn; n = - n; }
@djmips2 жыл бұрын
To make it bounce with a decay do this. if (n >= 0 && y > 310 ){ n = n - dn; n = - n*0.95; }
@GuilhermeOliveira-kr8vw2 жыл бұрын
Nice video. I have a question related to performance. Does OpenGL (or the GPU really) have hardware implementations for log, pow, exp and so on? From my experience with C/C++, these functions are implemented by using for-loops with methods that accelerate convergence of their series expansions. In order words, you might have potentially exchanged a single small for-loop by several bigger for-loops.
@TheArtofCodeIsCool2 жыл бұрын
Its a great question. My understanding is that on modern hardware this functions are all built in and very fast, on the order of a couple of clock cycles. The slowest operations are the inverse trig functions and texture fetches.
@LeutnantJoker2 жыл бұрын
Undoing the distortion was interesting. That's the difference between school math and applied math. You need to play around with the function to really understand their use.
@TheArtofCodeIsCool2 жыл бұрын
Yes, playing is crucial!
@themrpancake2 жыл бұрын
Really useful. Thanks again sir!
@lukasgehtdichgarnichtsan79062 жыл бұрын
Awesome video!
@andrey7302 жыл бұрын
Very interesting - I haven't developed intuition for logarithm function even though I can describe it and draw it But wasn't it possible to make the easing with exponential function like fract(x^n) instead of logarithm? It has the same property of getting it's period less and less with x growing. Why use logarithms then? I'm curious if there's logarithm unique uses that can't be done with expontial functions?
@TheArtofCodeIsCool2 жыл бұрын
The exponential function and log function are two sides to the same coin, so I wouldn't be surprised if this could be implemented with that. I chose the log because it has an asymptote at 0, which I can use to fade the bounce to zero when t=1. I'd be interested to see other solutions though!
@NikolaNevenov862 жыл бұрын
just awesome
@yankeshi59832 жыл бұрын
nice tutorial, and why x -= (1.-pow(base,.5))/(1. -1./base) let the function offset to the middle? I found when r to the large number, it will not to the middle.and I use x -= log(1.-(1.-base)/2.)/log(base).
@TheArtofCodeIsCool2 жыл бұрын
When I suspected the same solution as the one for undoing the distortion and plugged it in, it look right so I didn't think about it further. Good catch!
@yankeshi59832 жыл бұрын
@@TheArtofCodeIsCool love your tutorial let me have a deeper graphical understanding of functions by using desmos.
@gower19732 жыл бұрын
Why does the path traced out by the ball look sharp where it meets the x axis but blurs out as it reaches the apex and the effect seems to get worse as you go to the right, is it something to do with the aspect ratio or something else?
@KaedennYT2 жыл бұрын
Press underscore (shift-hyphen) to subscript. This works exactly like caret (shift-6 on my keyboard).
@markuss.60942 жыл бұрын
26:00 this could be used for e.g. a rope that is being stiffened by the character pulling it!
@TheArtofCodeIsCool2 жыл бұрын
Yes!
@w.mcnamara2 жыл бұрын
Incredible as always! Could you consider posting your videos to Odysee? I use that platform a lot and it would be great to watch your vids on there!
@TheArtofCodeIsCool2 жыл бұрын
Voila! odysee.com/@TheArtOfCode:b
@w.mcnamara2 жыл бұрын
@@TheArtofCodeIsCool incredible!! Thank you so much!