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.

AppGameKit Classic Chat / Is it possible to invert the Z-Axis?

Author
Message
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 6th Jul 2018 16:08
I'm converting tile-based maps with an 0,0 origin in the northwest (upper left) corner into 3D objects and want to keep things such that a tile's 2D X, Y coordinates become 3D coordinates. However, when positioning objects, positive Z goes to the north and I'd like it to go south to match the tile map layout.

Aside from negating Z when positioning the objects, is there a way to alter the camera to have positive Z go south? I don't mind having to reverse rotations. That seems easier to remember than having to negate Z when switching between render coordinates and map coordinates.

Thanks
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 6th Jul 2018 21:29 Edited at: 6th Jul 2018 22:22
If you view from below (like 0,-5,0) and look at (0,0,0) then positive x goes to the right and positive z goes down the screen. Its just a case of camera positioning and setting appropriate roll values.

You can make X go to the right and Y go down the screen just by positioning the camera in positive z and looking back along the z axis with roll set correctly (180) too.


Personally I always make tilemaps appear as though they are in the XZ plane and viewed from above are correct so that involves reversing z when creating the objects but thats not too hard..


You could also set a negative scale for objects too using SetObjectScale but this reverses winding order of triangles so you have to set your backface culling appropriately to use that.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 7th Jul 2018 00:36
I'm converting the 2D tile map to 3D cube objects for a Wolfenstein 3D type engine, so viewing from above and below aren't going to work for this.

I hadn't thought of a negative SetObjectScale. I'll have to try that out. I hope it works with ObjectSphereSlide. Thanks for the suggestion.

I tried reversing left and right with SetCameraBounds and that does reverse the render, but objects disappear when they should be visible as I rotate the camera.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 7th Jul 2018 00:46 Edited at: 7th Jul 2018 00:47
Quote: "I'm converting the 2D tile map to 3D cube objects for a Wolfenstein 3D type engine, so viewing from above and below aren't going to work for this."


If its in 3D and based on cube objects then just use the negative Y position as the Z position of your cubes and it should work fine.

SetObjectPosition (object, x,0,-y)

When you view from above your map it will appear as though you looking down on your 2D tilemap. That keeps it nice and simple - no fudging the render
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 7th Jul 2018 00:52
I'm currently using -y for z, but I'm wanting to avoid having to negate y when going back and forth between map coordinates and render/camera coordinates. If I have to, then I have to and it's starting to look like I do.

SetObjectScale did not work as well as I had hoped.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 7th Jul 2018 01:07 Edited at: 7th Jul 2018 01:09
Could you just reverse the map as you load it? (reverse the Y's)

Then everything would work fine with no coordinate switching.

Id be happy to do an example using a tilemap tool which then loads up a map as cubes of the tiles with a roof and floor added on....3 layers (floor, walls, roof) and just reverse Y as it loads and sets up the cubes)
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 7th Jul 2018 01:40 Edited at: 7th Jul 2018 01:41
I have the tilemap set up as a multi-dimensional array using, so I can't use negatives for the indices.

I'm using Tiled as the editor and already load up the layers from the TMX file using the -y for z. I was just hoping to make things a little easier for down the road so I don't have to remember that z is the "exception" and always needs to be negated.

I have a project using libgdx which also uses OpenGL and I somehow set it up such that positive Z is south, but for the life of me, I've looked over that code and don't remember how I did it. lol

Appreciate the offer of coming up with an example, but I do have something that works. I'm just seeing if I can make it easier.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 7th Jul 2018 01:52 Edited at: 7th Jul 2018 01:58
Quote: "I have the tilemap set up as a multi-dimensional array using, so I can't use negatives for the indices."


lol...I dont mean use negative indices (that certainly wont work)

I mean write a small function to reorder all the array values so the y values are reversed

So for example (2D 3x3 array but this works in 3d too as layers)

1,2,3
4,5,6
7,8,9

becomes

