• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

3D Are cylindrical or conical projections possible?

TheouAegis

Member
I was going to make this a GMS2 post, even though I can't use GMS2 anymore. Then I was like, in some ways this applies to GMS1's d3d matrices I guess, so I changed it to just a generic 3D post. I think the answer to this post is "no", but if someone wants to wrap their brain around this, I'd be happy to hear their thoughts.

I'm just wondering if there is any way to project a 2D field INTO a 3D cylindrical or conical perspective viewed from outside the circular edge. Consider in this image:

I'd want the projection looking into that hole. Except here's the catch: Instead of x and y being the plane around the outside of that hole and simply considering the hole as being that plane viewed from farther and farther away, I'm curious if there's a way to project that plane as though it were WRAPPED around the inside of that hole and - even better - flared at the edges. I get that, logically, this is somewhat nonsensical. If the plane was wrapped into the hole, like a cylinder, then it wouldn't flare out like this, except that's what I'm aiming for. Well, that's what my curiosity is aiming for. Here me out on this!

So here's the thing. This trippy black hole effect is actually what's going on in the game Gyruss. Shift the camera so you're actually looking down directly into the hole and that is what the player sees in Gyruss. Pick any intersection of two lines in this image and trace it with your finger. Congrats, you just simulated an enemy pattern in Gyruss.

It looks like just a simple linear scaling, but I took a peek at the code. Granted, my math skills are nowhere near what they were when I was in high school, but I extracted the z-depth transformations from the game data and tried to extrapolate a trendline. I quickly realized there was something off about the numbers. I plotted them on a chart and saw it was parabolic. I couldn't figure out a quadratic to fit it and the one Excel came up with seemed... implausible to me. Now, if someone wants to try to figure out the formula for these points (yes, I know they're rounded off, which doesn't help things), here are the z-depth transformations for the enemies:
There are 255 values in order using base 10. A z-depth of 0 corresponds to being in the center of the hole, a z-depth of 255 corresponds to being at the very edge
0
1
1
2
2
2
3
3
4
4
4
5
5
6
6
6
7
7
8
8
8
9
9
10
10
11
11
12
12
12
13
13
14
14
15
15
16
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
30
30
31
31
32
32
33
33
34
34
35
36
36
37
37
38
39
39
40
40
41
42
42
43
43
44
45
45
46
47
47
48
48
49
50
50
51
52
52
53
54
54
55
56
57
57
58
59
59
60
61
62
62
63
64
65
65
66
67
68
68
69
70
71
72
72
73
74
75
76
77
77
78
79
80
81
82
83
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
115
116
117
118
119
120
122
123
124
125
126
128
129
130
131
133
134
135
137
138
139
141
142
143
144
145
148
149
150
152
153
155
156
158
159
161
162
164
166
167
169
170
172
174
175
177
179
181
182
184
186
188
190
191
193
195
197
199
201
203
205
207
209
211
213
215
217
219
222
224
226
228
231
233
235
238
240
242
245
247
250
252
255
Anyway, the way this all ties in with my question is movement in Gyruss is handled just as you'd think looking at the black hole image. Enemies move around a concentric circle and in toward the center of the hole. Their position on screen is determined thus by their z-depth (how close they are to the hole) and their position along any cconcentric circle. This made perfect sense to me at first -- the position around a circle is movement along x and y, while the position toward the hole was along an artificial z. However, delving further into the code, I realized this seemingly made things difficult and blew my mind how the designers even came up with this stuff: path movement is defined by changes in angle around the screen and changes in z, not changes in x and y like a normal path. That's what lead me to my question.

Take a piece of paper and draw a path of any shape you want. That path would be defined by changes in x and y and easily compatible with GM's path assets. Now roll that paper up into a cylinder so that the path is on the inside of the cylinder. Now define that path. See my dilemma? Once you rolled up the paper, x is no longer simply x, it's x based on its direction from the middle of the cylinder, and y is no longer simply y, it's y based on the distance into the cylinder away from the viewer. Thus, is it possible in GMS1 or GMS2 to alter the projection so that x becomes direction, y becomes distance, and up becomes upside-down?
 

curato

Member
I am not sure about the 3D but I know you could do that in 2D fairly easily. (The picture that is)
 

Joe Ellis

Member
" is it possible in GMS1 or GMS2 to alter the projection so that x becomes direction, y becomes distance "
I think, no. Cus something about matrices working in a certain way, and are very linear, which this isn't. Although, if this information is interpretable you can of course make these transformations in the vertex shader based on the input x & y.
I think you might need to actually use 3d matrices for the view & projection though to make this work. Probably cus of how complicated the maths is otherwise, you'd probably have to spend 3 years studying and getting it to work.
Whereas that first picture you showed has been created with a 3d view & projection, and the vertices have simply been transformed, in quite a simple way of increasing\decreasing the radius for each stage\set\ring of vertices. So you can do this with the depth\z. I remember I made the same thing a few years ago when I was learning how to extrude quads from each other. The radius of each new set of vertices was multiplied by about 1.1 so it came out in a trumpet shape like that. So you probably just need to do this based on the depth of the stars and find a good amount to multiply by. Then when the positions are in a curved trumpet shape, you use a certain view & projection matrices to affect the angle they're looked at from. So you just do the transforming of the vertices in the vertex shader before they're multiplied with the view & projection matrices.
It'd be something like:
pos.xy *= pow(floor(pos.z), 1.1);

That's probably wrong, when I was doing it, it was one stage at a time, so you just multiplied whatever radius it was by 1.1, but in the shader you've gotta perform the repetitions in one go, so I think using power is the way to do this :S? But once you've got the real method of doing this, then you should be sorted.
 
Top