Earlier quoted context omitted.
No I really mean low level :-) Javascript is high level, but here notch is using it as a low level framebuffer.
> And indeed it is pretty impressive how fast the rendering happens given that the code operates at such lower level. Sorry if this is a stupid question, but wouldn't you normally expect low level code, whilst more time consuming to write, be faster or just as fast as higher level code. For example, how C is used as a standard for fast code since it's so low level.
Notch trying jsFiddle
31–40 of 143 posts
Re: Notch trying jsFiddle
#32Earlier quoted context omitted.
No I really mean low level :-) Javascript is high level, but here notch is using it as a low level framebuffer.
> And indeed it is pretty impressive how fast the rendering happens given that the code operates at such lower level. Sorry if this is a stupid question, but wouldn't you normally expect low level code, whilst more time consuming to write, be faster or just as fast as higher level code. For example, how C is used as a standard for fast code since it's so low level.
However if you use this approach in Javascript you get poor performances unfortunately. And indeed this demo requires fast computers to do what otherwise could be done in C with direct access to the video frame buffer with maybe 50 times slower computers.
Even C coders almost no longer try to do this low level things and let the graphic chip do a lot of the work when the goal is to produce a game.
So in Javascript instead you want to usually call a library that implements a 3D engine in a lower level language like C and with more direct hardware access.
But in this case, it makes sense to do all this in a low level way and in Javascript: it is just a demo that is full of interesting code and with an appealing visual output.
Re: Notch trying jsFiddle
#33 setInterval(clock, 1000 / 100);
Is there any reason for writing 1000/100 instead of 10?edit: Thanks guys!
Re: Notch trying jsFiddle
#34Re: Notch trying jsFiddle
#35Can anyone explain how this works? I never have got to grips with 3D.
Re: Notch trying jsFiddle
#36Can someone dissect this code and explain what it does?
The next set of three nested loops is generating a random "world" with a tunnel cut out of it.
The renderMinecraft function is performing a minimal perspective projection http://en.wikipedia.org/wiki/3D_projection for a single ray cast into the world. Each pixel is cast and then, for each object hit by the ray cast, the closest is found, and a texture mapped pixel is calculated and written into the frame buffer.
Re: Notch trying jsFiddle
#37setInterval(clock, 1000 / 100); Is there any reason for writing 1000/100 instead of 10? edit: Thanks guys!
Re: Notch trying jsFiddle
#38setInterval(clock, 1000 / 100); Is there any reason for writing 1000/100 instead of 10? edit: Thanks guys!
The usefulness is more obvious when you want 60FPS, which is not easily represented without rounding.
Re: Notch trying jsFiddle
#39setInterval(clock, 1000 / 100); Is there any reason for writing 1000/100 instead of 10? edit: Thanks guys!
Similarly, people will write (10 * 60 * 60) if the value is seconds and the programmer intends to indicate 10 hours.
Re: Notch trying jsFiddle
#40Can anyone explain how this works? I never have got to grips with 3D.
It looks like he's using a matrix to create cartesian coordinates in a model-view space and then performing some basic linear algebra on the points to animate it. For a primer on 3D worlds check out http://learningwebgl.com/blog/?page_id=1217 where they go over it using WebGL.