Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / General 3D Experiments...

Author
Message
Patriick
4
Years of Service
User Offline
Joined: 8th Jul 2015
Location: London, United Kingdom.
Posted: 9th Jul 2015 15:21 Edited at: 10th Jul 2015 02:02
I haven't used AppGameKit or AGK2 before and I don't intend on spending all of my time in it, but I picked it up in the Humble Bundle and I'd like to play about in my lunch breaks and spare time with a few things.

I know that this is primarily for 2d related projects (for the time being) due to the fairly limited 3d side of this tool, but I'd like to play about with the 3d anyway as I have some really interesting ideas for how I could create something entertaining in 3d without the use of any real animations outside of tweening things anyway.

I will get stuck with things, I might not be doing things the best possible way, but that is why I am making this post. I haven't found very many examples of using AppGameKit for 3d at all and it doesn't appear that many are trying to do much with it (at least publicly anyway) so I want to post my struggles and findings here for others looking to delve into the 3d aspects, if for nothing more than just a little fun or education purposes.

I am going to be using Tier 1 for all of this and my 'BASIC' knowledge is really limited going into this.

I don't know how often I can update this due to my active game development project with UE4, but I'll eventually make some videos when I learn some more and if I don't struggle too much I'll even enter the Indie game contest with my 3d sample game.

3D Experiments 01
The first objective here was to load an object with a texture and rotate it in the Y axis with the object scaled up for viewing purposes. Nice and simple, no over complications kind of like an advanced "hello world" of 3d with AGK2 I suppose you could say.

This is all from scratch based on whatever I can find in the documentation sections of AppGameKit on the website. I compiled a guide on Steam regarding this first Experiment: http://steamcommunity.com/sharedfiles/filedetails/?id=478258116

The Code:


The Explanation:
Quote: "// set window properties
SetWindowTitle( "3D Experiments 01" )
SetWindowSize( 1024, 768, 0 )
setclearcolor (30,60,30)"

Nothing special here, but I did add something... "setclearcolor" the rest comes as default when you start a new project. I added this because upon my first couple of attempts I was having a small error loading a texture onto the model although there were no compile errors, and I couldn't tell if the model was loading or not and I generally wanted to just change the colour to play it safe with being able to tell things apart anyway. There isn't anything special with the properties attached either. "setclearcolor (30,30,60)" is just "setclearcolor (R,G,B)" and I randomly chose numbers just to give things a change from black.

Quote: "//set textures
testTex1 = loadImage("testimg.jpg")"


Now as far as I understand this, we have to load in the texture and give it a name before we can apply it to anything like the model that we load in later... So what I did was, I stole a texture from the single 3d example provided with AppGameKit which was "mesh28-0.jpg" located in the media folder of that example (comes with your installation) and I chose to rename it and give it a simple name for testing.

Quote: "//load model and set texture to it
mesh1 = loadObject ("mesh-pCube1.obj")
setobjectimage (mesh1,testTex1,0)"

Here is where we load in the model with 'loadObject' where the object is placed into a 'media' folder within the project directory. If you want to be better organised you can also just create another folder for models and call that, like so: "models/mesh-pCube1.obj" as the media folder is the default location so you only declare your sub-folders and files within that folder. So we also have to give the model a name as an objectID so that we can refer to it within the code later and use that ID when we tell the code to place our loaded texture onto the model, I chose a simple "mesh1" for now. Also all I did was export a basic cube primitive from my preferred 3d software package for the model. So nothing special there.

Then I set the texture to the object by calling the object and then the texture that I loaded.

Quote: "// position camera
movecameralocalZ (1,15)"

For viewing purposes I moved the camera with this...

Quote: "// rotate objects
RotateObjectLocalY(mesh1, .4)"

Within the do loop I placed the code to rotate the object slowly to see the texture all around the mesh. As you can likely tell it rotates on the Y axis, then you define what rotates, for this instances it's the model that we loaded in earlier followed by how fast it rotates. I chose a .4 for that for no reason other than it wasn't too fast or too slow.

3D Experiments 02
My second objective would be to cycle through all models within a sub-directory of the media folder and load all of those in with certain textures applied to various models in a semi-modular way. For instance... I create a wall and placement of the wall in my 3d software, export them all and load in only one texture instance but apply it to multiple wall models. The only reason I am going to go that route is because I have no idea how to efficiently use the cloneObject command to make an instance of the model but use the placement I create within my 3d software, as right now it seems pretty limited as far as laying out a level in 3d with AppGameKit goes.

Not too much more complex but a nice progressive step compared to just loading a simple textured 3d object that rotates on screen... **This experiment is a work in progress**

The Code:


The Explanation:
I looked over the 3d example provided with the AppGameKit installation and stole some code after figuring out what everything did thanks to the documentation and I also went along and stole another texture from the media folder just to experimenting rapidly...



As you can see in the image, there is a little issue with the wall texture applying to the floor, but that is something I knew would happen due to a very small user error when I was creating the tile pieces in my 3d software, and naming on export... So let's just ignore that mishap for now because it's a tedious fix for what it's worth.

Quote: "// position camera
movecameralocalZ (1,15)
movecameralocalX (1,-.8)"

