Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Raycasting V2 - Progress!!! (https://forums.graalonline.com/forums/showthread.php?t=134270353)

Gunderak 08-17-2016 04:36 AM

Raycasting V2 - Progress!!!
 
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/d9c6378a01a99e9c...f2a7450dbf.gif

PHP Code:

//#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.600;
  
this.400;
  
this.off = {screenwidth/this.w/2screenheight/this.h/2};
  
this.off = {5050};
  
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.0temp.2000temp.++){
    if(
isobject((@"3D_R_"@temp.i))){
      (@
"3D_R_"@temp.i).destroy();
    } 
  }
  
onTimeout();
}
function 
sqrt(n) { 
  return 
n^0.5
}
function 
onTimeout(){
  for(
temp.0temp.this.wtemp.++){
    
temp.camerax temp.x/this.-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(+ (temp.raydiry temp.raydiry)/(temp.raydirx temp.raydirx));
    
temp.deltadisty sqrt(+ (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 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 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 + (temp.stepx)/2)/temp.raydirx;
    }else{
      
temp.perpwalldist = (temp.mapy temp.rayposy + (temp.stepy)/2)/temp.raydiry;
    }
    
temp.lineheight this.h/temp.perpwalldist;
    
temp.drawstart = -temp.lineheight/this./2;
    if(
temp.drawstart 0){
      
temp.drawstart 0;
    }
    
temp.drawend temp.lineheight/2  this.h/2;
    if(
temp.drawend >= this.h){
       
temp.drawend this.1;
    }
    
temp.this.map[temp.mapx][temp.mapy];
    
temp.= {000};
    if(
temp.== 1){
      
temp.= {100}; //Red for outside walls
    
}
    if(
temp.== 2){
      
temp.= {010}; //Blue for 2
    
}
    
temp.alp 1;
    if(
temp.side == 1){
      
temp.alp 0.5;
    }
    
//DRAWWWW
    
new GuiBitmapCtrl("3D_R_"@temp.x) {
      
thiso.off[0] + temp.x;
      
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
PHP Code:

      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

Quote:

Originally Posted by Crono (Post 1739533)
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

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/5a4818b46b4189ec...d7759cc4ea.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:

PHP Code:

    temp.floorxwall 0;
    
temp.floorywall 0;
    if(
temp.side == && temp.raydirx 0){
      
temp.floorxwall temp.mapx;
      
temp.floorywall temp.mapy temp.wallx;
    }else if(
temp.side == && temp.raydirx 0){
      
temp.floorxwall temp.mapx 1;
      
temp.floorywall temp.mapy temp.wallx;
    }else if(
temp.side == && 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.temp.drawendtemp.this.htemp.++){
      
temp.currentdist this.h/(temp.this.h);
      
temp.weight = (temp.currentdist)/(temp.distwall);
      
temp.currentfloorx temp.weight*temp.floorxwall + (temp.weight) * this.posx;
      
temp.currentfloory temp.weight*temp.floorywall + (temp.weight) * this.posy;
      
temp.floortexx int(temp.currentfloorx*this.texturewidth)%this.texturewidth;
      
temp.floortexy int(temp.currentfloory*this.texturewidth)%this.texturewidth;
      
Gunderak_3D.drawimagestretched(temp.xtemp.y11"wolftextures.png"temp.floortexx+(64*6), temp.floortexy11);
    } 

https://i.gyazo.com/e88d25d64e52a918...c087d196b5.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

Quote:

Originally Posted by BlueMelon (Post 1739634)
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

Quote:

Originally Posted by Gunderak (Post 1739639)
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

Quote:

Originally Posted by swimdude (Post 1739646)
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


Quote:

Originally Posted by Crono (Post 1739647)
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

Quote:

Originally Posted by Gunderak (Post 1739648)
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

Quote:

Originally Posted by swimdude (Post 1739650)
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

Quote:

Originally Posted by Gunderak (Post 1739651)
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


All times are GMT +2. The time now is 06:51 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.