-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|422|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Graphical Engines


 
Jayenkai
Created : 06 January 2008
 
System : Windows
Language : Blitz

Basic 2D in 3D

Got bored, did something half-useful!

It's not the best thing in the world, but I started working on my month's workshop entry, this morning, and decided I wanted something a bit better than plain Blitz2D for a change.

So, rather than work directly on the game, first I decided to code one of those "2D in 3D Mode" engine things that you see everywhere.
You can download it here.

I tried to make things nice and easy to use, (so that even I could figure it out!!) so I just gave everything a .sprite type, and I'll let the user decide how to use everything.


It basically means that you can do the following to get a bunch of rotating, alpha enhanced sprites on the screen.



Be aware though, there's no collision! You'll have to figure out all your collisions on your own. Sorry!

 

Comments


Sunday, 06 January 2008, 08:25
Jayenkai
Here's a neat effect!

Creates a nice ripple/wave of color.
RightMouse to make a wave, LeftMouse to tilt the camera.


Monday, 07 January 2008, 02:59
Toaster
Hey this looks really nice cept for the neat effect doesnt work for me. All I see is a white screen. Also you shouldnt be using gosub's well I never use them try the function command instead i find it much more useful then gosub.

-Toaster
Monday, 07 January 2008, 04:28
Phoenix
Looking good Jay -- what use do you have in mind for it? Will there be lots of particles?

Also you shouldnt be using gosub's well I never use them try the function command instead i find it much more useful then gosub.


Can you explain why it's a bad idea?
Monday, 07 January 2008, 06:06
Jayenkai
I figured Particles would probably be better off left as a seperate "Drawn over the top" 2D layer.. I can get about 250 objects onscreen on my downstairs PC, and I typically use that as a low-spec testbed, so that's my limit. So particles would be better off as additional.

What I'd really like to use it for is rotations and transparencies that I occasionally think could be useful. True, I very rarely do use them, but.. I'm sure I can come up with a reason for them!


The gosubs were used because then I could be lazy and reuse variables without having to declare them at the top. It means the "Setup" bit, which has to be used in every program using this set of functions, consists of the following.



If I'd made it a function, then I would have to insert the following into every program, instead...



As you can see, I may as well have just not even bothered with the Setup command, ignored the whole idea of the function altogether, and just copy+pasted the code right into my game each and every time.

Gosub = Better

The "showroughframework" routine was additionally left as a gosub because I threw it in at the last minute, and didn't want to bog-down the main code with extra details just for a really rubbish framerate display. There are better ones out there!
Monday, 07 January 2008, 12:30
Toaster
Ah but if you wanted options for setting up the 2D3D thingy then it would be better to use a function. Like,



I dont know its just how I program maybe a gosub would be best but I think theres some memory crap with gosub? Maybe I am thinking of goto another function I avoid like the devil.

www.blitzbasic.com/Community/posts.php?topic=28860

Lots of agreements flying back and forth there..

-Toaster
Monday, 07 January 2008, 13:37
Phoenix
I think theres some memory crap with gosub


I doubt it -- if there was it would probably have been fixed many versions ago.

I hate to be a pain in the ass, but I also hate skepticism. To be fair though, I'll admit that I never use them myself. But, that still doesn't mean that Goto/Gosub should be avoided like the devil.
Monday, 07 January 2008, 13:50
Toaster
Well I know goto's hog memory and thats a known fact in every language and almost all programmers stay away from them.

They don't have a defined exit point or some thingy like that and its general considered messy code or "spaguetti" code.

blitzbasic.com/Community/posts.php?topic=21711

