SFML community forums

General => SFML projects => Topic started by: Hapax on December 02, 2014, 09:45:16 pm

Title: Faux Car
Post by: Hapax on December 02, 2014, 09:45:16 pm
(click to show/hide)



Intro

It may be obvious to some that I've become interested in faux/fake/pseudo 3D. I think it shows in the Spinning Card (http://en.sfml-dev.org/forums/index.php?topic=16388.0) class that I created. I began to investigate more pseudo 3D usage and stumbled upon the old car games that used it.

I felt the need to attempt to see if I could also make this pseudo 3D track effect - using SFML, obviously!

Faux Car is what I came up with.

I'm not sure if I'm going to turn it into a complete game yet, but I do intend to evolve it.

The altitudes and positions are calculated using perspective algorithms but all turns are fake. There are no technically no rotations. Bends are simply accumulations of offsets.

I'm willing to discuss the code and show parts of it too. It's a little impractical to show it all; it's in many files and is reliant on my own library (full version of Hx).

Version Info

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Faux Car
Post by: achpile on December 02, 2014, 10:35:02 pm
CHAAAAASE HQ  ;D I love this game  ;D
And I love the preudo 3D (when I was 13, I wrote a maze game in QBasic with pseudo 3D graphics and first person camera view)
Title: Re: Faux Car
Post by: Hapax on December 02, 2014, 11:15:56 pm
Added video  :)

http://www.youtube.com/watch?v=dTreP5FehaI
Title: Re: Faux Car
Post by: Hapax on December 03, 2014, 12:01:09 am
Here's a runnable (playable?) version for you to try:
http://www.mediafire.com/download/3jbzd9w2ttuie53/Faux+Car+v0.0.2+first+tests.zip
It's Windows only, sorry  :(

Controls:
Up/down: accelerate/brake
Left/right: steer (left + right holds steady)
=/-: change speed of time
+/- (numpad): move forwards/backwards by one segment
0 (zero on numpad): reset car (reset track position, speed, steering, and horizontal position)
Title: Re: Faux Car
Post by: MiShu on December 03, 2014, 08:07:14 am
Nostalgia ... Just remember "Top Gear" :)
Title: Re: Faux Car
Post by: AFS on December 03, 2014, 07:52:12 pm
Nostalgia ... Just remember "Top Gear" :)

Oh man, Top Gear 2. I have fond memories of playing this game with my brother when I was a kid. Also, dat music.

http://www.youtube.com/watch?v=Ye-bPvKM7Ac


Anyway, interesting project, Hapax, hopefully it evolves into something great... like a Top Gear remake :P
Title: Re: Faux Car
Post by: Jesper Juhl on December 03, 2014, 08:06:17 pm
I loved Lotus Esprit Turbo Challenge (http://en.m.wikipedia.org/wiki/Lotus_%28series%29#Lotus_Esprit_Turbo_Challenge) when I was a kid. This brings back good memories.
Nice work Hapax.
Title: Re: Faux Car
Post by: ChronicRat on December 03, 2014, 08:17:12 pm
I loved Lotus Esprit Turbo Challenge (http://en.m.wikipedia.org/wiki/Lotus_%28series%29#Lotus_Esprit_Turbo_Challenge) when I was a kid. This brings back good memories.
Nice work Hapax.
Lotus III: The Ultimate Challenge - my favorite. It is ideal! =)
Title: Re: Faux Car
Post by: Cirrus Minor on December 04, 2014, 11:35:50 am
It looks very good, Hapax !
I've downloaded it, but I cannot try (MSVS libs are missing)  :(

My favorite pseudo-2D racing game was Death Track (but it was First Person view).
(click to show/hide)
Title: Re: Faux Car
Post by: marchred on December 06, 2014, 12:10:58 am
awsome O_o

PS : what about a minimapor something to peek what's next  ?
Title: Re: Faux Car
Post by: Dark2Dragon on December 08, 2014, 01:24:41 pm
F-Zero!

(http://wiiudaily.com/wp-content/uploads/2013/02/f-zero_gameplay.jpeg)

I love this game  ;D


Great work!
Title: Re: Faux Car
Post by: Hapax on December 09, 2014, 12:27:01 pm
Thanks for the kind responses! I always appreciate feedback  :)

I've downloaded it, but I cannot try (MSVS libs are missing)
I don't know what this means or how to fix it. I assume MSVS means Microsoft Visual Studio but I don't know why it should require Visual Studio. Any suggestions?

what about a minimapor something to peek what's next  ?
This is a HUD element for a game. I'm not even sure if I'll be making this into a game. I probably should but who knows?  ;D
The track (up to about position 2000) is created from a couple of sine waves so the corners alternate equally right then left  ;)
I've added a track position marker to the latest version so at least you'll easily know how far you are from the end...

