Updating a 2.5D game to graphics 2

OK so, I have scenery in and (mostly) working.

What helped most was moving the sprites’ X and Y to where I was setting the x1 and y1 values before (so leaving them at 0, 0) and making the remaining 3 points relative to that. More code, but it works!

Culling appears to be an issue though, as things vanish if they get too big, or if they go offscreen too much. This also leads to problems that I didn’t have before (not all the closest track sections are drawn now), but it solved others (far less culling when not needed, and things don’t vanish when you rotate in a certain direction).

Built and tested on ipad.

I was a bit optimistic - I set the draw distance to 300 meters (it was previously at 60!) and it ran at 60fps most of the time on the ipad 2, but not always. That was me being silly, I wouldn’t necessarily up the draw distance anyway, even 60 meters shows you plenty ahead (it feels further), and I need some CPU for AI etc :wink:

If corona gives me permission, I’ll testflight out the build to interested people. Not going to bother sticking up a video simply because the video at the top is close enough to what it looks like now, and framerate isn’t going to improve in the video as my comp is the limit!

@Corona guys - if you want to see the bugs, let me know, I can testflight you in or even send you the source code.

So, conclusions:

  1. There are still some bugs. Big wow on that one. Given this was marked as an alpha, I can’t say it has frustrated me with the bugs, there are fewer than I’d expect given the big undertaking that is graphics 2 :slight_smile:

  2. It *works*. No show-stopping bugs. To be honest the only problem is the culling, and that is all - if it wasn’t for that the demo would be running identically to what I had before (albeit a great deal quicker!).

  3. The implementation of the paths for me leaves a lot to be desired. Having path be a series of offsets doesn’t strike me as useful. I think it would be better to have it contain the actual image corners, which you can then modify directly. Needing to know the width and height of the image to position corners is absolutely horrible. This above all else is what I’d change as a design decision, as it is going to cause a lot of headaches in the future for people.

  4. Positioning the X and Y to the top left corner is also a pain, but I only had to do this because of culling bugs (and even then I only managed to minimise it). Hopefully this wouldn’t be necessary at the end, so I’m not going to lose any sleep over this.

The end result of this is instead of being able to do this, for example:
[lua] sprite.path.x1 = x1
sprite.path.x2 = x2
sprite.path.x3 = x3
sprite.path.x4 = x4

sprite.path.y1 = y1
sprite.path.y2 = y2
sprite.path.y3 = y3
sprite.path.y4 = y4[/lua]
I have to do something like this:
[lua]
local size = sizes[imageName]
local width = size.width
local height = size.height

sprite.x = x1
sprite.y = y1

sprite.path.x1 = 0
sprite.path.x2 = x2 - x1
sprite.path.x3 = x3 - x1 - width
sprite.path.x4 = x4 - x1 - width

sprite.path.y1 = 0
sprite.path.y2 = y2 - y1 -height
sprite.path.y3 = y3 - y1 - height
sprite.path.y4 = y4 - y1[/lua]
Cleary more code slowing stuff down, and a probable major hindrance for any generic 3D engine.

  1. I notice some jerkiness in the movement of the sprites when up close - am going to play a bit more later on to see if I am math.floor()-ing where I shouldn’t, or something else. Also going to disable the pixelated draw modes - just anything I can see that might cause pixels to misbehave.

OK I removed math.floor() and what-not and I am sure that the juddering is a bug with either graphics 2 or OGL, which means I’m naturally leaning towards G2 as I doubt OGL would have come this far with such a bug. Again, corona guys - if you are interested I can send the code and add you in testflight to see the actual problem - it is gonna be impossible to show it in a video.

I should point out (as I just noticed) that in the simulator I don’t see the jerkiness, only on the device.

One last point - I do now see sparklies amongst the track sections in the ipad (but not in the simulator). When I next have time I’ll see if they go if I math.floor() all the path coordinates, but for now I shall relax, I am quite pleased with how this went tonight!

For what it is worth (not a lot!) here is a terrible quality video (but it lets you see some of the culling bugs at least).

