Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: Chockosta on July 11, 2011, 12:00:35 pm

Title: [Lua] RayCaster
Post by: Chockosta on July 11, 2011, 12:00:35 pm
Hello guys !

With the OS 3, we had no mean to have 3D games on our calcs. This was a shame, because it's really funny when people are amazed by on-calc 3D stuff. (Actually, there is already Make3D by Levak)
But now, the first raycaster engine in Lua is released !
It's only a demo, you can move in a small 3D world in greyscale (I'll add colors).
Since Lua is interpreted, it's not really fast. So it's not very good-looking, because I cast one ray for two-pixels-wide columns...
Unfortunately, textures are impossible (it would become too much slow)

I plan to do a 3D game with this little engine... But nDoom will stay really really better than it.
(I attach the released demo and two screenies. Enjoy !)
Title: Re: [Lua] RayCaster
Post by: pianoman on July 11, 2011, 12:02:25 pm
Wow! Looks great!
What exactly is a raycaster? :P
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 11, 2011, 12:08:51 pm
pianoman I believe that it is a program that lets you draw 3d things like walls, trees and basically anything else. It calculates where the lines should go to. This is just my guess
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 11, 2011, 12:11:31 pm
Yep.

A raycaster is a tiny 3D engine which allows only perpendicular walls.
Title: Re: [Lua] RayCaster
Post by: p2 on July 11, 2011, 12:11:59 pm
WOW!!!  :o  :o
Title: Re: [Lua] RayCaster
Post by: Ashbad on July 11, 2011, 12:16:44 pm
pianoman I believe that it is a program that lets you draw 3d things like walls, trees and basically anything else. It calculates where the lines should go to. This is just my guess

Well, no actually :) a ray caster is basically projecting a 3D version of a 2D map based on your position, where some data will be walls and render as so, and everything else will be empty.  However, you can add non-raycasted objects in there as well like what Doom does using other techniques.

On a side note, nice job :)
Title: Re: [Lua] RayCaster
Post by: p2 on July 11, 2011, 12:18:51 pm
Why don't you make a game of it?
So that you'll have to walk around in this labyrinth and that you'll have to do things. (fight against monsters, Find things, ...)
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 11, 2011, 12:20:52 pm
I plan to do that.
But I need some time :) I'll post here when I will have something decent.
Title: Re: [Lua] RayCaster
Post by: Munchor on July 11, 2011, 12:42:39 pm
That looks very nice. I can't see any real game being made with this because it's very slow, afterall it's Lua, here's an animated screenshot I made for you:

(http://img.removedfromgame.com/imgs/LUARayCaster.gif)

Nevertheless, it looks good
Title: Re: [Lua] RayCaster
Post by: pianoman on July 11, 2011, 12:44:51 pm
Oh, I get it.
Is there any chance you can upload the code for this?
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 11, 2011, 12:49:01 pm
Sure... But it's not very good-looking :
Code: [Select]
function racine(a)
x=1
y=0.5*(1+a)
while math.abs(y-x)>0.001 do
x=y
y=0.5*(x+a/x)
end
return y
end

function renderMap(gc,map,w,h,camera)
for x=0,w,2 do
dirX=math.cos(camera[3])
dirY=math.sin(camera[3])
planeX=math.cos(camera[3]-1.5707963267949)
planeY=math.sin(camera[3]-1.5707963267949)
cameraX=(x*2/w)-1
rayPosX=camera[1]
rayPosY=camera[2]
rayDirX=dirX+planeX*cameraX
rayDirY=dirY+planeY*cameraX
mapX=math.floor(rayPosX)
mapY=math.floor(rayPosY)
deltaDistX=racine(1+(rayDirY*rayDirY)/(rayDirX*rayDirX))
deltaDistY=racine(1+(rayDirX*rayDirX)/(rayDirY*rayDirY))
hit=0
if rayDirX<0 then
stepX=-1
sideDistX=(rayPosX-mapX)*deltaDistX
else
stepX = 1;
sideDistX = (mapX+1-rayPosX)*deltaDistX
end
if rayDirY<0 then
stepY=-1;
sideDistY=(rayPosY-mapY)*deltaDistY
else
stepY=1;
sideDistY=(mapY+1-rayPosY)*deltaDistY
end

while hit==0 do
if sideDistX<sideDistY then
sideDistX=sideDistX+deltaDistX
mapX=mapX+stepX
side=0
else
sideDistY=sideDistY+deltaDistY
mapY=mapY+stepY
side=1
end

if map[mapX][mapY]>0 then
hit=1
end
end
if side==0 then
perpWallDist=math.abs((mapX-rayPosX+(1-stepX)/2)/rayDirX)
else
perpWallDist=math.abs((mapY-rayPosY+(1-stepY)/2)/rayDirY)
end
hauteurLigne=math.abs(math.floor(h/perpWallDist))
drawStart=math.floor(-hauteurLigne/2+h/2)
drawEnd=math.floor(hauteurLigne/2+h/2)
if drawStart<0 then
drawStart=0
end
if drawEnd>=h then
drawEnd=h-1
end

gc:setColorRGB(10,10,10)
if side==1 then
gc:setColorRGB(100,100,100)
end
gc:fillRect(x,drawStart,2,drawEnd-drawStart)
end
end



function on.escapeKey()
menu=1
platform.window:invalidate()
end
on.escapeKey()

function on.enterKey()
menu=nil
fovy=60
camera={10,10,0.05}
w=320 h=240
planeX=0 planeY=1
map={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1},{1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,1},{1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1},{1,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1},{1,1,1,1,1,1,1,0,0,1,0,0,1,0,0,1},{1,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1},{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1},{1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},{1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},{1,0,0,1,1,1,0,0,1,1,1,1,1,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}}
platform.window:invalidate()
end

function on.arrowKey(ar)
turn=nil
if ar=="right" then
camera[3]=camera[3]-0.1
end
if ar=="left" then
camera[3]=camera[3]+0.1
end
if ar=="up" then
if map[math.floor(camera[1]+math.cos(camera[3])/3)][math.floor(camera[2]+math.sin(camera[3])/3)]==0 then
camera[1]=camera[1]+math.cos(camera[3])/3
camera[2]=camera[2]+math.sin(camera[3])/3
end
end
if ar=="down" then
if map[math.floor(camera[1]-math.cos(camera[3])/4)][math.floor(camera[2]-math.sin(camera[3])/4)]==0 then
camera[1]=camera[1]-math.cos(camera[3])/4
camera[2]=camera[2]-math.sin(camera[3])/4
end

end
platform.window:invalidate()
end



function on.paint(gc)
if menu then
gc:setColorRGB(0,0,255)
gc:setFont("sansserif","r",30)
gc:drawString("RayCaster Demo",30,0,"top")
gc:setFont("serif","b",10)
gc:drawString("Press Enter to start",100,100,"top")
else
gc:setColorRGB(200,200,200)
gc:fillRect(0,0,platform.window:width(),platform.window:height())
renderMap(gc,map,platform.window:width(),platform.window:height(),camera)
end
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","r",8)
gc:drawString("Lua RayCaster Demo - Par Loic Pujet",10,200,"top")
end
Title: Re: [Lua] RayCaster
Post by: ztrumpet on July 11, 2011, 12:58:00 pm
That's very cool.  Great job, Chockosta.  It's a very nice attempt at pushing Lua's limits.
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 11, 2011, 12:58:40 pm
whats the framerate right now?
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 11, 2011, 01:01:28 pm
Well, the framerate is key input framerate. I don't know exacty it. between 2 and 3 fps on my calc

