Mathy questionaire

in simple terms this is basically

i, incrementing value from 30 for each cube
constant, some vector3
xyz = constant + vec3(cos(i) * i, sin(i) * i, i)

the actual code is

for (int i=0; i<30; i++) {
            mainShader.setUniformMat4("viewMatrix", glm::value_ptr(viewMatrix));
            mainShader.setUniformMat4("perspectiveMatrix", glm::value_ptr(perspectiveMatrix));
            glm::mat4 modelMatrix = glm::mat4(1.0f);
            modelMatrix = glm::translate(modelMatrix, cubePos + glm::vec3(cos(i) * i, sin(i) * i, i)); 
            mainShader.setUniformMat4("modelMatrix", glm::value_ptr(modelMatrix));
        glBindVertexArray(cubeVAO);
        glDrawArrays(GL_TRIANGLES, 0, 36);
}

as you can see thats not really what i want, its a spiral. how can i make them generate in like a sphere ish pattern around the constant vector3?

1 Like

didn’t know you can use C++ type of loop, sadly I can’t help cause I suck at math rofl, wait is that roblox

3 Likes

If you multiply i within your trigonometric functions by a fraction of math.pi, you can slow down the spiral into something a bit more recognizable.

To truly achieve the effect, though, you’ll probably want something that generates parts that are equidistant from each other, since they will space out as the radius increases in this current model. I will try and come up with something and get back to you.

UPDATE: I tried to do this in psuedo code

position = constant + (vec3(x,y,z) - light).Unit * 3

but we are missing some…


any ideas on making them equidistant?

I guess before I get too far into it, let me clarify what you’re looking for:

You want a spiral that originates in one point, spirals around a sphere, and then subsequently comes back together on the other side, yes? Something sorta like these marbles?

No i just want some cubes floating around in a spherish pattern. the idea is to make them all equidistant that way i can just move them closer or farther to the origin based on some random value

In order to make the points equidistant, you’ll need to define their radius from the origin in each step, compare that to a constant desired arc length, and that will give you your angle for that particular step. I think everything will stay copasetic in regards to your growing distance from the origin along the normal vector, but it could come out compressed instead of expanding like it did in the first model.

If you want to customize it, though, you’ll need to define some parameters like width and depth that lerp over the duration of the loop.