Stormworks: Build and Rescue

Stormworks: Build and Rescue

70 个评价
3D Vector Graphics DEMO
3
3
   
奖励
收藏
已收藏
取消收藏
文件大小
发表于
更新日期
188.834 KB
2023 年 12 月 28 日 下午 10:32
2023 年 12 月 28 日 下午 10:42
3 项改动说明 ( 查看 )

订阅以下载
3D Vector Graphics DEMO

在 Kernle Frizzle 的 1 个合集中
Lua, etc.
8 件物品
描述
UPDATE: Improved culling and edge compensation

Ever wanted to play a game inside a game?

This isn't that, but it's not too far off. This is a tech demo for drawing world space coordinate polygons (triangles) onto screens using the nifty LUA block thingies in microcontrollers.

Keep in mind this doesn't work perfectly the order in which the script draws the triangles doesn't fully account for the more massive triangles. Same goes for when the camera gets very close to a triangle point, but isn't facing towards it. It's not fully refined.

No shadows because 1) I don't know where I would start with that other than trying to make my own raytracing and 2) no way in hell that would fit within even twice the character limit.

This LUA will work for every screen size, or at least the ones I've tested. No guarantees you'll be able to tell whats actually going on in most of them though.

If you do want to add your own triangles, follow the instructions below:

Data Layout:
In the array "obj," there are "objects" containing triangles in the format:
{{x=x,y=y,z=z},{x=x,y=y,z=z},{x=x,y=y,z=z},c={r,g,b,a},col=true}
where the first 3 elements containing x y and z correspond to the coordinates of the vertices of a triangle. In this frame of reference, x and z are the horizontal plane and y is the "altitude." c represents the color value for the triangle, and col determines if the triangle has collision. Currently there is only vertical collision, no wall collision so beware.
One element in the array "obj" represents one object, and is therefore made of multiple triangles. A full object might look like this:
{ {{x=0,y=1,z=0.2},{x=1,y=1,z=5},{x=2,y=0.9,z=6},c={5,0,0,255},col=true}, {{x=7,y=2,z=4},{x=3,y=67,z=4},{x=4,y=3,z=1},c={0,5,0,255},col=true} }
This object contains two triangles, one red and one green. If you wanted to add this object to the "obj" array, you would write:
obj[#obj+1]= { {{x=0,y=1,z=0.2},{x=1,y=1,z=5},{x=2,y=0.9,z=6},c={5,0,0,255},col=true}, {{x=7,y=2,z=4},{x=3,y=67,z=4},{x=4,y=3,z=1},c={0,5,0,255},col=true} }

Unfortunately, due to the 4096 character limit, there is only so much you can add before the LUA rejects any more. If you do add your own shapes, I would suggest deleting the subprograms that draw the ones already added as well as the --comments marking where you're meant to add objects. Finding a way to automate the triangle process using for loops or your own subprograms will allow you to draw in more complex shapes, contours and and what else.


If you don't want to deal with that however, just have fun in the somewhat limited space already loaded into the script. It has a very large 2-tiered concrete looking cake for you!


development issues if you can call it that
When small triangles get too close to big triangles, in some cases the draw order gets confused and draws one on top of the other instead of the other way round. When a triangle clips through another triangle, there is no way to draw both without having overlap that doesn't actually exist. When the vertex of a triangle passes behind the camera, the way they're drawn on the screen can't account for it (I have a stopgap fix for it but it's far from perfect and usually bends the lines in odd ways).
For the last two, I could possibly try to detect when this kind of thing happens and cut a triangle that's either clipping or passing off the screen into multiple smaller triangles. This would in theory work, but optimizing it would be at a level I can't really do at the moment.
I tried abandoning drawn triangles entirely, instead doing a kind of a raster scan over the simulated 3D scene logging order and color values of the triangles that show up in each pixel, then using those values to draw an individual rectangle for every pixel on the screen. This in theory should fix every problem I have, but unfortunately the amount of checks and cycling through arrays makes it practically impossible to implement. Even on a 1x1 screen, 32x32 pixels, the max execution time (an entire second) is exceeded when more than 20 or so triangles are simulated.

TL;DR I would love to make doom in this but I have no ♥♥♥♥♥♥ clue what I could do to make it work
82 条留言
ACE 7 月 6 日 上午 5:18 
HMD verision?
NoNameIdk1 2024 年 9 月 1 日 下午 12:36 
Troagv, im pretty sure that would take more lines than we have in all of lua.
Kernle Frizzle  [作者] 2024 年 8 月 4 日 下午 6:48 
does this mean stormworks is turing-complete
Ication 2024 年 8 月 4 日 下午 6:30 
i swear we are going to be able to play stormworks in stormworks
Troagv 2024 年 5 月 18 日 上午 6:33 
pls pls make a raymarching renderer that would be amazing
Potato Enthusiast 2024 年 3 月 24 日 下午 7:43 
working on stormworks in stormworks :KOh:
habanero7715 2024 年 3 月 18 日 下午 5:08 
DOOM.
Kernle Frizzle  [作者] 2024 年 3 月 16 日 下午 2:41 
gotem
Kernle Frizzle  [作者] 2024 年 3 月 16 日 下午 2:41 
when ur mother
metro893 2024 年 3 月 16 日 上午 11:39 
when doom?