Page 1 of 2

2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 5:40 am
by feral
this tutorial demonstrates a dynamic compass
compass.png


I have my 3D engine now working :) and over the next few days i will be posting a series of small tutorials which build the engine step by step.

I am not saying it is a good engine, but it does work, and is as effective as , if not more so , then wolfenstien
( you can walkthough - fly - jump etc etc).... it may not be the best but I hope it helps others

I have broken it down into several stages because each stage builds up to a useful individual concept, that can be used outside of the engine in other sorts of games.

The first small lesson is an easy one ( and I admit is not really my code) but it is essential to the entire engine to understand the concept ( and later use it to build the 3D engine) there are other ways to do the same thing, but this way is very neat!

also ...my code is probably not the best, so any advice is welcome

The first step simply uses a concept posted by kaladoff (i believe that was the first post on it ?- correct me if I am wrong)

see http://game-editor.com/forum/viewtopic.php?f=5&t=4600&st=0&sk=t&sd=a&hilit=circle

In this step we simply move a Compass to point in the direction the Actor is facing using the same code.

3dtut1.zip
first stage of a 3d tutorial - ged format
(164.38 KiB) Downloaded 544 times


- use left right cursor to turn
- up = forward
- down = backwward

In the next stage, we use the same concept to move the entire world around the player, then, we move onto 3d.


feral
(feralX3d)

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 7:46 am
by feral
Converting a 2d top down map to a virtual 360 degree world
360degrees.png

3dtut3a.zip
updated version - ged files
(57.78 KiB) Downloaded 404 times

UPDATED VERSION

EDITED>>
This is the first stage of building a 3d engine.

The general idea is to use a normal top down 2d map for the game engine, so all collisions/ movements / fighting etc etc all happen in the 2d world... this solves most maths problems as all activity happens in 2d, so only standard 2d programming skills are required. ( and routines like moveto_avoid work well.)

then every thing is transferred to a 360 degree playing surface where the player ALWAYS looks UP. (towards top of screen.)

now this "virtual 360 world" can easily be converted over to FULL 3D

you will now notice that all x coordinates are now to the left or right of player, and all y coordinates are to the top or bottom of player, therefore there is NO complicated maths required to convert to 3D :)

eg: if y is less then player it must be infront of him. this cannot be done in 2d if the player can turn around and all sorts of trigonometry would normally be required, so this step was originally meant simply to solve this problem.

However it also created a pretty neat engine for RPG's

Also note that the "360 world" is created on the fly by the engine and is "rotated" using the same method used in the "compass" example in tutorial 1.

NOTE: the zdepthing is only rudimentary at the moment and there are no enemies or collisions yet.

I wanted each stage of the tutorial to be easy to follow.


The keys are the same as in the previous post. use the compass to find your way

HOW IT WORKS SO FAR

Firstly, i have built a simple 2d map, but allowed the player to move in 360 degrees.

At the moment the map only has "obstacles", things like trees wall etc that should stop the player and enemies from moving, so only simple collision rules are required.

In order to apply the same collision rule to all obstacles i have made 1 single characters called "obstacles" and added several different animations to it. this way the same rules apply to all objects in this "class"

to create the "virtual 3d world" all "obstacles when "created" pass their x,y coordinates to an array

on create
virtualx[cloneindex]=x;
virtualy[cloneindex]=y;
// store x and y as virtual positions

Then during the "draw" process of each 2d object, all the coordinates are updated according to where the player currently is
virtualx[cloneindex] = dist*sin(degtorad(ANG-direction_angle))+player.x;
virtualy[cloneindex] = dist*cos(degtorad(ANG-direction_angle))+player.y;
//turn virtual x and y according to players direction

This does not effect anything on the original 2D map, so all game calculations can still be applied to the 2D map.

The next step is simply to convert the "obstacles" current animation to a 360 degree world and store it in an array ready to build the 360 world - this means, if the 2d obstacle is a "rock" then the 3d obstacles should also be a "rock" but in 3D

I do this by taking the existing name of the current animation in 2D and storing it in a string array ready to make the 360 world

I simply ADD the string "360" to the existing animation...

NOTE: this occurs during the DRAW routine of every obstacle clone. It could happen during the create process to speed up the game , but if any "obstacles" change animations during the game they would not be passed on.. for example if a "gate" opens , or a wall collapses..(this will be more use when we have enemies that die or change animations)

int persp=360; // this is the string to add to the end of the current animations name
sprintf(obstacles.text,"%s%d", getAnimName(animindex), persp); //gets the current animations name and adds "360"
strcpy(vscenerytype[cloneindex],obstacles.text); // copies the new name to a string array placeholder for that particular
clone.

NOTE: this means the animations in the 360 degree clones must all match the original names plus 360
--in the 2d world animation=rock
-- in 360 world animation =rock360

I could have done this simply with animindex but this means I have to make sure every animation is loaded in the SAME order in both worlds. But, this way they can be loaded in any order ( useful if you delete one and recreate it later which messes up the animindex)