7,8,9
4,5,6
1,2,3

There is even the .swap() function for arrays so you could swap the y values in place without remaking the array. just iterate through the loaded array and swap everything in the Y direction

Load your map...Call a ReverseMapY() function on the array and use it with no conversion ??

Quote: "I have a project using libgdx which also uses OpenGL and I somehow set it up such that positive Z is south, but for the life of me, I've looked over that code and don't remember how I did it. lol"

Yeah, Direct X uses +ve z as south too and its frankly just a simple change in the projection matrix to switch between the two but we cant get to set the projection values in AGK. Not to mention it would probably cause culling issues as well as issues with stock shaders

Anyway, sounds like your ok with it.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 7th Jul 2018 03:39
Quote: "but we cant get to set the projection values in AGK"

I've been toying with https://www.appgamekit.com/documentation/Reference/3D/SetCameraBounds.htm which can alter the projection matrix (off centered or centered).

Based on some code found in the forum:

Then change the culling and make turning rotate in the opposite amount. The image is flipped vertically and going south is a positive Z, but sometimes objects disappear when they should be visible and I don't know why. If I can figure out the mystery of the disappearing objects, I'm set.

This project is with AppGameKit for Python, but I'll see if I can whip up something simple with Tier 1 and duplicate.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 7th Jul 2018 10:05 Edited at: 7th Jul 2018 10:09
lol...yeah...thats my code your (ab) using. SetCameraBounds() only sets a small part of the full 4x4 projection matrix and is designed to do it using z into the screen



Objects are most likely dissapearing as they will be outside the depth buffer or are getting culled as AppGameKit calculates them as behind the camera.You would have to reverse your far and near values which you cant in agk. If we could fully set all the projection matrix values then it would work but it would most likely break alot of the functionality that relies on a consistant set of axis directions.

You could try SetObjectScreenCulling(obj, 0) for all the cubes but looking at the math I doubt it would work to get them to draw properly. (most likely would be other issues too)

One option is to use a shader for the cubes which reverses the z value in the model or view matrix and assign it to the cubes.

Personally.....id just lay the cubes out by reversing y values.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 7th Jul 2018 17:09
@Bengismo: Thanks for posting that code in the other thread. The help for SetCameraBounds is really lacking.

I've also come to the conclusion that they disappear because of they are considered behind the camera by AppGameKit as well.

Thanks for your information and help. I was hoping I could avoid negating y everywhere, but it looks like that's not possible with AGK.
Lance
20
Years of Service
User Offline
Joined: 22nd Jul 2003
Location: Third planet from Sun
Posted: 7th Jul 2018 18:34
Look at this thread . It uses Tiled and converts it to 3D .

https://forum.thegamecreators.com/thread/221520
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 7th Jul 2018 23:10
@Lance: Thanks, but I already have code for doing that. I was just hoping to simplify the switching between render space coordinates and tile map coordinates because I was getting a bit tired of Z being a special case.
What I was wanting to accomplish doesn't appear to be possible with AppGameKit at the moment.

Another thought based on Bengismo's idea of rolling the camera would be to face +X with a roll 90, but that mangles all the coordinates and makes using rotation angles more complicated.

Sticking with Y => -Z => Y looks like the best/only option for me.
puzzler2018
User Banned
Posted: 7th Jul 2018 23:14
cant you just put - on the z
puzzler2018
User Banned
Posted: 7th Jul 2018 23:16 Edited at: 7th Jul 2018 23:19
give me some simple working code to work with what results you want to try to acheive

I understand code rather than grammer

Talking too much can sometimes get way off the subject at hand

Send some code and what your wanting to achiive with it
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Jul 2018 23:27 Edited at: 7th Jul 2018 23:28
if your tiled map y locations are between 0 and 200 then your 3d z location would be 200-x
just need to add any offsets
fubar

Login to post a reply

Server time is: 2024-04-25 21:45:40
Your offset time is: 2024-04-25 21:45:40