F-Zero!
Looks like fun but I have to say that the track looks like it's "actual" 3D  :P
Title: Re: Faux Car
Post by: Hapax on December 09, 2014, 12:31:13 pm
I improved this somewhat and added road-side objects. This became a technical nightmare because of the way I was drawing the road in segments. To get the objects to appear behind the road (when over a hill), I had to integrate them with the road into a single vertex array. Texture smoothing was also required as the scaling looked terrible without it.

The images used for the objects are random (as are their colours and transparency) from a random tileset which, again, I found online. It was downloaded from here (http://www.psalgo.com/boards/phantasy-star-ii-town-map-tiles-vt5580.html). I use a modified version of that tileset (I added to it).

Here's an image at the starting line, showing how the objects look:
(http://i.imgur.com/kGYyuqB.jpg)

This is also at the starting line but using the alternate "first-person" camera:
(http://i.imgur.com/IUHQKok.jpg)

A little bit into the track and it shows that the track and objects can even be seen from a following corner:
(http://i.imgur.com/Gkwy0L4.jpg)

Some tweaks have been made here and there, including adding extra controls. F1 now display all the controls available.

Here's a more recent video:
http://www.youtube.com/watch?v=ZCn05Lgudvk

The first-person camera is still broken, as you can see in the video. I haven't paid enough attention to it.

I wanted to texture the road but I hit that age-old problem of not being able to stretch textures of a quad equally. I really should investigate how to use shaders as I believe that I need a bilinear filter shader. I may be way off the mark but that's what it looks like I need  :P
I might just stick with plain coloured polygons for the road...

Here's the Windows download for this version:
http://www.mediafire.com/download/pbdt3fidkd7vr1t/Faux+Car+v0.0.5.zip
Title: AW: Re: Faux Car
Post by: eXpl0it3r on December 09, 2014, 12:38:10 pm
Nice project! :)

It looks very good, Hapax !
I've downloaded it, but I cannot try (MSVS libs are missing)  :(
You most likely need to install the VS redist which can find over at Microsoft's website.
Title: Re: Faux Car
Post by: Hapax on December 09, 2014, 12:46:49 pm
Thanks  :)

Does it need to be a specific version of the redistributable depending on which version I used?

EDIT: It looks like it matters so I'm going to include a link to the redistributable (in the original post).
Title: Re: Faux Car
Post by: Cirrus Minor on December 10, 2014, 08:37:47 am
Hi !
I've tried again. So we need the 32 bits version of Visual C++ Redistributable Packages for Visual Studio 2013 in your link to launch it, and then it crashes with this error:
(http://img4.hostingpics.net/pics/748599cons.png)

Hard coded path ?
Title: Re: Faux Car
Post by: Hapax on December 11, 2014, 12:48:40 am
Looks like it, yeah. I start tests using a pool of generic resources available globally and then copy them locally if I decide to keep on using that generic stuff. Fonts are pretty generic :D. Obviously, I had forgotten to update this path to the local one. Sorry about that  :(
I'll rebuild it tomorrow!
Looks like you're the only person who had this problem so you must the only person that has tried it, so thank you for giving it a go  ;D
Title: Re: Faux Car
Post by: Ixrec on December 11, 2014, 12:56:54 am
I tried it the other day and got that same error, but something distracted me and I forgot to report it. =(
Title: Re: Faux Car
Post by: StormWingDelta on December 11, 2014, 02:56:20 am
If you want to make your own fonts I'd try here: http://fontstruct.com/ . Might help get around generic resource errors like this.  Also my teacher found this one for sound effects: http://www.bfxr.net/ .
Title: Re: Faux Car
Post by: fulldizimcik on December 11, 2014, 03:18:57 pm
thnaks very good ;)
Title: Re: Faux Car
Post by: ChronicRat on December 11, 2014, 08:23:29 pm
If you want to make your own fonts I'd try here: http://fontstruct.com/ . Might help get around generic resource errors like this.  Also my teacher found this one for sound effects: http://www.bfxr.net/ .
What a cool sites! Thanks!
Title: Re: Faux Car
Post by: santiaboy on December 11, 2014, 10:46:01 pm
This is really cool! The acceleration and skidding sounds really remind me of these types of games!
Title: Re: Faux Car
Post by: Hapax on December 12, 2014, 02:13:28 am
Thanks :)

Here's the fixed download:
http://www.mediafire.com/download/pbdt3fidkd7vr1t/Faux+Car+v0.0.5.zip
Let me know what you think!

If you want to make your own fonts I'd try here: http://fontstruct.com/ . Might help get around generic resource errors like this.
The problem here is not that it's a generic resource but that I re-use resources during testing (this is still just a test project). I then only move to a local location as it progresses and I need customised resources, and/or if I'm distributing it. If I'd've created a new font, it'd probably be stored in the resource pool, ready to be used by all of my projects and I therefore would've still forgotten to alter this path ;)
Title: Re: Faux Car
Post by: Hapax on December 17, 2014, 11:44:44 am
Worked a little on the way it looks, tweaked a few more things, and added a few things.

Latest version has 3 cameras, road markings, basic background scenery, (adjustable) fade as the track and objects get further away (toggle-able), cruise mode (automatic drive), ability to reset the car back to the centre of the road, ability to show/hide the testing feedback information, basic scoring mechanism, and instant skip-to-end.

The current default camera (camera 1) is the behind the car. Camera 0 is more of a first person/on-car camera. Camera 2 is much higher up and more road is visible. However, their are not any dedicated car sprites for that camera 2's view so they're stretched and red.

Here's a couple of images of what the latest version looks like (click to see full size):
(http://i.imgur.com/uXLf7oG.jpg) (http://i.imgur.com/uXLf7oG.jpg)
(http://i.imgur.com/qzt04p4.jpg) (http://i.imgur.com/qzt04p4.jpg)

New windows binary
http://www.mediafire.com/download/6xxq9il4ljq97j1/Faux+Car+v0.0.8.zip (zip file: <4MB)

New resources
The car sprites are (quickly) custom edited from a video of a spinning 3d model of a car, found here (http://vimeo.com/88361152). The grey at the bottom is shadow that wasn't masked out.

The background scenery is cut from this photograph (http://4.bp.blogspot.com/-K6l0zfQP_Mc/TlBr32M0P-I/AAAAAAAAAqU/Xhiz51GeBlg/s640/SD44+2.JPG) - which is from this page (http://bonnevillesaltflats2011.blogspot.co.uk/) - and edited to tile. It was also scaled inside the program so it's quite pixelated.

The tree scenery sprite sheet (3 trees) was found here (http://forum.zdoom.org/viewtopic.php?f=3&t=15080&start=6330).

EDIT: Just updated the binary to fix that horizontal line across the scenery. The scenery is also now smoothed which helps it look further away/out of focus.
(http://i.imgur.com/0ziEAJZ.jpg) (http://i.imgur.com/0ziEAJZ.jpg)


Just as an aside, I'd like to mention that the new binary was compiled using the new SFML 2.2!  ;D
Title: Re: Faux Car
Post by: select_this on December 17, 2014, 12:40:36 pm
It's looking pretty good :) Reminds me of the many, many hours I spent playing the Outrun arcade game as a kid.
Title: Re: Faux Car
Post by: Tank on December 17, 2014, 01:56:37 pm
Really nice work. :)
Title: Re: Faux Car
Post by: Cirrus Minor on December 19, 2014, 01:02:27 pm
So, I've tried it.
The last version is cute, you really should make a racing game with this engine!
The annoying point is that, most of the time, we don't see far enough to know where we have to turn, but it's just a demo, I know :)
Good job!
Title: Re: Faux Car
Post by: Hapax on December 19, 2014, 02:04:08 pm
Thanks for the feedback!  :)

Reminds me of the many, many hours I spent playing the Outrun arcade game as a kid.
This was one of the games that came up during my research into this era. I must say that it seems to have the best 'look' of them all but it has some extreme weirdness in its code, apparently.

So, I've tried it.
you really should make a racing game with this engine!
It's more of just a class that draws a track depending on which position you say you are in  ;)
I might actually work on some controls for the car etc.. Any suggestions, since you've tried it?
The annoying point is that, most of the time, we don't see far enough to know where we have to turn, but it's just a demo, I know :)
It's a test/demo of just the track rendering really. It's quite a simple track: right/left/right/left etc.. The hills (at the moment) don't affect speed or grip. The reason it's hard to see where to go is that the test is of extremes; if it was to expand into a game, it wouldn't need so much altitude alteration and the curves probably wouldn't all be that extreme. It's the reason the last third is different; it was a test of more a subtle type.


I think the track code is okay now but it needs more work to generalise the road markings. Currently, they're hard-coded to have a lines on both edges and three lines every alternate segment.

Any suggestions of 'simple' 'gameplay' modifications would be appreciated and considered  ;D
Title: Re: Faux Car
Post by: Hapax on February 09, 2015, 01:28:10 am
On this latest version, I've added a few things by progression and also by hacking some features into it to make it slightly more interesting:

Here's a couple of images of what the latest version (v0.1.0) looks like (click to see full size):
(http://i.imgur.com/ZTpWEZs.jpg) (http://i.imgur.com/ZTpWEZs.jpg)
(http://i.imgur.com/RLXRRb7.jpg) (http://i.imgur.com/RLXRRb7.jpg)

Here's the download (Windows only, sorry) (zip file: <4MB):
http://www.mediafire.com/download/c1824862oou289i/Faux+Car+v0.1.0.zip



I am moving house and will no longer have access to the internet. I'm sure I just heard a number of sighs of relief that I'll not be on the forum so much; I think I might (unintentionally) irritate some people. I'll occasionally be popping on the forum on my phone but I don't know how much.

Due to that reason, I've hacked my test application to work as a sort of game. You actually get to race opponents (of a sort) and the track is randomly generated. Hopefully, some people (Windows users, since I've only been able to compile it for Windows) will get some fun from it.

It shows the entire control list when the window is first opened so feel free to have a look through them and play around.
Probably the most notable will be:

ARROW KEYS to control the car,
F1 to pause / show controls,
0 (zero on numpad) to reset and race the same track again,
F2 to reset and race a new, random track,
SPACE to reset the car to the centre of the road (useful if far off the side of the road), and
BACKSPACE to change the camera (there are 3).

If you want to just watch it drive itself to look at the track, use cruise mode (F9). You can still change the camera in this mode.

Hopefully speak to you all again soon,
Hapax.

(http://i.imgur.com/GqBuJpS.png)
Title: Re: Faux Car
Post by: Hapax on May 02, 2016, 05:18:09 pm
I have started working on this project again, albeit slowly.

The track engine has been created again - completely from scratch - so there is not really anything interesting to show just yet.

Still, I realised that there was never a video of the perviously latest version (v0.1.0). There is, of course, a download to play that version but it was only for Windows and some people might not be interested in playing it so here is a basic video of that version (that is still available for download):
(note that there is an HD 1920x1080 @60FPS version available on YouTube)
http://www.youtube.com/watch?v=QiSgmamUSVw
Title: Re: Faux Car
Post by: Hiura on May 02, 2016, 05:28:44 pm
racing against trees... why not after all!  ;D
Title: Re: Faux Car
Post by: Mortal on May 03, 2016, 12:10:01 am
hehe, trees is so hilarious

the video on your youtube channel is much more better. i enjoyed it and wished if the track is longer.
Title: Re: Faux Car
Post by: Hapax on May 03, 2016, 12:47:36 am
The reason that the opponents are trees/bushes is because they have/had to be drawn as part of the same vertex array as the track (including roadside objects) itself so uses the same texture. Technically, the opponents are actually roadside objects that are just moved!

I'm adding the ability to keep track of road heights so that objects drawn after the track can be clipped by the correct amount for its distance so that they can be "slotted in" to the scenery. This will release the restraint that everything should be drawn with a single vertex array other than the static single sprite player.

I have so many things that I want to add to this that none of them ever get added :( Still, I'm currently working on just the track so when I post newer track stuff, I'll leave the playable version (v0.1.0) available for download (there is no car in the newer version as yet - it's all definition, drawing and camera work)
Title: Re: Faux Car
Post by: Hapax on May 17, 2016, 04:55:22 pm
Latest update with new video!

It's at v0.2.5 at the moment.
It's all track definition, display and camera work.
Still, just because there is no longer a player sprite, driving controls, score, opponents, roadside objects with textures or sound doesn't mean that there hasn't been progress and there aren't new things!

The track definition can now have a palette of roadmarks. That is, roadmark for a single segment of track. They can then be "painted" onto the track and re-used (every segment uses one from the palette or nothing).

"Extra" roadmarks are also possible that aren't stored in the palette and are just additional "one-shot" marks. These can actually be added in real-time and I currently add "skid marks" to the track by pressing a key (I forgot to do this for the video). They can only be added though; once they're there, they're there. Well, you can remove them but it's not simple to find them and removing them could cause relocation of data.

Split-screen has been integrated with the way the track's view is now used and there are now three pre-defined "screens": one vierw full, two view top, two view bottom. The two views can be completely independant parts of the track but the camera needs to be set for each view. The top one in the video (first-person-style) is a customised view that allows the camera to get in closer to bring out more feeling of speed and being closer to the road.

Probably the most noticable thing in the video will be the new objects. They are technically identical to the road marks (they're just quads linearly interpolated between segments) but also allow height. Objects, like roadmarks, are stored in a palette and can be added like "extra roadmarks" in that they can be "painted/pasted" wherever on the track. Each object can have a number of parts or "planes", which are just quads. These planes are stored withing a single segment and grouped into objects. Objects in the palette can be re-used in any position ("depth" cannot be changed - it is always in the same depth within a segment) with a colour that is multiplied by each plane. Planes are not sorted depending on distance from the camera; they are only drawn in the order provided so actual depth sorting is not (currently?) possible. It is possible to see this in the video; the "solid chevrons" near the beginning of the track have the left side drawn first so when they are close, the right ones are drawn incorrectly.

Another noticable thing (if you watch more than the first minute of the video) is that the camera not has completely free movement. Its only real positional restraint is that it is relative to the track (since the curves in the road are "fake/pseudo"). Camera rotation, though, is more limited, as expected. The only rotation provided by the ability to move the vanishing point to any position. I have considered and may add z rotation at a later date (it should be simple view rotation).

Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki)'s Progress Bar is used at the top to show the current position in the track. It's left at its default state so it's a simple black and white bar. Not that it's currently necessary since there is also a single roadmark that stretches the entire length of the road and starts from the left side of the road and ends at the right side.

Although the road and roadmarks are stored with direct segment information, the track is built from a "blueprint". This blueprint specifies certain higher-level properties and then the track definition is built from that blueprint. For example, the blueprint's road definition (actual road, not marks, colours or objects) is randomly generated - similar to how it was in v0.1.0. It randomly chooses the properties of each piece of road such as length and bend amounts (start bend and end bend). Each piece always starts with the bend amount of the previous piece to allow smooth joints. When building from the blueprint, these amounts are interpolated using an easing function that generates smooth turns in the road. The altitude is similarly generated with the final tilt angle always being zero so that the road is flat at the end. The altitudes usually finish before the road ends, which is why the road is often flat later on.

Roadmarks are also specified in the blueprint. This allows "extra roadmarks" to be defined overall rather than segment by segment. For example, the "progress roadmark" is defined in the blueprint as a single quad the starts at the first segment at the left of the road and ends at the last segment at the right of the road. When the definition is built from the blueprint, this is interpolated for each segment and each segment gets an extra roadmark that is contained in that single segment.

Plinth (https://github.com/Hapaxia/Plinth) is used extensively in Faux Car. From just specifying colours from the extended colour list through using its vectors on to using its interpolations. The interpolations form most of the work in the track calculations. That is linear mostly but the easing interpolation (smoothing track pieces) as well as piecewise interpolation (the "rainbow block" at the beginning) are also used along with its Range type with "inverse linear" interpolation. Plinth is also used for resource management although there aren't many of those at this point.

How the track's road works
The centre point (the front) of the segments are projected towards the vanishing point. The amount of bend for that segment is added to that segment and that value is stored. Each segment backwards takes the total bend so far and adds on its own and offsets its segment point by that amount; it's accumulative. For each of these points, a single unit is measured at its depth and also stored; this serves as a multiplying amount for anything at that depth, including the "bend" (or accumulated horizontal offset) amount.

After these points have been projected, the actual vertices are updated. These are done in reverse so that the front of the track is drawn over the back. Each segment has a stored projected position and a "unit length" so any point within one segment (between two segment points) can be interpolated and offset from the point by multiplying by the unit length. This applies to the road, the roadmarks, and the objects! The only thing that isn't subject to this is the road-side which is always from the left-side of the view to the right-side of the view; it's y position is taken from the segment points but the x positions are always the same.

Anyway, enough waffling; here's the video:
http://www.youtube.com/watch?v=ceuQimdKSuM
Title: Re: Faux Car
Post by: AFS on May 17, 2016, 08:52:15 pm
Impressive stuff! (although I must admit that half of your explanation went over my head :P).

I remember these kind of racing games used simple sprites as background (buildings, clouds and whatnot), and they just moved left and right according to the camera. Very effective to add depth. Are you planning on adding those?
Title: Re: Faux Car
Post by: Hapax on May 17, 2016, 10:29:16 pm
Thank you!  :)

Yes, I am planning to add image/texture-based stuff too. The earlier, playable version -
(click to show/hide)
- did have a sprite for the player, "billboard" style textured road-side objects, bitmap text and a wrapped background image at the horizon, which I intend to re-implement once the track stuff is further on. Knowing me, though, I'll probably start to add it before it's ready, as I did before. ;D
Title: Re: Faux Car
Post by: Glocke on May 18, 2016, 02:05:42 pm
This looks awesome! Reminds me of the good old days with Lotus Turbo Challenge :)
I'm looking forward to a native linux version ;-)
Title: Re: Faux Car
Post by: Rhimlock on May 20, 2016, 01:49:33 pm
Nice.
Makes me want to chase some trees, who think they could run away from me ;-)
Title: Re: Faux Car
Post by: Hapax on January 31, 2017, 03:35:40 am
Still working on this, on and off.
Current version: 0.3.2

Fully remade the "track" engine.
Technically, it's now called "scene" as it's the entire scene :)

Prepare yourself for a lot of information!
(there is a screenshot at the end)


The entire thing is split into "projects" (I'm using Visual Studio). This allows me to do all of the scene work in one and build it as a static library. Then, it can be used by multiple other projects. For example, the actual game and a track editor (which still needs to be made).

I'll be mainly discussing the "Scene" project/library here as that's the bit I've been working on (and is the "interesting" part as there's no game or anything yet).

The Scene class is the actual drawable scene and is the thing that does all the projections and putting everything together. It holds a pointer to scene definition classes so that they can be switched out (separately, if required).
The scene definition classes are:
Track, Marks, Objects and Sprites.

Track is the road, mainly.
That is, it defines its length, its curves and hills, its colours as well the horizon/sky/background textures to use.
A track is defined by "pieces". There are two types of pieces: Standard and Pattern. Most pieces are Standard.
Standard piece is a basic, singular piece that occurs only once. A pattern piece allows a repeatable pattern to be created.
Track stores these pieces and Scene interpolates the points it needs from the pieces as it needs them.

A StandardPiece stores a position (start distance along track), a length (distance from position), and then an initial and final value. The value is determined by the type of StandardPiece. The start value is used at the beginning of the piece (at its position) and the final value is used at the end of the piece (position + length). At any distance between those two distances, the value is interpolated. The interpolation type can be specified for each piece. Types are: none, linear and ease. Linear and Ease interpolate the start and final value based on linear and easing interpolation. None ignore the final value and uses only the start value.

The two most obvious and most important are bendPieces and slopePieces. These define the curves and hills of the track. They are both of type StandardPiece.
For the following examples, we will assume that the piece's position is 100 and its length is 100. This piece would then be in effect from 100 up to 200.
Examples of bend pieces:
A curve could have an initial value of 0.2 (a slight curve to the right). The curve would have interpolation of None and any final value is not used. This creates a simple, constant curve (all points on this piece would be a bend value of 0.2)
A curve could have an initial value of 0.2 (slight curve to the right) and a final value of 0 (straight ahead). The curve would have a bend value of 0.2 at distance 100, a value of 0 at distance 200 and a value of 0.1 at distance 150. This type connects a right bend (of 0.2) to a straight road (0).
Examples of slope pieces:
A hill could have an initial value of 0.2 (slight incline). The hill would have interpolation of None and any final value is not used. This creates a simple, constant incline (all points on this piece would be a slope value of 0.2)
A hill could have an initial value of 0.2 (slight incline) and a final value of 0 (flat). The hill would have a slope value of 0.2 at distance 100, a value of 0 at distance 200 and value of 0.1 at distance 150. This type connects an incline (of 0.2) to a flat road (0).

Similar pieces exist for the colour of the road, the colour of the ground (roadside), the colours of the ground on the background and the colours in the sky gradient, and even the texture IDs of the sky, ground (background), and reverse sky and ground (this can be used to change these colours and textures dependant on distance on the track).

A Pattern Piece is slightly more complex.
It has a (start) position as with StandardPiece. It also has the interpolation type.
However, instead of a single initial value and a single final value, it has a vector for each. It then stores a vector of "nodes", which basically just store which value from the vectors to use and how long for. The piece also stores how many types the entire pattern of nodes should be repeated. The length of this piece, then, is one higher than the number of repeats, multiplied by the length of all of the nodes.
The PatternPiece is used for road and ground (roadside) colours. This allows repeating colour patterns including the simple alternating shades as per the "usual" road-based game.

Using these pieces, a track can be built simply and Scene can create the final track image from that. Bend and Slope pieces can overlap; the values are simply added together where multiple pieces overlap.

Marks are the marks on the road (or anywhere on the ground).
A Mark is defined as one or more Quads. These quads are two-dimensional as they are flat on the road.
Each mark has its own position, colour and scale, which applies to all quads in that mark.
Each quad stores the four points of a quad - a polygon with four vertices, as well its own colour and an positional offset. The polygon must be convex but, of course, concave polygons can be created by using multiple quads.
Quads are stored separately (in their own vector) and the Marks store a vector of pointers to quads. This allows the same quads to be used in different marks.
Marks, when drawn, are clipped to each segment of the road and drawn in pieces, one or two per segment that contains it. For example, a simple stripe that stretches for 6 segments will be split into 6 stripes - one for each segment.
Marks and Quads are stored in their original form. They are split in real-time each frame. This, however, can be time-consuming so Marks can be "baked". Baking splits all of the marks' quads and stores the split quads and which segment it should be displayed with. This allows much quicker calculations.

Objects are very similar to Marks. They also store multiple quads, which are split for each segment. They also allow baking. The only real difference is that the quads in Objects are three-dimensional. That is, they can also have height/vertical offset (y) whereas Marks can only have horizontal offset (x) and distance (z).

Sprites are also quite similar to both Marks and Objects but are a lot more simple. They are "billboard" quads that are specified by width and height only. However, their position is three-dimensional, allowing "floating" sprites. Sprites do have one feature that objects and marks do not - textures.
Sprites are used for all 2D textured sprite graphics in the scene. They can be static (roadside scenery etc.) or dynamic (vehicles etc.).
Sprites does not contain only the Scene Sprites described above; it also includes Sky Sprites that allow sprites to be drawn on the background as it anchors to the background "plate". They are always drawn after all of the background and before all of the scene (track, marks, objects and scene sprites).

There can be a lot of Marks, Objects and Sprites for a track so each cycle, a vector of pointers of each are prepared; these pointers are all of the items that are within the visible range of the scene. Then, for each segment, the vector of pointers is then consulted to see which ones are in that segment. This significantly reduces the amount of testing.

The Scene itself only really has camera controls plus a few set-up things. The set-up things are, of course, setting which Track, Marks, Objects and Sprites to use as well as setting which texture resources to use. There are two textures: the main scene texture and the background texture. It also stores a TextureSheet for each, which is basically just the texture rects for each sprite/image in the texture.
There is also a function to get a predefined view, which provides a full window view or half window views in the top or bottom half - useful for one player and two player set-ups!
The rest of the controls are camera controls. Things like: position (3D), aspect ratio, where the vanishing point is, the camera depth (effective depth of the scene) - I think I will use this as an effect :).
One other feature added to this version is reversible direction. That is, the track can be drawn from the camera as if it's facing towards the beginning of the track instead of the end. One use for this is a flipped view to display a mirror.
Of course, there is one other method: update(), which brings Scene up to date based on its camera's current position and using the current state of the Track, Marks, Objects and Sprites.

Scene's update sets the range of segments that will be drawn and then updates the projections for each. It then updates the background vertex array before updating the main scene vertex array.

The background vertex array consists of multiple quads:
the sky base (skyTopColor),
the sky gradient - top part (skyTopColor to skyMiddleColor),
the sky gradient - bottom part (skyMiddleColor to skyBottomColor),
the skyline - texture above horizon,
the ground block (groundBlockColor - colour below horizon),
the groundline - texture below horizon,
all Sky Sprites.

The Scene vertex array consists of, for each segment:
a ground segment (both road sides at once - a horizontal bar),
a road segment,
all baked marks' quads for the segment,
all unbaked marks' quads clipped to the segment,
all baked objects' quads for the segment,
all unbaked objects' quads clipped to the segment,
all sprites within the segment.

First, it calculates a maximum number of vertices required to draw the scene.
It starts with the number of segment multiplied by 8 (one quad for the ground and one quad for the road)
It sets the range of Marks, Objects and Sprites so that they can prepare the ones in range and then adds 4 for each of their quad in the segment.
Note that, at this point, any unbaked Marks or Objects will be split into segments and stored as quads - similar to baked quads.
During the projection updates earlier, if a segment is facing away from the camera, it marks it as invisible and adds 8 (4 for the ground, 4 for the road) to a counter called vertexReduction, as these won't be drawn.
The vertex array is then resized to the maximum number of vertices required minus vertexReduction.

vertexReduction is reset to 0 as there may be more reductions to follow...

Then, quads are added...
For each segment - in reverse order (see Painter's Algorithm (https://en.wikipedia.org/wiki/Painter's_algorithm)):
if the segment was not previously as invisible, the ground and road quads are added,
loops through all baked marks' quads within visible range to see if they're for the current segment. If it is, it will add that quad otherwise it will add 4 to vertexReduction,
similarly loops through all marks' dynamically split quads and adds quads or 4 to vertexReduction,
loops through all baked objects' quads within visible range to see if they're for the current segment. If it is, it will add the quad only the top of the quad is above the top of the hill/ground at this point otherwise it will add 4 to vertexReduction,
similarly loops through all objects' dynamically split quads and adds quads or 4 to vertexReduction if behind a hill,
loops through all sprites in range to see which ones are in the current segment. For each one that is, if the sprite's boolean "isActive" is true, the sprite's quad will be added unless its position is on the wrong side of the camera or its top is below the hill in which case 4 will be added to vertexReduction. If isActive is false, vertexReduction gets another 4.

"Adding a quad" in this case consists of using an iterator pointing to the vertex array (technically, it's a vector of vertices) and modifying the current and following 3 vertices for the quad and then moving the iterator forward by four. When a quad that was prepared for doesn't get added, this leaves unused vertices at the end of the vertex array. vertexReduction keeps track of how many are unused.

That's the update. All that is left is to set the view to whichever is needed and the draw it. The draw function draws the background vertex array first using the background texture and then draws the scene vertex array using the scene texture. When it draws the scene "vector" of vertices, it uses the pointer overload for draw that takes a size and passes the size of the vector minus vertexReduction, which stops it from drawing all the unused vertices at the end:
target.draw(m_vertices.data(), m_vertices.size() - m_vertexReduction, primitiveType, states);



The app itself that I am currently using to develop the Scene will be a starting point for both the game and the track editor. Currently, it allows movement of the camera, independant movement of the single car sprite including flipping its direction, modification of the camera depth and vanishing point, and changing setup things like: toggling camera direction, car visibility, framerate limit, pixelation and cycling window mode (window, fullscreen, fullscreen window). Cycling window mode skips fullscreen mode if its not a valid mode.
You can also toggle a "feature" that "wobbles" the Marks and Objects (different sine wave side to side) but this only works for unbaked Marks and Objects.



I have a dilemma/question.
I can't decide on whether Faux Car should have a pixelated display or not:
(http://i.imgur.com/Y5CT5cm.png) (http://i.imgur.com/Y5CT5cm.png)
(http://i.imgur.com/v7XOgnl.png) (http://i.imgur.com/v7XOgnl.png)
Click images for full-sized versions.
Title: Re: Faux Car
Post by: Tank on January 31, 2017, 12:33:42 pm
Quote
I have a dilemma/question.
I can't decide on whether Faux Car should have a pixelated display or not:
Roll a dice. :)
Title: Re: Faux Car
Post by: bitano on January 31, 2017, 03:34:59 pm
Quote
I have a dilemma/question.
I can't decide on whether Faux Car should have a pixelated display or not:
Roll a dice. :)

Or a user setting !!! (it felt like multiple exclamation marks were required for extra emphasis)
Title: Re: Faux Car
Post by: Hapax on January 31, 2017, 05:37:12 pm
The pixelation is currently togglable.

One problem, though, is that I need a render texture to pixelate but can't use anti-alias on the render texture. This would mean that to use anti-alias, I would have to provide a work around that skips the render texture and draws directly onto the screen :(

Another problem, too, is that the "quality of the pixels" would determine the level of detail required in the actual textures. If pixelated, lesser textures are needed. If not pixelated, more detail can be added.

See? A dilemma! ;D
Title: Re: Faux Car
Post by: eXpl0it3r on February 15, 2017, 11:00:23 pm
Just found this randomly on a Discord server and it reminded me of Faux Car. Maybe you can draw some "inspiration" from it. ;D

http://www.youtube.com/watch?v=3hPIf7ui1Do
Title: Re: Faux Car
Post by: mpeg3 on February 15, 2017, 11:20:31 pm
The pixelation is currently togglable.

One problem, though, is that I need a render texture to pixelate but can't use anti-alias on the render texture. This would mean that to use anti-alias, I would have to provide a work around that skips the render texture and draws directly onto the screen :(

Another problem, too, is that the "quality of the pixels" would determine the level of detail required in the actual textures. If pixelated, lesser textures are needed. If not pixelated, more detail can be added.

See? A dilemma! ;D
It's looking great. Well done. BTW I vote for non-pixelated version!
Title: Re: Faux Car
Post by: Hapax on February 16, 2017, 01:13:14 pm
It's looking great. Well done. BTW I vote for non-pixelated version!
Thank you. I think it's going to have to have the option; might take a bit longer now though ;D

Just found this randomly on a Discord server and it reminded me of Faux Car. Maybe you can draw some "inspiration" from it. ;D
(click to show/hide)
Haha. It's a bit further ahead than mine :(
Four things I don't like about it:
;D

I've actually been working on this a bit recently. Finally got back to the stage where it has a drivable car :)
Title: Re: Faux Car
Post by: Hapax on February 06, 2018, 02:43:58 am
I wanted to show the most recent state of this project as it isn't completely discarded. It has been a few months since I've done anything to it but its latest version has a number of things that wasn't in the other versions so I decided this thread needed an update!

Version 0.4.0

Another overhaul of the engine, separating out the sprite and track definitions and sprites from the engine and linking them in later. The engine now dynamically updates from the current state of definitions. Track definitions are now 'building blocks' of pieces and patterns and the engine builds the scene from those.

Added new scene features.
The scene can now be viewed forwards or backwards. That is, the 'camera' can be faced forwards or backwards. 'Sprites' can have separate front and back faces which are shown dependant on which view direction is used (and which way the sprite is faced).
The background scenery at the horizon can be looped and different for front and back views; it can also have scenery below the horizon.
The background sky can show special sprites that match the background scenery but can be moved and animated.

Added A.I. opposition.
The A.I. is admittedly rather simple but it's better than 'trees that have position based on time'. Currently, they stick to their lane and change their speed based on the curvature of the track. Each opponent has differing speeds for both straight track and curved track (some opponents are better on bends and some are better on straights).

Added collision.
The player now collides with the opponents. The opponent is not affected so the player is forced to be affected severely - slowed heavily and turned away from the opponent.
The player also collides with other sprites or 'billboards'. They also have individual settings as to how they affect the player: no collision, 'no-pass' which stops the player dead, and jump. Jump causes the car to jump upwards into the air and the height is dependant on the player's speed.

Added speed boost.
The player can now boost their speed for a short time, similarly to "nitro boosts" in some other games. This boost causes the perspective depth to change and it 'feels' even faster! It's difficult to get a chance to see this in action with the current track however but it is visible in the example video.

Added menus.
A state system was added to the game so this allowed menus to be implemented. Some game settings can now be set via these menus. This includes preference of KPH or MPH, global audio volume, video settings and a few 'dev' flags (a couple are shown in the example video).

Here's an example video (1920x1080 60FPS):
https://www.youtube.com/watch?v=SDHE9UenCMc

Here's the download (Windows only, sorry) (zip file: <3MB):
http://www.mediafire.com/file/1glbahp7u3g27ko/Faux+Car+v0.4.0.zip

If you're missing the Visual Studio libraries, you will need to install the Visual Studio 2015 redistributable from Microsoft. I believe the one required is this one:
https://www.microsoft.com/en-us/download/details.aspx?id=53840