|
This thread is locked; no one can reply to it. |
1
2
|
Sprites in Raycasting |
Billybob
Member #3,136
January 2003
|
What in the world has my thread become! I'm dumb!. Uhhh, stop dis-ing OpenGL, cause that is what I'm using for my next "3D" project >8) First off, thanks for all the help, I think what I thought was correct and what you are telling me is making me think that what I thought about being correct in thinking what I thought was good. Get that? Got that? Good. My engine is not like Doom or Wolfenstien, it is an Advanced Raycaster much like the rex3D engine, but still a raycaster, just slightly different. I guess I'm off to go work up some code for rendering sprites Thanks for the help.
Let me run this math by ya and make sure its good. X is the offset of the sprite's center from the center of the screen. X = P * tan a and of course I can get the height scale of the sprite via my translation function used on the walls and I can use the ratio of the translated height and the real height to figure out how wide to draw the sprite. All that sound OK? It better be.
|
Thomas Harte
Member #33
April 2000
|
Quoted code: odistance=(int)(DIV_VIEW/sqrt((obj_x<i>-px)*(obj_x<i>-px)+(obj_y<i>-py)*(obj_y<i>-py))); oangle=RAD_TO_DEG(atan2(obj_y<i>-py,obj_x<i>-px))-pa; if(oangle<0) oangle+=359; if(oangle>359) oangle-=359; odisplayx=(int)(oangle/0.1875)+(SCREEN_W/2); stretch_sprite(front,object[0],odisplayx-odistance/2,100-odistance/2,odistance,odistance); I have various observations. First of all, I think you actually want this: if(oangle<0) oangle+=360; if(oangle>359) oangle-=360; e.g. the angle '360' is not the same as the angle '1'. So, odistance is the perspective projected size of a square tile in pixels, oangle is the angle between the centre of the view and the object. odisplayx=(int)(oangle/0.1875)+(SCREEN_W/2); You've picked oangle to be always positive, so your objects are always on the right hand side of the screen here. It strikes me that you might instead want the following: odistance=(int)(DIV_VIEW/sqrt((obj_x<i>-px)*(obj_x<i>-px)+(obj_y<i>-py)*(obj_y<i>-py))); oangle=RAD_TO_DEG(atan2(obj_y<i>-py,obj_x<i>-px))-pa; while(oangle<-180) oangle+=360; while(oangle>=180) oangle-=360; odisplayx=(int)(oangle/0.1875)+(SCREEN_W/2); stretch_sprite(front,object[0],odisplayx-odistance/2,100-odistance/2,odistance,odistance); i.e. you restrict your angle to the range [-180,179] rather than [0, 359]. You might be able to use 'if' rather than 'while', I'll let you think about that one! Quote: Let me run this math by ya and make sure its good. X is the offset of the sprite's center from the center of the screen. X = P * tan a I'm confused by P. If you've calculated distance from viewer to object and called this P then in your right angled triangle, you have one angle, and the hypotenuse and want to get the side opposite the angle, so you 'sin angle = opposite / hypotenuse'. Conversely if you want the side adjoining you use cos. If you have the adjoining side, which I guess you mean is P, then yeah: tan A = X / P Although I reiterate my claim from earlier in this thread that adding objects in a trigonometric manner is silly and processor expensive. [My site] [Tetrominoes] |
aybabtu
Member #2,891
November 2002
|
Yay!;D I attached a screenshot... |
X-G
Member #856
December 2000
|
Do you have to keep attaching .pcx files? You can't view them inline. It's annoying. At least make them .bmp ... -- |
23yrold3yrold
Member #1,134
March 2001
|
BMP is too big. PNG/GIF is teh win!! -- |
Thomas Fjellstrom
Member #476
June 2000
|
Use png's much better on the bandwidth. -- |
X-G
Member #856
December 2000
|
I said at least, since he's likely generating these screenshots via Allegro, which can't save gif/png without extra libs. -- |
23yrold3yrold
Member #1,134
March 2001
|
Yeah, but everyone should have a program for converting BMP's to a multitude of file formats ... -- |
X-G
Member #856
December 2000
|
In case he doesn't, I just want to express that even .bmp is better than .pcx, since .bmp can be viewed inline. -- |
aybabtu
Member #2,891
November 2002
|
I do have a program, but it's 'new' and takes over a minute to load up...it's so much easier for me (:P) to do it this way...but, from now on...I'll convert them to GIFs.:) |
Billybob
Member #3,136
January 2003
|
ewwww, CODE, I'm dumb!. Theories for me. I eat theories for breakfast, and sometimes for lunch. Well, I'm going to make my entity engine, and then I'll work on the sprite rendering code. If I run into problems with my theories then I'll check out code, heh. EDIT http://www.cljy.com/~billy/Sprite Theory.JPG
|
|
1
2
|