Just because I am a little OCD with things I manually adjusted the camera for a better view by slightly offsetting in the -X axis. Nothing big or impressive there though.

Quote: "gosub _load_Objects"

gosub as I understand allows you to tell the code to hop to a later portion of the code and in this instance I took a page out of the example 3d code provided and altered it to fit what was required after looking it over and reading through the documentation.

Quote: "_load_Objects:
objmax=24
for obj=1 to objmax
obj$="models/mesh-pPlane"+str(obj)+".obj"
LoadObject(obj,obj$,0)
if obj>=16 and obj<=24
tex$="textures/wall.jpg"
else
tex$="textures/floor.jpg"
endif
teximg=LoadImage(tex$)
SetImageWrapU(teximg,1)
SetImageWrapV(teximg,1)
SetObjectImage(obj,teximg,0)"

So, where we're going to be cycling through models within a sub-directory of the 'Media' folder we set a maximum, which I've used the amount of obj files in the folder as the max count, that you can see at objmax=24.

Quote: "
objmax=24
for obj=1 to objmax
obj$="models/mesh-pPlane"+str(obj)+".obj"
LoadObject(obj,obj$,0)"

Where my mesh exports from my 3d software were named mesh-pPlane we define the first section of the name and use "obj=1 to objmax" to say "add 1 to the srting (file name) before adding .obj to the maximum count of 24." at least this is how I understand the code in simple explanation terms. Then we take that and load the objects into the scene.

Quote: "if obj>=16 and obj<=24
tex$="textures/wall.jpg"
else
tex$="textures/floor.jpg"
endif"

Now this part I love... This is just using what we created before to cycle through the objects and load them into the scene but to define which texture is loaded to which object. Essentially saying this but in code "if the model number (the obj string) is equal to or greater (>=) and if the model number is equal to or lower than 24 then we use the wall texture, but if not, then we apply the floor texture"

Quote: " teximg=LoadImage(tex$)
SetImageWrapU(teximg,1)
SetImageWrapV(teximg,1)
SetObjectImage(obj,teximg,0)
next obj"

The next part is just loading the image defined with tex$ into the scene and applying to the objects. Followed by next obj to cycle through.

So far so good!! I don't quite know if I will have time to a third experiment today, but it has been fun so far just playing around, it's sad there aren't more examples for both 2d and 3d though... Hopefully the recent Humble Bundle may change that with a mass of users flowing in.

-----

Please if any of you more experienced members out there have any advice regarding how I am going about things in my code, please make suggestions with explanations and not just code snippets of what is better, it's best if you can educate myself and others who may view this on why the suggested edits are better.



Kind Regards,
Patrick.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Jul 2015 17:45
Welcome

It looks like you've made a good start, especially reporting what you are doing/have done. The first posts by new members are usually questions

What you are doing all looks good. I always say keep it simple, and add optimisations later when you understand the language and your own goals more clearly. Loading multiple models and one texture seems like the next logical progression in your experimenting.

Many people here came from the predecessor DarkBASIC Professional which was a fully fledged 3D language. So at the moment we feel slightly restricted, but 3D is being implemented right now. In the meantime, lots of us switched to 2D and realised it's actually just as much fun.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Patriick
4
Years of Service
User Offline
Joined: 8th Jul 2015
Location: London, United Kingdom.
Posted: 9th Jul 2015 18:37
BatVink wrote: "Welcome

It looks like you've made a good start, especially reporting what you are doing/have done. The first posts by new members are usually questions

What you are doing all looks good. I always say keep it simple, and add optimisations later when you understand the language and your own goals more clearly. Loading multiple models and one texture seems like the next logical progression in your experimenting.

Many people here came from the predecessor DarkBASIC Professional which was a fully fledged 3D language. So at the moment we feel slightly restricted, but 3D is being implemented right now. In the meantime, lots of us switched to 2D and realised it's actually just as much fun."


Hi, thank you for the welcome message!

I've had a little fun with AppGameKit so far, I'll definitely have to play about with creating some kind of simple 2d game over the next weekend (not this one coming up) and see how that goes.

I understand how it feels with the limitations yeah, it's clear that it's not quite ready for full on 3d developments just yet, but I really am happy to see even this simple implementation of 3d so far, it allows us to just experiment and play about, and actually there is a great deal that you could do without using animated models or really in-depth 3d features, with just these basics from the documentation that I've seen. I feel like once I get to grips with the language a little more in time I could really create something entertaining and enjoyable, of course it'd be in the style of a turn based movement style of game with tweening for the shortage of animation support, but things are currently possible generally speaking.

Not that I intend to go that route, it's far beyond what I would be capable of right now and what I have the time to invest in learning how to achieve right now.

I am looking forward to the future developments of this little software though, it's pretty nifty and I like it.

I've just updated the post with Experiment 02. Is there any way that I can get pushed out of the probationary period of being a new member here(?) I've been moved out of that probationary thing on the FPSC Reloaded/GameGuru forum previously.

Regards,
Patrick.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Jul 2015 22:29
Quote: " Is there any way that I can get pushed out of the probationary period of being a new member here(?)"


It's a law unto itself. Only the inner sentinels of the Forum know how it releases you from probation purgatory. It doesn't take long though.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2019-07-23 09:54:46
Your offset time is: 2019-07-23 09:54:46