http://www.youtube.com/watch?v=MgkJ0fs2Kmw&feature=youtu.be

This is really really cool!

Would be great to get more info on your culling bug. Does it only happen when it rotates? Code would be great — preferably a stripped down project. 

I didn’t quite understand why you were basing everything off top-left — is this a workaround for the culling bug?

For the corner offset stuff, we can’t really make it actual values b/c we need to have a consistent origin, and anchor/ref points change that. Maybe having offsets expressed as percentages, e.g. ranging from -1.0 to 1.0 would make things more convenient? 

Hey Walter.

You can see the culling bug in the video. The trackside objects vanish before they are in front of my cull plane (basically when things get too close). You can see another way the culling bug kicks in in the video when I brake to a stop and move left and right - the nearer I am to the left edge of the road the less track sections that get culled (in fact if I stay at the left edge, it draws all the track sections correctly).

The reason I base everything off top left is for simplicity. While a sprite retains its square shape, things like width, height, rotation, offsets etc make sense, but when you can move any of the corners to where you want, this relationship begins to break down. For example, what is the angle of rotation of an image if I also rotate the corners arbitrarily?

That’s not to say these things aren’t useful but they are complimentary.

Anyway, bottom line is, when dealing with 3d calculations like this, you don’t think of each polygon as a seperate entity, but as part of a whole. So the easiest way to set things up is to position all the sprites at 0, 0 (top left of the screen) and just calculate all the coordinates of the various polygons together - that is to say, ey all use a common reference point or origin.
For whatever reason, the culling goes rather haywire, hence why instead of doing this I choose the top left corner (convenient because it is the first in order, and also the top left, ignoring massive distortions). However, that is likely to be unneccesary when the culling bug is fixed, so doesnt really worry me now.

The fact that the path is an offset is what concerns me.
For a system like this, where each sprite is a face you run into problems almost immediately. Anything but the most simple of 3d representations will require faces using different images. As my code shows (and it didnt show all of it) the difference between being able to specify the corners by pure coordinates, or having to do them via offsets based on the size of the source image is rather drastic - something that will certainly add up on the overhead per face and how many you can throw around.

For the origin method I proposed, the anchor point is also the sprite’s position - that is to say I place the sprite at 0, 0 and make the anchor 0, 0 as well. At this point, having spent only a few hours in graphics 2 I must admit I’m not quite following the reason for not allowing direct placement of the corners - my suggestion was that the path, instead of being offsets, would be the actual values of the corners (relative to the anchor and x y pos of the sprite). You could ‘easily’ make the path be the real values rather than offsets (ie fill them with the width and height of an image when created or you change frame), which would allow for easier and more direct control.

I understand the difficulties of using real values rather than offsets - it can cause problems if you change the frame of a sprite and the frame is a different size, but in reality what would be the expected result in this case? I think this sort of issue is far more likely to be relevant where people are arbitrarily changing the path and frame of a sprite and want to maintain the path between changes.

Now, having said that, I’ve not looked into the other uses of paths - errr polygons I think use them too? I will take a gander is week as time permits, but I don’t expect to find any anomolies there making offsets make more sense than actual coordinates, but any help in understanding this would be gratefully accepted.

I’ll sort out the code tomorrow I think - I’ll include the whole project but will chuck everything you don’t need to look at into functions at the end of the main.lua, and hilight where the nice bits happen. One question - where do I send this stuff soit gets to the right people?

Another thing, just to make sure I understood your comment. When I refer to actual coordinates, I am referring to them being absolute relative to the origin. Obviously if I set a sprite to 0, 0 ajd change the path, then add 10 pixels to its X value, the whole thing should move 10 pixels to the right :slight_smile:

“So the easiest way to set things up is to position all the sprites at 0, 0 (top left of the screen) and just calculate all the coordinates of the various polygons together - that is to say, ey all use a common reference point or origin.
For whatever reason, the culling goes rather haywire, hence why instead of doing this I choose the top left corner (convenient because it is the first in order, and also the top left, ignoring massive distortions).”