EDIT : or maybe more, I really don't know :)
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 11, 2011, 01:20:05 pm
It shouldn't be too hard to calculate the framerate if you have a timer you can use. Also, on a calc, the framerate does not need to be very high, as the LCD has a very slow response time, so a high framerate would look like a blur.
Title: Re: [Lua] RayCaster
Post by: p2 on July 11, 2011, 01:29:17 pm
Spoiler For Spoiler:
And now please try to make this in the high quuality like EPIC CITHADEL
If you'll be able to make that, You'll be really very good.

What's about windows in the walls, or doors?
Title: Re: [Lua] RayCaster
Post by: Jim Bauwens on July 11, 2011, 01:34:19 pm
This is real nice, good job Chockosta!
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 11, 2011, 01:40:11 pm
This is real nice, good job Chockosta!
Nope...
This is aMAZE-ing
not funny ?
EDIT: I answer myself: no.
Anyway, awesome.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 11, 2011, 02:53:48 pm
I think you should go ahead and make a 3d maze game out of this. It would be much more conveient to control than the one in TI-BASIC.
Title: Re: [Lua] RayCaster
Post by: Darl181 on July 11, 2011, 11:30:01 pm
For things like windows, you might be able to get away with just putting in a different texture..
Doors could all be "locked", as in they're not actual doors but textures as well :P
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 11, 2011, 11:50:48 pm
If you want the engine to run at 1fps, then textures for doors and windows would work. (not to mention textures would take up a huge amount of space due to the fact lua only uses double floats) Lua is impractical for making something like this, so hats off to Chockosta for pushing the limits of Lua the way it is right now.
Title: Re: [Lua] RayCaster
Post by: Darl181 on July 12, 2011, 12:22:15 am
So solid walls it is :P
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 12, 2011, 01:54:34 pm
Unfortunately, I only can draw plain walls, like Toxic_Kitten said.
But i could add "non-3D" sprites (like in Doom).
Unfortunately, image drawing sucks. I look for a way to add sprites...

And thanks to everybody for your comments !

EDIT : I've added some colors. I will look better on the CX :)
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 09:23:25 am
looks great!



What's about a little map, to see, where you are (Shown while pressing special key)

So would windows be possible?



to Chockosta:
In your sign is no RayCaster. It's missing.
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 13, 2011, 09:32:46 am
What's about a little map, to see, where you are (Shown while pressing special key)

So would windows be possible?
I thought this was supposed to be a maze game. I think that would be better without the map personally
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 13, 2011, 09:36:34 am
Of course, if it is a maze, the map must not be shown. But if it becomes a FPS or a GTA, the map is a good idea.
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 13, 2011, 09:51:03 am
Of course, if it is a maze, the map must not be shown. But if it becomes a FPS or a GTA, the map is a good idea.
That would be a good idea
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 13, 2011, 10:01:31 am
A map is really easy to add. Good idea :)
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 13, 2011, 10:07:11 am
(
Of course, if it is a maze, the map must not be shown. But if it becomes a FPS or a GTA, the map is a good idea.
That would be a good idea
This is not my idea, give credits and +1s to p2.
)
And don't forget to display where in the map you are ;D
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 10:08:16 am
thanx.

But would it be possible to add windows into the walls?
And what sort of game would you make of it?
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 13, 2011, 10:09:09 am
would it be possible to add windows into the walls?
Unfortunately, I only can draw plain walls, like Toxic_Kitten said.
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 10:10:57 am
sorry, haven't seen this.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 13, 2011, 10:36:38 am
For the sort of game, I wish I could do a FPS... I will try to optimize it.
But I think I will only can do a maze game.
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 10:38:20 am
what means FPS?
I only know FPA (FancyPantsAdventure)
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 13, 2011, 10:44:23 am
FPS is a First Person Shooter
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 10:49:02 am
Wouldn't be a PortalToTheFlash be possible, too?
I think it would be great in a 3D-map.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 13, 2011, 11:26:06 am
The little map is done ! you can activate/deactivate it by pressing "m".

