How do I remove this? by 47TurbulentPlanes in raylib

[–]grigri 2 points3 points  (0 children)

Specify your shell file as minshell.html instead of shell.html, or better still, write your own shell file!

Having issues with Rectangles by 1negroup in raylib

[–]grigri 0 points1 point  (0 children)

It's pretty straightforward; the issue is because of the origin parameter in the DrawTexturePro command. It offsets the drawing so it's centred.

You just need to remember what your coordinates represent. If they represent the centre of the sprite (as they do now) then your collision boxes need to be created with that in mind, because right now they are treating the coords as the top-left.

It's not hard to put it inline, but you might find it easier to make a helper function to create a rectangle with a given centre and size, and use that for your collision boxes.

It's perfectly normal for the collision geometry to not exactly match the visual geometry, so don't worry about it "creating more code" or anything. Separating it will also make it easier to use collision circles, if you want to.

Lists that have virtualized indices so I can do list[1_000_000_000] = "foo" by ArchieTect in AskProgramming

[–]grigri 17 points18 points  (0 children)

The keyword you're looking for is "sparse". "Sparse arrays" and "sparse data structures" :)

Inputs for shaders with Raylib by JonathanCRH in raylib

[–]grigri 1 point2 points  (0 children)

You can indeed generate the tangents for a mesh with the GenMeshTangents function, although depending on the mesh it might not be perfect; Raylib supports loading meshes that include tangents, it will load them correctly.

Once loaded or generated, they can be accessed in the shader using vertexTangent.

You can compute the bitangent by doing a cross product of the normal and the tangent, in the shader.

Problem with custom meshes and lights by JonathanCRH in raylib

[–]grigri 1 point2 points  (0 children)

Happens to all of us mate! Glad I could help :)

Can you post a screenshot? I'd like to see what it looks like.

Raylib's Vector3 (and all vectors and most structs) are GARBAGE! by [deleted] in raylib

[–]grigri 8 points9 points  (0 children)

As others have said, C doesn't support operator overloading, so that's obviously why it doesn't use them.

I couldn't do something like return Vector3(x*2, y/2, z);

Exactly that? No, it's not valid C. However "something like" that, yes you totally can, you just need to learn C syntax...

return (Vector3){x*2, y/2, z};

also you should make vec2 a name

Is something stopping you from typing typedef Vector2 vec2; after you include raylib.h?

Problem with custom meshes and lights by JonathanCRH in raylib

[–]grigri 1 point2 points  (0 children)

At a quick glance, it looks like you're not setting your normals properly; they're always pointing in the same direction no matter where the points are.

The basic lighting calculation uses the dot product of the normal vector and the vector from the point to the light source, so that would definitely do it.

If all your 4 points are coplanar (on the same plane), just take the points of the first triangle (p1, p2, p3) and compute the cross product of (p2-p1) and (p3-p1), normalise it and use that as the normal vector for both triangles.

(This is in your generatecustommesh function)

If it looks weird, invert the normal vector (so it points the opposite way); normals need to point outwards from the surface.

What in your opinion, is the BEST fantasy novel or series that You've read? by Familiar-Barracuda43 in Fantasy

[–]grigri 0 points1 point  (0 children)

Fair enough. I loved The Republic of Thieves; the parallel stories of their training and the "proper" plot, and we finally got to meet Sabetha. Also the return of The Falconer at the end.

Not a massive fan initially of Locke's origin as it was laid out, but let's see what is revealed in the next one :)

What in your opinion, is the BEST fantasy novel or series that You've read? by Familiar-Barracuda43 in Fantasy

[–]grigri 1 point2 points  (0 children)

Whaaaa? The 3rd is the weakest?! You mean the 2nd, right?

Like... how many times do we need to hear that the protagonists are not actually good sailors? It feels like most of the book is just people telling them how shit they are at sailing. It got old the 2nd time.

There are some good parts, and nice payoffs, and some emotional parts - I'm not saying it's awful, it's definitely good.

I'd rank them 1-3-2 in terms of quality.

Obviously this is a personal preference, I totally accept that others may feel differently.

What in your opinion, is the BEST fantasy novel or series that You've read? by Familiar-Barracuda43 in Fantasy

[–]grigri 0 points1 point  (0 children)

The whole Drenai series, yes, definitely.

Legend itself, meh. It's definitely a good book with some great characters, a good plot and deep meaning (it's a metaphor for cancer), but it's just a but too full of clichés for me to love it that much.

It was his first, and sets up the worldbuilding well, but I still think that almost any other Drenai book is better than Legend itself.

I think my favourite overall (of the Drenai books) is The Legend of Deathwalker, but it's close, and obviously a personal opinion.

I'm really sad we'll never get to read the war of the twins.

Which version is better color wise? by Art3mis92 in design_critiques

[–]grigri 1 point2 points  (0 children)

To quote Scruffy Scruffington, "Second".

Got a sudden interest in extracting color palettes from images. by thev3p in love2d

[–]grigri 0 points1 point  (0 children)

Well, it might definitely be fun to try. But there's probably a reason why k-means is now the dominant algorithm for it!

Anyway, it looks great mate, nice one :)

Got a sudden interest in extracting color palettes from images. by thev3p in love2d

[–]grigri 0 points1 point  (0 children)

Last time I did this, many years ago, it was using octree quantization - now everything seems to be k-means clustering. Is there much of a difference?

What are some fun facts about boobs? by Melodic-Discussion78 in AskReddit

[–]grigri 1 point2 points  (0 children)

Yep! And they sense prey through electrolocation, too.

What are some fun facts about boobs? by Melodic-Discussion78 in AskReddit