Lastly, I create a single 360 degree obstacle Actor, and load it with all the xxxx360 animations ( remove 'create' at start up as you don't need this actor)
then in the create routine of the all the 2d sprites I make every "obstcale" create a seperate matching version of the 360 clone - one for each, and park them off screen.

CreateActor("obstacles360", "icon", "(none)", "(none)", 9990, 9990, true);

from here the game starts and all the 360 clones update themselves to the virtual coordinates, and change there individual animations to match the appropriate one using the premade "tables" of arrays. (the x,y, and animation string arrays), and then the 360 world is created. ( and updated during runtime automatically.)

Thats it for this stage. I hope that is not to long winded , if it is let me know and I will shorten it. or if something doesn't make sense.

the following tutorials will be much shorter as most of the main concepts have now been covered.

also let me know if this is boring people, or you want me to continue. I know some of this could be done different ways so any advice is welcome.

the next step is zdepthing the on screen actors, and walking under and through objects such as through doors and under big trees (things that are higher then ground level)

cheers
feral
(feralX3d)

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 10:48 am
by asmodeus
:shock: The first tutorial wasn't very great, but when I played the second... that was sooo cool!

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 11:12 am
by Fuzzy
I think the idea was that the first was simple so that people could see how it all progresses to a full game. Its a good lesson, +1 point for feral!

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 11:18 am
by feral
asmodeus wrote::shock: The first tutorial wasn't very great, but when I played the second... that was sooo cool!


yeah, i know the first was very simple, but the entire game engine is based on that simple piece of code... so i wanted to introduce it as a basic idea first.... :D

glad you liked the second one tho, will post more soon.

And, btw i just realised i had stuffed up on the turning circle of the player.. so it was very hard to move around properly.

I just did a quick update and reloaded the file, you should turn around OK now... not perfect, but i will fix that soon.

latest version of that demo is 3dtut3a.zip

cheers
feral

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 11:22 am
by pyrometal
This is very well done feral! I'll be awaiting the next installment of your tutorial even though I don't personally need this type of code at the moment. It just interesting to see what other people are making! ttyl

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sat Apr 26, 2008 12:54 pm
by makslane
Great!

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sun Apr 27, 2008 6:22 am
by feral
sorry not much of an update today as I have struck a problem :oops:

I have fixed the zdepthing

and added to more "classes" of objects - one you can walk over..(grass rocks etc)
and one that you will be able to walk under (unless you jump into it or fly into it later but i am still working on this :()

I have had a problem trying to figure out collisions ... so will need to work that out before i get back to this..
I posted a request in the support area if any one has any ideas..

also, as i have repeated a LOT of code, so, I may work on some "functions" before the next update

cheers
feral

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Mon Apr 28, 2008 12:16 am
by jwelch
This is awesome! +1 point for you!
Can we use the engine as a base for our own games?

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Mon Apr 28, 2008 2:06 am
by feral
jwelch wrote:Can we use the engine as a base for our own games?


Absolutely, anyone can use it. that is why I am trying to make the tutorials are easy as possible.

I am hoping when after I finish the final beta, that the whole GE community can jump in and help improve it, as a generic engine for other ge users.. if there is enough interest in it that is..

i am hoping that if there is enough interest in it, that after i have finished the actual engine, that i can start working on addon's such as mapmaker kits/mod building kits etc etc

cheers
feral

BTW: what is the point system stuff all about ? is there a thread i this ? cause i think I owe some people some points already :oops:

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Tue Apr 29, 2008 6:37 pm
by asmodeus
:D Here is a small 3d rally game made with feral's scripts. :D

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Tue Apr 29, 2008 6:57 pm
by pyrometal
wow, that's pretty awesome!

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Wed Apr 30, 2008 12:43 am
by Game A Gogo
this is amazing! nice work! +1

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sun May 04, 2008 12:49 am
by feral
I have a litte problem, in that i was about to upload the next tutorials when I discovered they were already way over 10mb

I am going to optimise some code and graphics etc,... and try again, but there may be a small delay, sorry.

in the meantime I have uploaded a partial (cut down) version of a true 3D demo using this engine, to the development section, just to show where all this is all heading to..

see http://game-editor.com/forum/viewtopic.php?f=4&t=5658



BTW: the piece of code I wrote earlier in one of the tutorials is completely unnecessary.
feral wrote:NOT NEEDED
int persp=360; // this is the string to add to the end of the current animations name
sprintf(obstacles.text,"%s%d", getAnimName(animindex), persp); //gets the current animations name and adds "360"
strcpy(vscenerytype[cloneindex],obstacles.text); // copies the new name to a string array placeholder for that particular
clone.

NOTE: this means the animations in the 360 degree clones must all match the original names plus 360
--in the 2d world animation=rock
-- in 360 world animation =rock360


at the time I thought GE needed separate animation names even if in separate actors..which is not true

all I really had to do is call the animation "rock" in the 2d world, and "rock" in the 360 degree world, and just use the same names in each 'world' - so that step is not needed - sorry about the confusion.

thanks
feral

Re: 2D to 360 degree to 3D Tutorial 1

PostPosted: Sun May 11, 2008 2:38 pm
by moonmoon
Great. I'm looking forward to this...