Er... What is PortalToTheFlash ?
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 11:28:23 am
http://armorgames.com/play/107/portal-the-flash-version
Where to download the newest version?
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 13, 2011, 11:34:50 am
Oh, you want the version with the map ? It's not so much fun :p
For Portal, the matter is that I can't use the third dimension. It's only a projection of a 2D world. So I don't have any gravity.
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 13, 2011, 11:35:13 am
Builderboy started a PortalX (http://ourl.ca/4250/78603) but it is not for Nspires and it is in 2D, like the Flash version
@Chockosta, you mean that you can't jump and all, only walk ?
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 13, 2011, 11:38:29 am
Yeah. Sad, isn't it ?
Title: Re: [Lua] RayCaster
Post by: p2 on July 13, 2011, 11:49:36 am
I ment, that you'll have to go to a special point on the map, without walking, just portals.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 13, 2011, 02:10:18 pm
It is possible to change the camera height without sacrificing performance, but only to the point that the camera is level with the tops or the bottoms of the walls. It just involves changing the calculations for figuring out which pixel is the top and bottom of the wall for each column. After that, further raycasting is needed to show walls further out in the distance.
Title: Re: [Lua] RayCaster
Post by: Deron on July 13, 2011, 06:38:49 pm
You could at least have given credit to Lode Vandevenne (http://lodev.org/cgtutor/raycasting.html) before copying the code from his tutorial nearly word by word, or you should've at least changed the variable names to give us the illusion that the "Par Loic Pujet" actually was true. Sorry for being harsh, but I don't feel much sympathy for people who pretend to have made something themselves, and don't even have the guts to thank or in the slightest way mention the original creator. I'm looking forward to hearing your silly excuses.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 13, 2011, 11:25:18 pm
You don't actually know if Chockosta used his code or not, so I wouldn't go and accuse him, a PM asking him about this would be more appropriate. However, if this is true, then Chockosta, you should give him credit.
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 14, 2011, 02:35:30 am
(I don't think Deron can PM with only 1 post but I don't know)

- I don't think Wolfeinstein was made in Lua. So Chockosta still had some work to do if he copied.
- If Chockosta had copied the code, he would not have only plain walls. So he didn't (I think).
- There is no point accusing Chockosta and letting all the others raycasting-makers, since Doom looks more like Wolfeinstein than this Maze.
Title: Re: [Lua] RayCaster
Post by: Deron on July 14, 2011, 06:00:31 am
You don't actually know if Chockosta used his code or not, so I wouldn't go and accuse him, a PM asking him about this would be more appropriate. However, if this is true, then Chockosta, you should give him credit.
Alright.

Vandevenne's code:
Code: [Select]
double cameraX = 2 * x / double(w) - 1; //x-coordinate in camera space
double rayPosX = posX;
double rayPosY = posY;
double rayDirX = dirX + planeX * cameraX;
double rayDirY = dirY + planeY * cameraX;
Chokosta's code:
Code: [Select]
cameraX=(x*2/w)-1
rayPosX=camera[1]
rayPosY=camera[2]
rayDirX=dirX+planeX*cameraX
rayDirY=dirY+planeY*cameraX



Vandevenne's code:
Code: [Select]
int mapX = int(rayPosX);
int mapY = int(rayPosY);
double deltaDistX = sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
double deltaDistY = sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
Chokosta's code:
Code: [Select]
mapX=math.floor(rayPosX)
mapY=math.floor(rayPosY)
deltaDistX=racine(1+(rayDirY*rayDirY)/(rayDirX*rayDirX))
deltaDistY=racine(1+(rayDirX*rayDirX)/(rayDirY*rayDirY))



Vandevenne's code:
Code: [Select]
if (rayDirX < 0) {
        stepX = -1;
        sideDistX = (rayPosX - mapX) * deltaDistX;
} else {
        stepX = 1;
        sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
}
if (rayDirY < 0) {
        stepY = -1;
        sideDistY = (rayPosY - mapY) * deltaDistY;
} else {
        stepY = 1;
        sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
}
Chokosta's code:
Code: [Select]
if rayDirX<0 then
stepX=-1
sideDistX=(rayPosX-mapX)*deltaDistX
else
stepX = 1;
sideDistX = (mapX+1-rayPosX)*deltaDistX
end
if rayDirY<0 then
stepY=-1;
sideDistY=(rayPosY-mapY)*deltaDistY
else
stepY=1;
sideDistY=(mapY+1-rayPosY)*deltaDistY
end



Vandevenne's code:
Code: [Select]
while (hit == 0) {
        if (sideDistX < sideDistY) {
          sideDistX += deltaDistX;
          mapX += stepX;
          side = 0;
        } else {
          sideDistY += deltaDistY;
          mapY += stepY;
          side = 1;
        }

        if (worldMap[mapX][mapY] > 0)
                hit = 1;
}
Chokosta's code:
Code: [Select]
while hit==0 do
if sideDistX<sideDistY then
sideDistX=sideDistX+deltaDistX
mapX=mapX+stepX
side=0
else
sideDistY=sideDistY+deltaDistY
mapY=mapY+stepY
side=1
end

if map[mapX][mapY]>0 then
hit=1
end
end



Vandevenne's code:
Code: [Select]
if (side == 0)
      perpWallDist = fabs((mapX - rayPosX + (1 - stepX) / 2) / rayDirX);
else
      perpWallDist = fabs((mapY - rayPosY + (1 - stepY) / 2) / rayDirY);
Chokosta's code:
Code: [Select]
if side==0 then
perpWallDist=math.abs((mapX-rayPosX+(1-stepX)/2)/rayDirX)
else
perpWallDist=math.abs((mapY-rayPosY+(1-stepY)/2)/rayDirY)
end



Vandevenne's code:
Code: [Select]
int lineHeight = abs(int(h / perpWallDist));
int drawStart = -lineHeight / 2 + h / 2;
if(drawStart < 0)
       drawStart = 0;
int drawEnd = lineHeight / 2 + h / 2;
if(drawEnd >= h)
       drawEnd = h - 1;
Chokosta's code:
Code: [Select]
hauteurLigne=math.abs(math.floor(h/perpWallDist))
drawStart=math.floor(-hauteurLigne/2+h/2)
drawEnd=math.floor(hauteurLigne/2+h/2)
if drawStart<0 then
drawStart=0
end
if drawEnd>=h then
drawEnd=h-1
end

Do you want more?

Hayleia I don't know what Wolfenstein has to do with all this, you clearly did not read either the content in the link nor my last message.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 14, 2011, 06:02:52 am
Actually, I did not see that tutorial.
I just type "tutorial raycating" in google, and I found really many tutorials :

http://ressources.mediabox.fr/tutoriaux/flashplatform/affichage/3d/raycasting
http://www.permadi.com/tutorial/raycast/
http://zupi.free.fr/PTuto/index.php?ch=ptuto&p=intro
http://lodev.org/cgtutor/raycasting.html

All these ones are from the same tutorial.
I did not know how to make a raycaster, so I read all that. But I did not copy/paste them. And moreover, I had to port the code from a different language.
That's true, some variables have the same name. But I changed things, like the events, which are totally from me.
But you are right, I should have given credit to the tutorial author. That was not very nice, I am sorry. But there are at least 4 tutorials. So which one should I have quoted ?

If you tell me which one is the original, I will put a link in my first post, and apologies.
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 14, 2011, 07:27:47 am
Hayleia I don't know what Wolfenstein has to do with all this, you clearly did not read either the content in the link nor my last message.
Ok, I should not fight but I read your link and it is written "Wolfenstein 3D" so it is you that didn't read your link before speaking. So before saying people are stupid, look at you. As I don't want to start a fight, I will not answer you from now.
If you want to keep saying people copy others, go to the ASM forums and ask why they all use bcall(ClrLCDfull)
Title: Re: [Lua] RayCaster
Post by: JosJuice on July 14, 2011, 08:22:27 am
Ok, I should not fight but I read your link and it is written "Wolfenstein 3D" so it is you that didn't read your link before speaking. So before saying people are stupid, look at you.
The thing he linked to was an raycasting tutorial. The mention of Wolfenstein there was only intended to serve as an example of what raycasting can do - that guy didn't make Wolfenstein or use any of its code.
If you want to keep saying people copy others, go to the ASM forums and ask why they all use bcall(ClrLCDfull)
The programmers there aren't trying to claim that they wrote ClrLCDFull. They just call it whenever they have to use it.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 14, 2011, 08:36:40 am
...
The programmers there aren't trying to claim that they wrote ClrLCDFull. They just call it whenever they have to use it.

But me, I wrote this raycaster. I followed a tutorial, but I wrote the entire thing.
Title: Re: [Lua] RayCaster
Post by: JosJuice on July 14, 2011, 08:41:17 am
...
The programmers there aren't trying to claim that they wrote ClrLCDFull. They just call it whenever they have to use it.

But me, I wrote this raycaster. I followed a tutorial, but I wrote the entire thing.
Yes. We probably just stop fighting.
Title: Re: [Lua] RayCaster
Post by: Deron on July 14, 2011, 11:53:20 am
Hayleia I don't know what Wolfenstein has to do with all this, you clearly did not read either the content in the link nor my last message.
Ok, I should not fight but I read your link and it is written "Wolfenstein 3D" so it is you that didn't read your link before speaking. So before saying people are stupid, look at you. As I don't want to start a fight, I will not answer you from now.
If you want to keep saying people copy others, go to the ASM forums and ask why they all use bcall(ClrLCDfull)
The tutorial only mentioned Wolfenstein a couple of times, but it has nothing to do with the core content. Also, when did I say anyone was stupid? Furthermore, since when has discussing about an issue on the Internet become fighting?

...
The programmers there aren't trying to claim that they wrote ClrLCDFull. They just call it whenever they have to use it.

But me, I wrote this raycaster. I followed a tutorial, but I wrote the entire thing.
I stand my ground. A big part of the code was copied from the tutorial and you did in no way mention it or the creator of it. There's a difference in reading documents and making up your own mind (i.e. reading many tutorials and then writing your own code from scratch), and copying chunks from another person's code (it doesn't matter if you removed a couple of brackets and changed function names to make it work on the calculator, it's not what's important). He may have meant to have his code copied freely, but it still doesn't change the fact that it is disrespectful to pretend it was all made by you (don't tell me you didn't try to), when it clearly wasn't. It's not a crime; it's just a matter of education, respect and honesty.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 14, 2011, 01:09:02 pm
Sure. I totally agree. Please read my post ( http://ourl.ca/12034/227840 ) and tell me which tutorial is the original one, then I'll mention it.

And I did not "removed a couple of brackets and changed function names". I used the tutorial author's code to create mine. Isn't it the purpose of a tutorial ?
Also, I'm not a great coder, and I've never done a 3D engine (even if it's only a raycaster) before that. So I have to train, and that's a training. It's absolutely not a finished program, it's a trial of an engine for a possible game.

You are right, I should have given credits to the author. But what you say is a little excessive, don't you think so ?
Title: Re: [Lua] RayCaster
Post by: Deron on July 14, 2011, 02:03:57 pm
Sure. I totally agree. Please read my post ( http://ourl.ca/12034/227840 ) and tell me which tutorial is the original one, then I'll mention it.

And I did not "removed a couple of brackets and changed function names". I used the tutorial author's code to create mine. Isn't it the purpose of a tutorial ?
Also, I'm not a great coder, and I've never done a 3D engine (even if it's only a raycaster) before that. So I have to train, and that's a training. It's absolutely not a finished program, it's a trial of an engine for a possible game.

You are right, I should have given credits to the author. But what you say is a little excessive, don't you think so ?

I shouldn't have to explain you this, but it's about material (or electronic, in this case) property, not about some tutorials which you read. I'm sorry if you do not understand that, but it should be very clear and obvious. What I can see is that your code resembles very closely to that of Vandevenne, because you blatantly copied big portions of code from him. There's nothing more to it. It should also be quite obvious that a honest gesture of an educated and respectful man would be at the very least to thank him for that, not go along and pretend you made it. The purpose of a tutorial is to be a tutorial, to teach and to show (or something along those lines). It doesn't matter if you took the code from a tutorial, from a book or from a donkey's ass, all that matters is that you took vast chunks of it from someone else. That you're not a very good coder and that it's not a finished program has absolutely nothing to do with this, it doesn't give you any special privileges. I suppose it all comes down to education and good manners, two fundamental things that many people lack.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 14, 2011, 02:17:00 pm
Please READ my posts !
I perfectly understand what do you mean.
I WANT to thank the tutorial author. But the tutorial that I followed I this one :
http://ressources.mediabox.fr/tutoriaux/flashplatform/affichage/3d/raycasting
It's not the same that you talk about, so I don't know the original author.
So I quote myself : "tell me which tutorial is the original one, then I'll mention it." and "If you tell me which one is the original, I will put a link in my first post, and apologies."

That's the third time I repeat that, so please READ before posting ! That is really annoying.
Title: Re: [Lua] RayCaster
Post by: Deron on July 14, 2011, 02:38:18 pm
Oh okay, sorry my bad. I first thought that the fact that the variables dirX, dirY, planeX, planeY, cameraX, rayPosX, rayPosY, rayDirX, rayDirY, sideDistX, sideDistY, perpWallDist, mapX, mapY, hit, stepX, stepY, deltaDistX, deltaDistY, side, drawStart and drawEnd have the exact same name and do exactly the same thing in Vandevenne's was a coincidence.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 14, 2011, 04:07:29 pm
Mmmh.
I read your post more than 10 times, I still don't understand it. I think that it's ironic, but I really don't understand anything.
And anyway, it doesn't answer to my question.

Which tutorial should I mention ? I followed this one : http://ressources.mediabox.fr/tutoriaux/flashplatform/affichage/3d/raycasting and you talk about this one : http://lodev.org/cgtutor/raycasting.html
That's the fourth time I ask this, so if keep not answering, I'll just ignore you.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 14, 2011, 04:18:59 pm
Oh okay, sorry my bad. I first thought that the fact that the variables dirX, dirY, planeX, planeY, cameraX, rayPosX, rayPosY, rayDirX, rayDirY, sideDistX, sideDistY, perpWallDist, mapX, mapY, hit, stepX, stepY, deltaDistX, deltaDistY, side, drawStart and drawEnd have the exact same name and do exactly the same thing in Vandevenne's was a coincidence.
It's a good, easy to understand naming system. Im also using it for the raycaster I'm working on.
Title: Re: [Lua] RayCaster
Post by: ztrumpet on July 14, 2011, 04:24:06 pm
Hey Deron, quick question:  Why is the tutorial Chockosta followed ( http://ressources.mediabox.fr/tutoriaux/flashplatform/affichage/3d/raycasting ) and the one you believe he copied ( http://lodev.org/cgtutor/raycasting.html ) so similar?  By your logic one of these tutorials must be copied off the other.

On another note, Chockosta, you should have probably mentioned that you followed a tutorial in your first post. :-\
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 15, 2011, 03:02:48 am
Ok, I should not fight but I read your link and it is written "Wolfenstein 3D" so it is you that didn't read your link before speaking. So before saying people are stupid, look at you.
The thing he linked to was an raycasting tutorial. The mention of Wolfenstein there was only intended to serve as an example of what raycasting can do - that guy didn't make Wolfenstein or use any of its code.
If you want to keep saying people copy others, go to the ASM forums and ask why they all use bcall(ClrLCDfull)
The programmers there aren't trying to claim that they wrote ClrLCDFull. They just call it whenever they have to use it.
For Wolfeinstein, sorry, I'm French so the only word I understood to the tutorial was Wolfeinstein ;D
For ClrLCDFull, I was referring to the variables names that Chockosta "copied", not to the fact Chockosta says he made it (did you understand that FrEnchglish sentence ?). Deron says that "rayPosY" and all are the same, but it is just because it is more convenient to use "speaking words" that were already used by the tutorial, because we still can put an ".equ" and use something other than ClrLCDFull.
Title: Re: [Lua] RayCaster
Post by: Ashbad on July 15, 2011, 08:36:02 am
You could at least have given credit to Lode Vandevenne (http://lodev.org/cgtutor/raycasting.html) before copying the code from his tutorial nearly word by word, or you should've at least changed the variable names to give us the illusion that the "Par Loic Pujet" actually was true.

What do you want from him, money?

I notice you haven't been conducting yourself professionally concerning the matter, so I don't blame anyone here for ignoring you.  I would ignore you too.  Obviously he didn't derive all of the code himself, but keep in mind that Vandevenne guy probably used a tutorial to generate some of his code as well; most ray casters use similar naming conventions for variables, all engines will be pretty close in that sense (what you you gonna do now, blame all assembly programmers who made line drawing routines that they stole the idea of using deltaX and deltaY from some guy who made one using those conventions in FORTRAN II?)

Before making such a smart-assed remark that makes someone look like a thief and a bad programmer, look around at other tutorials, and you'll see for sure very, very, very similar code.  Don't come onto these forums just to cause trouble, you add nothing productive or friendly to the mix, and just ruin the whole lingo.

Quote from: Deron
Sorry for being harsh, but I don't feel much sympathy for people who pretend to have made something themselves, and don't even have the guts to thank or in the slightest way mention the original creator. I'm looking forward to hearing your silly excuses.

Sorry for being harsh, but I don't have much sympathy for code originality trolls whose only contribution to the site is complaining about something without thinking over what they're complaining about.  I'm looking forward to hearing your silly excuses.
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 15, 2011, 09:00:32 am
This might not be a fight yet, but it is coming very close. People please stop arguing over this and help Chockosta figure out which tutorial to mention(or if he should mention them all).

Yes, Chockosta should have mentioned he used a tutorial(even though this seems almost self evident at least to me), but you should not keep beating him over the head with this. Why can't you guys just work together and solve this so your actually contributing to the community instead of just causing problems

EDIT:Ashbad I agree with most of your post, but saying
I'm looking forward to hearing your silly excuses.
will just cause more fights. Please just help stop it instead of increasing the problem.

And guys the Wolfenstein 3d thing was just a small mistake please drop it.

I am seriously tired of seeing arguments over pointless things whether it be in real life or on the internet. This is a waste of everyones time and just hurts everyone involved

EDIT2: Ashbad I'm sorry I didn't read your post thoroughly enough. I didn't see that your last sentence was taken from one of Deron's quotes. I'm sorry for saying you were trying to start fights
Title: Re: [Lua] RayCaster
Post by: Hayleia on July 15, 2011, 11:21:18 am
Ok, as Ruler said, we are going to avoid fight.
So, Deron, read Chockosta's post (http://ourl.ca/12034/227840) and answer it politely. Then, Chockosta would access to your request. But if you don't, he wouldn't.
Title: Re: [Lua] RayCaster
Post by: pianoman on July 15, 2011, 12:37:44 pm
Changing the subject... :P
The map looks really great, Chockosta.
I'm glad you're on our side, not TI's. [/feeble attempt at humor]
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 15, 2011, 12:52:09 pm
Once I find the 84+ keypad for my nspire...I am making a raycaster in TI-BASIC./me really needs to get more sleep
Title: Re: [Lua] RayCaster
Post by: p2 on July 15, 2011, 02:09:05 pm
raycaster in BASIC?
That would be cool.
I can't wait for watchin this code.
I ever thought it's not possible to make 3D objects in basic.
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 15, 2011, 02:25:37 pm
I ever thought it's not possible to make 3D objects in basic.
Its possible but its really hard(I believe)
Title: Re: [Lua] RayCaster
Post by: p2 on July 15, 2011, 02:26:47 pm
Do you have any Idea how it would be possible?
I don't have any.

But I'm sure it'll be SLOOOOW!  :P
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 15, 2011, 02:27:43 pm
Let me see if I can find one of the 3d programs I saw at one point on ti-calc.
I believe its with drawing lines
Title: Re: [Lua] RayCaster
Post by: p2 on July 15, 2011, 02:29:02 pm
I've seen a 3D program for 84+, too.
But it was ASM.
Never seen one on Basic.
Title: Re: [Lua] RayCaster
Post by: ruler501 on July 15, 2011, 02:29:56 pm
Look here p2 these are all in basic http://www.ticalc.org/pub/83plus/basic/graphics/3d/. well they're in the basic section
Title: Re: [Lua] RayCaster
Post by: TIfanx1999 on July 15, 2011, 03:31:13 pm
@Deron: You've made your point quite clear, and Chockosta has been nothing but apologetic and patient, and understanding in his responses. The only post I've seen you make are repeating the same thing over and over and being extremely rude about it. If you wish to remain here you need to change your poor attitude. I'd also like to point out that there are a great many other threads and projects to look at here, so if you are actually interested in contributing please look around.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 15, 2011, 03:34:49 pm
It'll be on the homescreen, so only 16 rays to cast. Hopefully, I can get 1 fps.
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 26, 2011, 12:10:58 pm
I entirely rewrote the engine (no more fights with that, I hope...)
And I've coded a small maze generator (It can generates more than 30,000,000,000 mazes), so here is the first 3D maze game in Lua.
Unfortunately, I'm in holidays and I did not bring my TI-Nspire, so I'll post it in a week.
Title: Re: [Lua] RayCaster
Post by: Jim Bauwens on July 26, 2011, 02:11:58 pm
Nice, I'm looking forward to it!
Title: Re: [Lua] RayCaster
Post by: cypressx1 on July 27, 2011, 07:36:24 am
me too!
Title: Re: [Lua] RayCaster
Post by: Adriweb on July 27, 2011, 11:45:34 am
Yep, it definitely looks cool to have a 3D random puzzle game, congrats :)

looking forward to see it ! (the game, and the code :P)
Title: Re: [Lua] RayCaster
Post by: pianoman on July 27, 2011, 12:31:46 pm
Can't wait for it :D
Title: Re: [Lua] RayCaster
Post by: calc84maniac on July 27, 2011, 02:27:19 pm
I was reading earlier in the topic and it was said that textures would be impossible to do quickly in Lua. But can't you exploit the image.copy() function? You could store each column of the texture as a TI.image, and select one of these columns depending on where the wall is intersected. Then, instead of doing something like:
Code: [Select]
gc:drawRect(x, y, xwidth, yheight)
You could do:
Code: [Select]
gc:drawImage(image.copy(columnImage, xwidth, yheight), x, y)
This is probably a bit slower than just drawing a rectangle, but I can't imagine it being as slow as drawing textures manually.

Edit: Removed extra closing parentheses
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 27, 2011, 05:16:20 pm
That would be a lot of TI.images :P
Title: Re: [Lua] RayCaster
Post by: calc84maniac on July 27, 2011, 07:37:03 pm
That would be a lot of TI.images :P
Nobody has to know if you keep them in an array, hehe
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 27, 2011, 08:32:37 pm
What has this world come to? Images in arrays? Blasphemy!
You can put images in matrices now? *.*
Title: Re: [Lua] RayCaster
Post by: calc84maniac on July 27, 2011, 08:35:11 pm
Well, Lua uses tables. You can put anything you want in a table, I'm pretty sure.
Title: Re: [Lua] RayCaster
Post by: pianoman on July 27, 2011, 09:48:28 pm
Yeah, you can put everyhing in a table :P
Title: Re: [Lua] RayCaster
Post by: Adriweb on July 28, 2011, 01:10:40 am
You can also use jimbauwens' ti.image compression algorithm %)
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 28, 2011, 08:26:07 am
I can try, but I don't have too much hope.
TI.images are awfully slow. Look at my Bobby Carrot : when there are not too much sprites, the drawing is fast. But when there are more than 50 sprites (30*30 pixels), you have to wait more than 1 sec before the screen is refreshed.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 28, 2011, 10:26:24 am
Then that's no good. :( Even rendering every other column, that's still 160 images. I'm not too surprised, as that was supposed to be a general purpose routine for displaying a few images here and there, not optimized for speed.
Title: Re: [Lua] RayCaster
Post by: Adriweb on July 28, 2011, 11:22:01 am
[ i'm not saying anything, okay ? ]

TI.Image will be faster in the future (very probably) thanks to [ that I really can't say ]

[ / oops what did I just say ]
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on July 28, 2011, 11:24:55 am
[ i'm not saying anything, okay ? ]

TI.Image will be faster in the future (very probably) thanks to [ that I really can't say ]

[ / oops what did I just say ]
:o ... interesting
Title: Re: [Lua] RayCaster
Post by: Chockosta on July 28, 2011, 11:26:10 am
So I just have to wait for OS 3.1, right ?
Title: Re: [Lua] RayCaster
Post by: Adriweb on July 28, 2011, 11:30:59 am
Probably, I don't really know. Maybe 3.2 (or whatever is after 3.1), though :)

it depends if TI will [ grllmmmll ] the [ grlgmrl ], really.
Title: Re: [Lua] RayCaster
Post by: Jim Bauwens on July 28, 2011, 11:45:03 am
/me hits adriweb with a large nspire prototype :p
Title: Re: [Lua] RayCaster
Post by: Adriweb on July 28, 2011, 11:50:33 am
/me hits adriweb with a large nspire prototype :p


/me blocks jimbauwens with 2 released Nspire and 3 prototypes !  :P


Ok lol let's stop spamming and get back to raycaster :)
Title: Re: [Lua] RayCaster
Post by: critor on July 29, 2011, 05:34:36 am
/me hits adriweb with a large nspire prototype :p


/me blocks jimbauwens with 2 released Nspire and 3 prototypes !  :P

;)
Title: Re: [Lua] RayCaster
Post by: Chockosta on August 05, 2011, 08:37:45 am
I'm back, so I can post my 3D mazes game.  :)

If you don't want to download it, here is a video :

I did not suppress the mini-map, but if you use it, the game is really easy.
Should I remove it ?
Title: Re: [Lua] RayCaster
Post by: Adriweb on August 05, 2011, 05:23:47 pm
Really impressive !

Mind to share the code for this one ?
Title: Re: [Lua] RayCaster
Post by: critor on August 06, 2011, 05:19:05 am
Did you know that Mazes3D does support colors?

Check the CX screenshot in the TI-Bank news! ;)
http://ti.bank.free.fr/index.php?mod=news&ac=commentaires&id=1273
Title: Re: [Lua] RayCaster
Post by: Chockosta on August 06, 2011, 11:53:43 am
Critor : thanks for the news !
Adriweb :
Here is the code (yeah, I should add comments) :
Code: [Select]
pieces={{{0,0,0,0,0,0,0},{0,0,0,1,0,0,0},{0,0,0,0,0,0,0},{0,1,0,2,0,1,0},{0,0,0,0,0,0,0},{0,0,0,1,0,0,0},{0,0,0,0,0,0,0}},{{1,0,1,0,0,0,1},{1,0,1,1,1,0,1},{0,0,0,0,1,0,1},{0,1,0,0,1,0,0},{0,1,0,1,1,0,0},{1,1,0,0,1,1,0},{1,1,0,0,0,0,0}},{{1,1,1,0,1,1,1},{1,0,0,0,0,0,1},{1,0,0,1,0,0,1},{0,0,1,1,1,0,0},{1,0,0,1,0,0,1},{1,0,0,0,0,0,1},{1,1,1,0,1,1,1}},{{1,1,1,0,1,1,1},{0,0,1,0,0,1,0},{0,0,1,0,1,0,0},{0,0,0,0,0,0,0},{0,1,1,1,1,1,0},{0,0,0,0,0,0,1},{1,0,0,0,1,1,1}},{{1,1,1,0,1,1,1},{1,0,0,0,0,0,1},{1,0,1,0,1,0,1},{0,0,0,0,0,0,0},{1,0,1,0,1,0,1},{1,0,0,0,0,0,1},{1,1,1,0,1,1,1}},{{1,1,1,0,0,0,0},{1,0,0,0,0,1,0},{1,0,0,0,1,0,0},{0,0,0,1,0,0,0},{0,0,1,0,0,0,1},{0,1,0,0,0,0,1},{0,0,0,0,1,1,1}}}

function width() return platform.window:width() end
function height() return platform.window:height() end
function refresh() platform.window:invalidate() end

function generateMaze()
 local tempMap,mazePieces,currentRow
 tempMap={}
 tempMap[1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
 tempMap[30]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
 mazePieces={}
 for i=1,16 do
  mazePieces[i]=pieces[math.random(2,6)]
 end
 mazePieces[math.random(2,16)]=pieces[1]
 for i=1,28 do
  currentRow={1}
  currentRow[30]=1
  for j=1,28 do
   currentRow[j+1]=mazePieces[math.floor((j-1)/7)+math.floor((i-1)/7)*4+1][(i-1)%7+1][(j-1)%7+1]
  end
  tempMap[i+1]=currentRow
 end
 map1=tempMap
end

function sqrt2(a)
 x=1
 y=0.5*(1+a)
 while math.abs(y-x)>0.001 do
  x=y
  y=0.5*(x+a/x)
 end
 return y
end

function exp2(a)
 return a*a
end

function sign(a)
 if a<0 then
  return -1
 else
  return 1
 end
end

function render3D(gc,surf,map,cam)
 gc:setColorRGB(189,228,255)
 gc:fillRect(surf.x,surf.y,surf.w,surf.h/2)
 gc:setColorRGB(47,127,0)
 gc:fillRect(surf.x,surf.y+surf.h/2,surf.w,surf.h/2)
 for i=0,surf.w-1,surf.res do
  column=(i*2/surf.w)-1

  rayStartX=cam.x
  rayStartY=cam.y
  rayDirX=math.cos(cam.rot)+math.cos(cam.rot-1.5707963267949)*column
  rayDirY=math.sin(cam.rot)+math.sin(cam.rot-1.5707963267949)*column

  rayCellX=math.floor(rayStartX)
  rayCellY=math.floor(rayStartY)

  rayStepX=sqrt2(exp2(rayDirY)/exp2(rayDirX)+1)
  rayStepY=sqrt2(exp2(rayDirX)/exp2(rayDirY)+1)
  rayLengthX=rayStepX*(rayStartX%1*sign(-rayDirX)+(sign(rayDirX)+1)/2)
  rayLengthY=rayStepY*(rayStartY%1*sign(-rayDirY)+(sign(rayDirY)+1)/2)

  hit=nil
  while not hit do
   if rayLengthX<rayLengthY then
    rayLengthX=rayLengthX+rayStepX
    rayCellX=rayCellX+sign(rayDirX)
    wallSide=0
   else
    rayLengthY=rayLengthY+rayStepY
    rayCellY=rayCellY+sign(rayDirY)
    wallSide=1
   end

   if map[rayCellX][rayCellY]~=0 then
    hit=true
    wallType=map[rayCellX][rayCellY]
   end
  end
  if wallSide==0 then
   wallDist=math.abs((rayCellX-rayStartX+(1-sign(rayDirX))/2)/rayDirX)
  else
   wallDist=math.abs((rayCellY-rayStartY+(1-sign(rayDirY))/2)/rayDirY)
  end
  columnHeight=math.abs(math.floor(surf.h/wallDist))
  columnStart=surf.h/2-columnHeight/2
  if columnStart<0 then
   columnStart=0
  end
  if columnHeight+columnStart>=surf.h then
   columnHeight=surf.h-columnStart
  end

  if wallSide==1 then
   gc:setColorRGB(100,0,0)
  else
   gc:setColorRGB(140,0,0)
  end
  if wallType==2 then
   gc:setColorRGB(255,255,255)
  end
  gc:fillRect(i+surf.x,columnStart+surf.y,surf.res,columnHeight)
 end
end



function drawMap(gc,map,cam)
 gc:setColorRGB(69,45,0)
 gc:setPen("medium","smooth")
 gc:drawRect(0,0,66,66)
 gc:setColorRGB(222,189,127)
 gc:fillRect(0,0,66,66)
 startX=1 startY=1
 if cam.x>=6 then startX=math.floor(cam.x)-5 end
 if cam.y>=6 then startY=math.floor(cam.y)-5 end
 if cam.x+5>#map then startX=#map-10 end
 if cam.y+5>#map[1] then startY=#map[1]-10 end
 for i=startX,startX+10,1 do
  for j=startY,startY+10,1 do
   if map[i][j]~=0 then
    if map[i][j]==1 then
     gc:setColorRGB(120,78,0)
    elseif map[i][j]==2 then
     gc:setColorRGB(255,255,255)
    end
    gc:fillRect(60-(i*6-startX*6),j*6-startY*6,6,6)
   end
  end
 end
 gc:setColorRGB(69,45,0)
 gc:fillArc(60-(cam.x*6-startX*6-3),cam.y*6-startY*6-3,5,5,0,360)
end



function on.escapeKey()
 menu=1
 won=nil
 refresh()
end
on.escapeKey()

function on.enterKey()
 menu=nil
 mapDraw=nil
 camera={x=3,y=3,rot=1.05}
 screen={x=0,y=0,w=width(),h=height(),res=2}
 generateMaze()
 refresh()
end

function on.arrowKey(ar)
 if not menu then
  turn=nil
  if ar=="right" then
   camera.rot=camera.rot-0.1
  end
  if ar=="left" then
   camera.rot=camera.rot+0.1
  end
  if ar=="up" then
   if map1[math.floor(camera.x+math.cos(camera.rot)/3)][math.floor(camera.y+math.sin(camera.rot)/3)]~=1 then
    camera.x=camera.x+math.cos(camera.rot)/3
    camera.y=camera.y+math.sin(camera.rot)/3
   end
  end
  if ar=="down" then
   if map1[math.floor(camera.x-math.cos(camera.rot)/4)][math.floor(camera.y-math.sin(camera.rot)/4)]~=1 then
    camera.x=camera.x-math.cos(camera.rot)/4
    camera.y=camera.y-math.sin(camera.rot)/4
   end
  end
  if map1[math.floor(camera.x)][math.floor(camera.y)]==2 then
   menu=1
   won=1
  end
  refresh()
 end
end

function on.charIn(ch)
 if not menu then
  if ch=="m" then
   mapDraw=not mapDraw
  elseif ch=="*" and screen.w<width() then
   screen.w=screen.w+width()/height()*5
   screen.h=screen.h+5
   screen.x=width()/2-screen.w/2
   screen.y=height()/2-screen.h/2
  elseif ch=="/" and screen.w>100 then
   screen.w=screen.w-width()/height()*5
   screen.h=screen.h-5
   screen.x=width()/2-screen.w/2
   screen.y=height()/2-screen.h/2
  elseif ch=="h" then screen.res=2
  elseif ch=="l" then screen.res=4
  end
  refresh()
 end
end



function on.paint(gc)
 if menu then
  gc:setColorRGB(0,0,255)
  gc:setFont("sansserif","r",30)
  gc:drawString("MAZES 3D",75,0,"top")
  if won then
   gc:drawString("You won !",80,150,"top")
  end
  gc:setFont("serif","b",10)
  gc:drawString("Press Enter to start",100,100,"top")
 else
  render3D(gc,screen,map1,camera)
  if mapDraw then
   drawMap(gc,map1,camera)
  end
 end
 gc:setColorRGB(0,0,0)
 gc:setFont("sansserif","r",8)
 gc:drawString("Lua Mazes 3D - Par Loic Pujet",10,200,"top")
end

Title: Re: [Lua] RayCaster
Post by: Adriweb on August 06, 2011, 12:34:14 pm
Thanks you !
Title: Re: [Lua] RayCaster
Post by: DJ Omnimaga on August 06, 2011, 02:22:40 pm
That is great! That makes me want a CX more and more, although I need to find one under $230 with taxes included x.x

It seems to run at a decent speed too. I wonder if you could make a video of it in color?
Title: Re: [Lua] RayCaster
Post by: Chockosta on August 06, 2011, 02:26:31 pm
Well, to have it in color, I need to use the TI-Nspire software, and the speed is about 3 times faster than on-calc...
Title: Re: [Lua] RayCaster
Post by: critor on August 06, 2011, 06:43:33 pm
So we need a real TI-Nspire CX emulator...
Title: Re: [Lua] RayCaster
Post by: critor on August 07, 2011, 04:47:15 pm
I think you could add variable-height walls quite easily. ;)
Title: Re: [Lua] RayCaster
Post by: DJ Omnimaga on August 07, 2011, 05:00:28 pm
So we need a real TI-Nspire CX emulator...
Yep. I had the student software, but my license expired and I didn't feel like buying it. I wonder if it would be easy to add color support in the emu?
Title: Re: [Lua] RayCaster
Post by: critor on August 07, 2011, 05:16:56 pm
So we need a real TI-Nspire CX emulator...
Yep. I had the student software, but my license expired and I didn't feel like buying it. I wonder if it would be easy to add color support in the emu?

It's more complicated than that, as the current Nspire emulator just doesn't run the CX 3.0 Boot2, which is encrypted unlike non-CX Boot2 versions.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on August 07, 2011, 05:24:42 pm
I thought we had to decrypt the boot2 anyways for the emulator. Or is this a new kind of encryption?
Also, kinda off topic, but if the calc has 16 bit color, that means updating the screen from a screen buffer will take 4x as long.
Title: Re: [Lua] RayCaster
Post by: critor on August 07, 2011, 05:47:52 pm
I thought we had to decrypt the boot2 anyways for the emulator. Or is this a new kind of encryption?
Also, kinda off topic, but if the calc has 16 bit color, that means updating the screen from a screen buffer will take 4x as long.

Non-CX Boot2 were encoded and had to be decoded, not decrypted.

The CX Boot2 is encoded AND encrypted. This is much worse. It has to be decoded and decrypted (which requires some key).
It is probably decrypted by the CX Boot1 we'll never be able to link legally online (unlike the Boot2 which just needs to be extracted from any OS installation file).
Title: Re: [Lua] RayCaster
Post by: DJ Omnimaga on August 07, 2011, 05:51:27 pm
Hmm I see... I hope this doesn't compromise the arrival of a CX emu in the future...
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on August 07, 2011, 06:38:58 pm
It's illegal to decrypt stuff now?
Title: Re: [Lua] RayCaster
Post by: calc84maniac on August 07, 2011, 09:13:09 pm
Yeah, it may be possible to reverse engineer the boot1 to make a decryption routine built into the emulator. Would that be sufficiently legal?
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on August 07, 2011, 09:17:03 pm
I wouldn't be surprised if TI does the same thing as the signing key controversy if that happens.
Title: Re: [Lua] RayCaster
Post by: calc84maniac on August 07, 2011, 09:18:16 pm
But they had no real ground to stand on in that case, and they might not in this case either.
Title: Re: [Lua] RayCaster
Post by: fb39ca4 on August 07, 2011, 09:22:34 pm
Well, I could see them trying to pose the encrypted code as DRM, and then saying we are circumventing it which is apparently illegal in the DMCA.
Title: Re: [Lua] RayCaster
Post by: NecroBumpist on August 19, 2011, 01:08:30 am
While I know this thread is somewhat dated, and the topic really has shifted more towards the CX's DRM, I thought I would highlight the importance of basic Lua optimizations.

I ran the code from the first page (slightly modified, included a timer call so I could get a consistent frame rate), and it ran at 4 to 5 frames per second.
I modify the code some (only localizes variables and common functions), and then I can get 6 - 7 frames per second.
This doesn't change the algorithm at all, though that could probably be improved.

Code: (minor optimizations) [Select]

local timer_stop = timer.stop;
local timer_start = timer.start;
local window = platform.window;
local invalidate = window.invalidate;
local w, h, planeX, planeY, map;


function on.timer()
timer_stop();
invalidate(window);
end

local math_abs = math.abs;
local math_floor = math.floor;
local math_cos, math_sin = math.cos, math.sin;

local function racine(a)
local x=1
local y=0.5*(1+a)
while math_abs(y-x)>0.001 do
x=y
y=0.5*(x+a/x)
end
return y
end

local function renderMap(gc,map,w,h,camera)
local math_cos, math_sin = math_cos, math_sin;
local dirX, dirY, rayPosX, rayPosY, rayDirX, rayDirY, mapX, mapY, deltaDistX,
deltaDisY, hit, stepX, sideDistX, stepY, sideDistY;
for x=0,w,2 do
dirX=math_cos(camera[3])
dirY=math_sin(camera[3])
planeX=math_cos(camera[3]-1.5707963267949)
planeY=math_sin(camera[3]-1.5707963267949)
cameraX=(x*2/w)-1
rayPosX=camera[1]
rayPosY=camera[2]
rayDirX=dirX+planeX*cameraX
rayDirY=dirY+planeY*cameraX
mapX=math_floor(rayPosX)
mapY=math_floor(rayPosY)
deltaDistX=racine(1+(rayDirY*rayDirY)/(rayDirX*rayDirX))
deltaDistY=racine(1+(rayDirX*rayDirX)/(rayDirY*rayDirY))
hit=0

if rayDirX<0 then
stepX=-1
sideDistX=(rayPosX-mapX)*deltaDistX
else
stepX = 1;
sideDistX = (mapX+1-rayPosX)*deltaDistX
end
if rayDirY<0 then
stepY=-1;
sideDistY=(rayPosY-mapY)*deltaDistY
else
stepY=1;
sideDistY=(mapY+1-rayPosY)*deltaDistY
end


while hit==0 do
if sideDistX<sideDistY then
sideDistX=sideDistX+deltaDistX
mapX=mapX+stepX
side=0
else
sideDistY=sideDistY+deltaDistY
mapY=mapY+stepY
side=1
end

if map[mapX][mapY]>0 then
hit=1
end
end

local perpWallDist;

if side==0 then
perpWallDist=math_abs((mapX-rayPosX+(1-stepX)/2)/rayDirX)
else
perpWallDist=math.abs((mapY-rayPosY+(1-stepY)/2)/rayDirY)
end
local hauteurLigne=math.abs(math_floor(h/perpWallDist))
local drawStart=math_floor(-hauteurLigne/2+h/2)
local drawEnd=math_floor(hauteurLigne/2+h/2)
if drawStart<0 then
drawStart=0
end
if drawEnd>=h then
drawEnd=h-1
end

gc:setColorRGB(10,10,10)
if side==1 then
gc:setColorRGB(100,100,100)
end
gc:fillRect(x,drawStart,2,drawEnd-drawStart)
end
end


local menu;
function on.escapeKey()
menu=1
invalidate(window);
end
on.escapeKey()

function on.enterKey()
menu=nil
--fovy=60
camera={10,10,0.05}
w=320 h=240
planeX=0 planeY=1
map={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1},{1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,1},{1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1},{1,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1},{1,1,1,1,1,1,1,0,0,1,0,0,1,0,0,1},{1,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1},{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1},{1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},{1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},{1,0,0,1,1,1,0,0,1,1,1,1,1,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}}
invalidate(window);
end

function on.arrowKey(ar)
turn=nil
if ar=="right" then
camera[3]=camera[3]-0.1
end
if ar=="left" then
camera[3]=camera[3]+0.1
end
if ar=="up" then
if map[math_floor(camera[1]+math_cos(camera[3])/3)][math_floor(camera[2]+math_sin(camera[3])/3)]==0 then
camera[1]=camera[1]+math_cos(camera[3])/3
camera[2]=camera[2]+math_sin(camera[3])/3
end
end
if ar=="down" then
if map[math_floor(camera[1]-math_cos(camera[3])/4)][math_floor(camera[2]-math_sin(camera[3])/4)]==0 then
camera[1]=camera[1]-math_cos(camera[3])/4
camera[2]=camera[2]-math_sin(camera[3])/4
end

end
invalidate(window);
end

local milli = timer.getMilliSecCounter;
local last = 0;

function on.paint(gc)
if menu then
gc:setColorRGB(0,0,255)
gc:setFont("sansserif","r",30)
gc:drawString("RayCaster Demo",30,0,"top")
gc:setFont("serif","b",10)
gc:drawString("Press Enter to start",100,100,"top")
else
gc:setColorRGB(200,200,200)
gc:fillRect(0,0,platform.window:width(),platform.window:height())
renderMap(gc,map,platform.window:width(),platform.window:height(),camera)
end
gc:setColorRGB(0,0,0)
gc:setFont("sansserif","r",8)
gc:drawString("FPS: " .. tostring(1000/(milli()-last)),10,200,"top")
last = milli();
timer_start(0.01);
end
Title: Re: [Lua] RayCaster
Post by: Jim Bauwens on August 19, 2011, 07:00:35 am
Very good example NecroBumpist :)
I recommend people this guide for optimizing their code: http://trac.caspring.org/wiki/LuaPerformance .
Title: Re: [Lua] RayCaster
Post by: Chockosta on August 27, 2011, 06:33:59 am
Thank you for your help, NecroBumpist !
Unfortunately, you optimized the old version, which was a bit slower. I will try to improve the new one.

I didn't know localization was that faster.