PDA

View Full Version : Raycasting V2 - Progress!!!


Gunderak
08-17-2016, 04:36 AM
Okay! So I have sort of made some progress with my efforts in raycasting using GS2, it's still very buggy and still doesn't look quite right...

https://i.gyazo.com/d9c6378a01a99e9c072dedf2a7450dbf.gif

//#CLIENTSIDE
function onCreated(){
this.maxlooplimit = 100000;
sleep(0.5);
this.map = {
{1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,2,0,1},
{1,0,0,0,0,0,0,0,0,0,2,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,2},
{1,0,0,0,0,1,1,0,0,0,0,0,2},
{2,0,0,0,0,0,0,0,0,0,0,0,1},
{2,0,0,0,0,0,0,0,0,0,0,0,1},
{2,0,0,0,0,0,0,0,0,0,0,0,1},
{2,0,0,0,0,2,2,0,0,0,0,0,1},
{2,0,0,0,0,2,2,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,2,2,2,1,1,1,1},
};
this.w = 600;
this.h = 400;
this.off = {screenwidth/2 - this.w/2, screenheight/2 - this.h/2};
this.off = {50, 50};
this.mapwidth = this.map[0].size();
this.mapheight = this.map.size();
this.posx = 2;
this.posy = 2;
this.dirx = -1;
this.diry = 0;
this.planex = 0;
this.planey = 0.66;
this.time = 0;
this.oldtime = 0;
for(temp.i = 0; temp.i < 2000; temp.i ++){
if(isobject((@"3D_R_"@temp.i))){
(@"3D_R_"@temp.i).destroy();
}
}
onTimeout();
}
function sqrt(n) {
return n^0.5;
}
function onTimeout(){
for(temp.x = 0; temp.x < this.w; temp.x ++){
temp.camerax = 2 * temp.x/this.w -1;
temp.rayposx = this.posx;
temp.rayposy = this.posy;
temp.raydirx = this.dirx + this.planex * temp.camerax;
temp.raydiry = this.diry + this.planey * temp.camerax;
temp.mapx = int(temp.rayposx);
temp.mapy = int(temp.rayposy);
temp.sidedistx = 0;
temp.sidedisty = 0;
temp.deltadistx = sqrt(1 + (temp.raydiry * temp.raydiry)/(temp.raydirx * temp.raydirx));
temp.deltadisty = sqrt(1 + (temp.raydirx * temp.raydirx)/(temp.raydiry * temp.raydiry));
temp.perpwalldist = 0;
temp.stepx = 0;
temp.stepy = 0;
temp.hit = 0;
temp.side = 0;
if(temp.raydirx < 0){
temp.stepx = -1;
temp.sidedistx = (temp.rayposx - temp.mapx)*temp.deltadistx;
}else{
temp.stepx = 1;
temp.sidedistx = (temp.mapx + 1 - temp.rayposx) * temp.deltadistx;
}
if(temp.raydiry < 0){
temp.stepy = -1;
temp.sidedisty = (temp.rayposy - temp.mapy) * temp.deltadisty;
}else{
tmep.stepy = 1;
temp.sidedisty = (temp.mapy + 1 - temp.rayposy) * temp.deltadisty;
}
temp.count = 0;
while(temp.hit == 0){
temp.count ++;
if(temp.sidedistx < temp.sidedisty){
temp.sidedistx += temp.deltadistx;
temp.mapx += temp.stepx;
temp.side = 0;
}else{
temp.sidedisty += temp.deltadisty;
temp.mapy += temp.stepy;
temp.side = 1;
}
if(this.map[temp.mapx][temp.mapy] > 0){
temp.hit = 1;
}
if(temp.count == 9999){
temp.hit = 1;
//maxlooplimit..?
}
}
if(temp.side == 0){
temp.perpwalldist = (temp.mapx - temp.rayposx + (1 - temp.stepx)/2)/temp.raydirx;
}else{
temp.perpwalldist = (temp.mapy - temp.rayposy + (1 - temp.stepy)/2)/temp.raydiry;
}
temp.lineheight = this.h/temp.perpwalldist;
temp.drawstart = -temp.lineheight/2 + this.h /2;
if(temp.drawstart < 0){
temp.drawstart = 0;
}
temp.drawend = temp.lineheight/2 + this.h/2;
if(temp.drawend >= this.h){
temp.drawend = this.h - 1;
}
temp.t = this.map[temp.mapx][temp.mapy];
temp.c = {0, 0, 0};
if(temp.t == 1){
temp.c = {1, 0, 0}; //Red for outside walls
}
if(temp.t == 2){
temp.c = {0, 1, 0}; //Blue for 2
}
temp.alp = 1;
if(temp.side == 1){
temp.alp = 0.5;
}
//DRAWWWW
new GuiBitmapCtrl("3D_R_"@temp.x) {
x = thiso.off[0] + temp.x;
y = thiso.off[1] + temp.drawstart;
width = 1;
height = temp.drawend;
bitmap = "block.png";
alpha = temp.alp;
red = temp.c[0];
blue = temp.c[1];
green = temp.c[2];
}
}
temp.rot = 0;
temp.ms = 0.1;
if(keydown(1)) temp.rot = -0.1;
if(keydown(3)) temp.rot = 0.1;
if(keydown(2)){
if(this.map[int(this.posx - this.dirx * temp.ms)][int(this.posy)] == 0){
this.posx -= this.dirx * temp.ms;
}
if(this.map[int(this.posx)][int(this.posy - this.diry * temp.ms)] == 0){
this.posy -= this.diry * temp.ms;
}
}
if(keydown(0)){
if(this.map[int(this.posx + this.dirx * temp.ms)][int(this.posy)] == 0){
this.posx += this.dirx * temp.ms;
}
if(this.map[int(this.posx)][int(this.posy + this.diry * temp.ms)] == 0){
this.posy += this.diry * temp.ms;
}
}
temp.olddirx = this.dirx;
this.dirx = this.dirx * cos(-temp.rot) - this.diry * sin(-temp.rot);
this.diry = temp.olddirx * sin(-temp.rot) + this.diry * cos(-temp.rot);
temp.oldplanex = this.planex;
this.planex = this.planex * cos(-temp.rot) - this.planey * sin(-temp.rot);
this.planey = temp.oldplanex * sin(-temp.rot) + this.planey * cos(-temp.rot);
settimer(0.05);
}