So I’m unclear on the above because you mention top-left in both the desired workflow and also in the workaround for culling.

“The fact that the path is an offset is what concerns me.
For a system like this, where each sprite is a face you run into problems almost immediately. Anything but the most simple of 3d representations will require faces using different images. As my code shows (and it didnt show all of it) the difference between being able to specify the corners by pure coordinates, or having to do them via offsets based on the size of the source image is rather drastic - something that will certainly add up on the overhead per face and how many you can throw around.”

In our model, each object is local/relative to the parent group, not absolute. Sounds like you want absolute coordinates? Maybe I’m not understanding, but this seems like a big departure from our model (graphics 1.0 and graphics 2.0)

“For the origin method I proposed, the anchor point is also the sprite’s position - that is to say I place the sprite at 0, 0 and make the anchor 0, 0 as well. At this point, having spent only a few hours in graphics 2 I must admit I’m not quite following the reason for not allowing direct placement of the corners - my suggestion was that the path, instead of being offsets, would be the actual values of the corners (relative to the anchor and x y pos of the sprite). You could ‘easily’ make the path be the real values rather than offsets (ie fill them with the width and height of an image when created or you change frame), which would allow for easier and more direct control.”

By default, the path is centered around the object’s origin (anchor defaults to 0.5,0.5). This is true for polygons as well. If you change, the anchor then the path is re-positioned. So in this case, offsets make the most sense.

Also, the offsets give us the flexibility to do an optimization where we could turn off 2.5D for objects that don’t use it. Not everyone uses it.

Sounds like you have a particular workflow in mind. I still don’t quite understand it, so hard for me to comment on specifics.

“I understand the difficulties of using real values rather than offsets - it can cause problems if you change the frame of a sprite and the frame is a different size, but in reality what would be the expected result in this case? I think this sort of issue is far more likely to be relevant where people are arbitrarily changing the path and frame of a sprite and want to maintain the path between changes.”

Can you give me a simple code snippet that demonstrates how this changes over a series of enterFrames? That would help me understand what’s hard about managing offsets.

Walter Ill try to find time to sort out some simple demos for you as soon as I can. I think we are gonna keep having a misunderstanding until I can show what I mean. Give me a day or so to work up some demos and possibly an image or two and I think we should be able to resolve everything :slight_smile:

Walter - I have the code for this demo waiting for you guys to look at, and have simplified it as much as possible (moved everything irrelevant into functions at the bottom of the main.lua, and highlighted where the ‘interesting’ bits happen).

Now, where do I send them to? :slight_smile:

Nice! Awesome job!

Awesome!

You can send to me: walter at coronalabs dot com. Attach, or send me a private link, etc.

Walter - files sent. Have fun :slight_smile:

I did include a longish discussion of the path value and how I feel the implementation is wrong, but of more concern for you I believe (as it is an actual bug) is the culling of images. Do a comparision of the old and new versions - it will become readily apparent where the errors are happening.

Oh that’s nice, it embedded the vid!

Corona is installed happily alongside my other versions, and I head over to the alpha docs. I was not impressed :wink:

So will have to download the fishies demo to see how to actually distort these wee images.

At least my original code actually runs in the new corona. Granted it looks like rubbish and there is distortion all over the shop, but it runs! I am guessing the distortion comes from removing the registration points, so my first task will be to factor this in and get it looking and running how it did before.

Immediately got caught out by the simulator only running properly on the first monitor - heart attack avoided!

Button locations fixed (x, y being middle now instead of left and top - not sure how I feel about this change yet. Well, I always hated top and left as the parameter names, but making them be in the center… guess I’ll get used to it).
Realised that if I don’t accelerate, I can move left and right without graphics going wrong. So yeah, the changing of image properties is what is making them go hay-wire.
Also - background colour was yellow not green. Fix = divide the RGB components by 255 to put them into 0-1 range. Easy!

Hmmm sprites are going a bit wrong. I am wondering if setting their width and height is not working properly…

OK given up on that since I believe I’ve encountered abug - so, direct to the quad things then, must look at the demo now!