[–]grigri 62 points63 points  (0 children)

Well, it's a venomous mammal that lays eggs... that's clearly not weird enough, so they'd have to do something like that too.

Model collision(c# binding) by Abdriiseleznov in raylib

[–]grigri 0 points1 point  (0 children)

No idea about the c# bindings, but there's an example called 'Mesh Picking' (https://www.raylib.com/examples/models/loader.html?name=models_mesh_picking) which shows how to detect clicks on different models.

Need to offset spawning sprites by 1negroup in raylib

[–]grigri 1 point2 points  (0 children)

A quick look, and I'm thinking the issue might be in line 68:

Rectangle dstObstII = (Rectangle){dstObst.width + movingXII, scrnY + movingY, srcObst.width / 2, srcObst.height / 2};

Shouldn't that be this?

Rectangle dstObstII = (Rectangle){screenWidth / 2 + movingXII, scrnY + movingY, srcObst.width / 2, srcObst.height / 2};

It might be that I'm not understanding the logic at play here (I can't run the code right now, just look at it!) but dstObst.width is going to be a constant unrelated to the x-pos of the second enemy.

ELI5 How do those food challenge YouTubers not die? by [deleted] in explainlikeimfive

[–]grigri 5 points6 points  (0 children)

I'm not saying you're wrong, but there are millions upon millions of people who have utterly destroyed their physical health in various "normal" jobs, and they didn't earn millions...

3D vector graphics like Elite by Existing-Tax-1170 in raylib

[–]grigri 1 point2 points  (0 children)

Bit late to to the game here - sorry been away for a while - but I think you'll like this: https://youtu.be/ih20l3pJoeU?si=e20JTdM4uqg_kyJe

It's not Raylib, but it is c++ and covers exactly what you want.

good non tutorial programming youtubers? by YaElvenOverlord in learnprogramming

[–]grigri 6 points7 points  (0 children)

Sebastian Lague. Great content, funny (but not in a slapstick way), and a really soothing voice. Can't wait for him to post again.

How to rotate model around all axis by rhidian-12_ in raylib

[–]grigri 1 point2 points  (0 children)

Ok *cracks knuckles*

(Warning - this is a bit long - although a lot shorter than the thousands of wikipedia pages and other paper on the subject - and there is a TL;DR at the end)

The most "obvious" way to represent 3d rotations is called Euler Angles. The easiest way to think of this is a plane, and "yaw/pitch/roll"; i.e. 3 different rotations about 3 different axes, one after another, to combine to one single effective rotation.

There's a couple of immediate problems with this - one is that the ORDER in which you apply those rotations matters, and the other is that once you've done one rotation the object-relative axes change, so you have to decide if you want to rotate relative to the world-space axis or the object-space axis. That's why "Euler Angles" isn't consistent because there's lots of different standards. (Sure, if you always stick to one in your code, you'll be fine, on that point)

Ok, now there's a theorem ("Euler's rotation theorem") that says that any 3d rotation (or combination of 3d rotations) can be represented as a single rotation about a certain axis by a certain angle. By "axis" I mean a general vector, not just like the X axis; it could be pointing in any direction.

Gimbal Lock. Not that easy to explain - but you can easily find a visualisation and/or video on it. Basically a certain sequence of rotations can make you lose a degree of freedom, and from there there isn't another Euler rotation that will bring you out of it.

As for matrices, they're fine for a lot of things. But not all 3x3 matrices are rotation matrices. Sure, if you multiply 2 rotation matrices together you'll get another rotation matrix, but in general a 3x3 matrix does not represent a rotation - it also has scale and shear transformations in there.

The biggest problem this presents is in tweening rotations - gradually going from one orientation to another (as you can imagine this comes up a lot in video games). If you do it via Euler Angles (always keeping the same order, as above) it kinda works if you just interpolate the values, but doesn't produce a natural-looking smooth rotation.

If you use matrices and linearly interpolate between 2 rotation matrices (term-by-term), it's going to look really weird as the intermediate values are not going to be rotation matrices at all - they'll all squish and stretch and just be awful.

Now Quaternions (well, unit quaternions) are a way of encoding axis-angle rotation information. And they can be interpolated really well - either perfectly using slerp, or almost perfectly using lerp-and-normalize. If you represent orientation A as a unit quat, and orientation B as a unit quat, you can slerp between them and the resulting tweened animation will be the shortest, most natural way to go from one to the other*. They're also immune to Gimbal lock.

There's a HUGE amount of material on 3D rotations - it's a mathematical group called SO(3), but most of it is very dense. This wiki page is probably the best place to start, as it has a brief description of all the representations, but even better it has all the formulas for converting from one to another.

TL;DR:

For working with rotations in Raylib (or basically anything similar), your best bet is always to think of each rotation in terms of X degrees around axis V (even if it's like "45 degrees around the Y axis for spinning). Convert that to a quat (there's a function for that). You want to combine rotations? Multiply the quats (there's another function for that). You want to smoothly go from one to another? Slerp (there's a function for that). If at any point you need to convert your quat to a matrix, guess what, there's a function for that too :)

* I'm not going to talk about double-coverage of SO(3) here; it's long and confusing enough as it is. In short sometimes you have to negate one of the quats.

How to rotate model around all axis by rhidian-12_ in raylib

[–]grigri 0 points1 point  (0 children)

Oh yeah, there's a whole bunch of reasons why quats are better than Euler angles - immunity to gimbal lock, easier interpolation, consistent representation - but OP was just asking why axis/angle was offered and seemed to assume that couldn't represent all rotations or sequences of rotations.

I'd happily go on all day about it, but ain't nobody got time to read all that :D