-Toaster
Friday, 06 February 2009, 05:21
9572AD
Huh? How are GOTO commands being programmed nowadays that they would hog memory? They should do nothing more than transfer program flow control to another memory location, AFAIK.
Monday, 11 May 2009, 09:14
Teasy
If the language (Blitz) is coded properly:
- GOTO should have the fastest executing time, as it's a simple jump instruction. There is no RETURN, so there should be no additional memory usage per call.
- GOSUB would do a similar thing to a FUNCTION call, except that GOSUB is faster. It's a simple jump with the ability to RETURN to the jump point, except FUNCTION supports variable/value input/output (parameters, returns, etc).
- GOSUB and FUNCTION can both be called recursively which will probably result in a stack overflow if done excessively, which is what I think some people here are referring to
Monday, 11 May 2009, 12:08
Afr0
GOTO and/or GOSUB should be avoided like the plague because they make your code harder to read and maintain.
Monday, 11 May 2009, 12:41
Phoenix
Goddamnit, what's up with all of the goto-pooping? They are a feature of the lanugage, just like any other, and should be used with care, just like any other. Gotos may be bad for your 10,000+ line team projects, but that's not quite what this is. Personally I've found goto to be very helpful when wanting to break out of nested loops.
Monday, 11 May 2009, 12:50
Jayenkai
My 2D-in-3D Engine kicks ass!!!!
Monday, 11 May 2009, 19:27
JL235
The problem with GOTO is that what you are doing is obscure. Are you building an if statement? Some kind of loop? Is it like a function call where you will goto back later? Or a custom branch (like Phoenix's example). That's why if there is a non-GOTO alternative you should always use it instead.

I've not tried this in BB, so this is purely speculation, but if you are able to jump in and out of functions with GOTO then the stack frames will need to be added/removed. So it wouldn't be a single jump statement.
Tuesday, 12 May 2009, 01:12
Afr0
What he said. ^
|
|
Tuesday, 12 May 2009, 02:54
JL235
To clarify, GOTO itself is not bad. It's just a jump, that's all.

I think it's the need for GOTO that is bad and a failing of the language. This is in the same way that design patterns have been considered a failing of the language. The design pattern itself is good!

That's why I think that if you have a good need to use GOTO, like a design pattern, then you should use it!
Tuesday, 12 May 2009, 05:03
Jayenkai
So, after a year and a half of this Goto crap, has anybody actually used this yet?

'cos I've been pretty much using this 3D engine as standard, lately.
Friday, 22 January 2010, 20:57
Teasy
The code is excellent, Jay.
I'm still easily disoriented by 3D stuff,
so I always rely upon someone else's base 3D code
for doing 2D stuff

But I just spotted something interesting:
The Sprite\Order you used as the Z in PositionEntity.
I would think EntityOrder can use that,
while the Z can stay 0,
so there's no distance/scaling probs.
(Unless you would want to use height difference ofcourse )
Saturday, 23 January 2010, 03:32
Jayenkai
Probably.. *shrugs*
I'm not very good at 3D, and the fact that this exists at all is pretty much down to pure luck
Saturday, 23 January 2010, 13:15
Teasy

Monday, 25 January 2010, 09:10
mindstorm8191
Wow, so much arguing about GOTO. Well, here's my two cents. GOTO is a very basic command, and doesn't hog up memory. GOSUB is also very simple, but with the option of returning to where you were. The only memory consumption it causes is to store the address where it was coming from. Both are very handy tools, when used in the right places.

As far as program flow goes, however, both aren't ideal commands to use. GOTO allows you to jump anywhere in your program, and if you're not careful, you'll end up needing to hunt down every GOTO destination in your program. Besides, there are more useful tools for controlling your program flow: loops and if statements are more flexible and provide very clear organization to your code. But used in moderation GOTOs can be a valuable thing to have. I had a complex nested loop strucure at one point, and finding the exit state was pretty deep into it all. Instead of obfuscating my code with all the steps needed to exit that loop, I used a GOTO to reach the bottom, and finished off the whole system.

GOSUBs can serve the same tasks as funcions, but functions provide more flexibility, IMO. Jay, you may not know this, but you can place your global declarations and type structures in your included file, and they'll work the same from there. You can then set your global variable values from the 'user' program file, and use them in your module function all the same. Then you could call it like this:
{code}
Setup2D3D
{\code}

Hope this helps!