Would anyone have any ideas on how to make it look more realistic, maybe even texture/shading etc?

If I remove if(temp.count == 9999){
temp.hit = 1;
//maxlooplimit..?
}
I get: Script: Loop limit exceeded in function onTimeout in script of Weapon -Gunderak/3D

So guessing something isn't 100%..

EDIT: I was using this as a base and trying to convert it to GS2
http://lodev.org/cgtutor/files/raycaster_flat.cpp

Crono
08-17-2016, 05:47 AM
seems cool

Gunderak
08-17-2016, 05:58 AM
seems cool

Thanksss <3

I just can't get it to look right though :(

Gunderak
08-18-2016, 03:19 AM
Such improvements, much wow!
The walls still bug out when you are close, not sure why o.o
4PockpSEl0w
Just using the wolfenstein graphics as a placeholder for now.

Xerath
08-19-2016, 03:36 AM
What a beauty

Crono
08-19-2016, 03:56 AM
time to make graalenstein eh?

Gunderak
08-19-2016, 07:15 AM
https://i.gyazo.com/5a4818b46b4189ec4db21ed7759cc4ea.gif

Managed to implement the way the floors are done in Doom etc but since I can't access the image buffer it's wayyyyyy too slow to actually render a 1x1 pixel graphic for the floor and ceiling data, so for now just using a solid image.


Here is my floor logic if anyone has any ideas on how to make it not laggy, maybe I'm doing it a dumb way, not sure:


temp.floorxwall = 0;
temp.floorywall = 0;
if(temp.side == 0 && temp.raydirx > 0){
temp.floorxwall = temp.mapx;
temp.floorywall = temp.mapy + temp.wallx;
}else if(temp.side == 0 && temp.raydirx < 0){
temp.floorxwall = temp.mapx + 1;
temp.floorywall = temp.mapy + temp.wallx;
}else if(temp.side == 1 && temp.raydiry > 0){
temp.floorxwall = temp.mapx + temp.wallx;
temp.floorywall = temp.mapy;
}else{
temp.floorxwall = temp.mapx + temp.wallx;
temp.floorywall = temp.mapy + 1;
}
temp.distwall = temp.perpwalldist;
temp.distplayer = 0;
if(temp.drawend < 0){
temp.drawend = this.h;
}
for(temp.y = temp.drawend; temp.y < this.h; temp.y ++){
temp.currentdist = this.h/(2 * temp.y - this.h);
temp.weight = (temp.currentdist)/(temp.distwall);
temp.currentfloorx = temp.weight*temp.floorxwall + (1 - temp.weight) * this.posx;
temp.currentfloory = temp.weight*temp.floorywall + (1 - temp.weight) * this.posy;
temp.floortexx = int(temp.currentfloorx*this.texturewidth)%this.tex turewidth;
temp.floortexy = int(temp.currentfloory*this.texturewidth)%this.tex turewidth;
Gunderak_3D.drawimagestretched(temp.x, temp.y, 1, 1, "wolftextures.png", temp.floortexx+(64*6), temp.floortexy, 1, 1);
}

https://i.gyazo.com/e88d25d64e52a9184304bfc087d196b5.png
I mean, it works, but like 0.00005 FPS lol.

BlueMelon
08-23-2016, 04:46 PM
Nice! I think Dusty made something similar but for like a mario kart style minigame

Gunderak
08-24-2016, 02:51 AM
Nice! I like Dusty made something similar but for like a mario kart style minigame

Thanks! I was thinking just a minigame where you could see other players in the 3D world etc and kill them for fun, not sure where I am taking it at this stage, having issues with rendering sprites, the ZBuffer thing is confusing me.

swimdude
08-24-2016, 04:14 PM
Thanks! I was thinking just a minigame where you could see other players in the 3D world etc and kill them for fun, not sure where I am taking it at this stage, having issues with rendering sprites, the ZBuffer thing is confusing me.

would LOOOOVE for this to be its own thing on my server, maybe you can expand on it if you want, a small DOOM MMO via graal haha.

im a huge DOOM fan :p, hit me back. ill let you work on that project w my server.

Crono
08-24-2016, 07:47 PM
any projects or is this more of an experiment?

Gunderak
08-24-2016, 11:28 PM
would LOOOOVE for this to be its own thing on my server, maybe you can expand on it if you want, a small DOOM MMO via graal haha.

im a huge DOOM fan :p, hit me back. ill let you work on that project w my server.

I'm not sure if at this stage I'll disclose the full source, because it may get used still, and sorry no time, too busy working on Zone iPhone :D


any projects or is this more of an experiment?

It started as an experiment but not I'm thinking of taking it further, improving it etc and possibly making it into a minigame!

swimdude
08-25-2016, 07:04 AM
I'm not sure if at this stage I'll disclose the full source, because it may get used still, and sorry no time, too busy working on Zone iPhone :D




It started as an experiment but not I'm thinking of taking it further, improving it etc and possibly making it into a minigame!

yea ill pay you if they arent, if they arent then thats def a nono !pissed!

Gunderak
08-25-2016, 07:57 AM
yea ill pay you if they arent, if they arent then thats def a nono !pissed!

Bahaha, maybe one day, but tbh doesn't bother me, I work full time anyway so I get money from that.

swimdude
08-26-2016, 07:27 AM
Bahaha, maybe one day, but tbh doesn't bother me, I work full time anyway so I get money from that.

so humble i love it ;)

nice to see ppl still with some talent running around doing something different. keep us updated w this

Crono
08-26-2016, 07:58 AM
merge with zexon for true bomberman 3d

swimdude
08-26-2016, 11:25 AM
merge with zexon for true bomberman 3d

would be a fun adaption to the server :p crono a genius

Crono
08-30-2016, 09:19 AM
would be a fun adaption to the server :p crono a genius

i got plenty of (stupid) ideas