Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: problem wih Pseudo 3D for car-racing[SOLVED]  (Read 4754 times)

0 Members and 1 Guest are viewing this topic.

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
problem wih Pseudo 3D for car-racing[SOLVED]
« on: November 24, 2015, 05:11:23 pm »
hello

i have made small car-racing game by implementing Pseudo 3D based on tutorial in here http://codeincomplete.com/posts/2012/6/24/javascript_racer_v2_curves/.
the code runs fine but when i implemented the curves the car always stuck in middle. how can i fix this?

i want car drafts to opposite direction of curve's direction to give realistic view of this kind of games. in the tutorial, it suggests to use "easeIn()" and "easeInOut()" and adjust the player position like this
playerX = playerX - (dx * speedPercent * playerSegment.curve * centrifugal);

but those don't work correctly in my code. beside the tutorial doesn't explain the curves very well, it seems the author missed vital details in this section.
« Last Edit: November 26, 2015, 06:04:40 pm by MORTAL »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: problem wih Pseudo 3D for car-racing
« Reply #1 on: November 24, 2015, 10:02:00 pm »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: problem wih Pseudo 3D for car-racing
« Reply #2 on: November 24, 2015, 11:02:26 pm »
thanks @Jesper Juhl for links

i have fixed jarring behavior in curves, i was calculated camera depth wrongly. the correct calculation should be like this:

Game()
...
, mCameraDepth(1 / std::atan((100.f / 2.f))) //fov = 100.f
...

no need to convert it to radain as tutorial suggested. but the problem is how to make car position (camera x position) reacts with direction of curve. for example when curve is turned to right-hand the player position (camera x direction) goes to left smoothly and vise-versa. the formal for adjust camera position as in tutorial won't work in the my code. i have edit the code in respo and comment the formal for `playerX` in update function to find better solution for it.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: problem wih Pseudo 3D for car-racing
« Reply #3 on: November 25, 2015, 03:44:12 am »
I think "curve" here refers to the curvature of the road, rather than an interpolation curve. Is that right, Mortal?

To change the way the track is drawn based on the where the car is, you could try:
1) offsetting (horizontal) positions before projection (if you're projecting depth), or
2) offsetting all position by a set amount (or just moving the view for the track).

The easing part of that tutorial is about transition from straight road to fully cornered road.

The code line in your original post is to determine the player's horizontal position on the road.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: problem wih Pseudo 3D for car-racing
« Reply #4 on: November 25, 2015, 03:51:44 pm »
thanks Hapax for your time

Quote
I think "curve" here refers to the curvature of the road, rather than an interpolation curve.
sorry, i'm not so familiar with mathematics terminology, whats the difference between the curvature of the road and an interpolation curve. i have read other tutorial now regrading mode 7, it explain the mathematics under hood  this kind of game. it seems this subject is away complicated more it looks.

Quote
To change the way the track is drawn based on the where the car is, you could try:
1) offsetting (horizontal) positions before projection (if you're projecting depth), or
2) offsetting all position by a set amount (or just moving the view for the track).
i believe this what update() is doing. it advances the camera view position by certain amount it either moves forward (vertically) or moves aside (horizontally). before the projection. the projection is the final step before drawing it in screen.

Quote
The easing part of that tutorial is about transition from straight road to fully cornered road.
yes .. you are absolutely right. i figured it out after posting my question.

Quote
The code line in your original post is to determine the player's horizontal position on the road.
here where i'm stuck now. when i added this code line to update() function it start jarring and it won't do what it supposes to do. in javascript every thing works fine but in c++ all sorts of abnormality are happening every time.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: problem wih Pseudo 3D for car-racing
« Reply #5 on: November 27, 2015, 02:48:59 am »
thanks Hapax for your time
You're welcome.

sorry, i'm not so familiar with mathematics terminology, whats the difference between the curvature of the road and an interpolation curve
Linear interpolation is finding points between two other points in the straight line between those points.
Curves can be used for interpolation instead of a straight line and this is often used for easing.
Examples: http://easings.net/

here where i'm stuck now. when i added this code line to update() function it start jarring and it won't do what it supposes to do. in javascript every thing works fine but in c++ all sorts of abnormality are happening every time.
I'm not sure exactly what problem you are experiencing. "Jarring", "won't do what it's supposed to do", and "all sorts of abnormality are happening" are not very descriptive, unfortunately.
If it isn't working as expected, you need to make sure that every variable used in that calculation is at the value you expect it to be. Try outputting them (I'd recommend real-time updates for these so you'll probably need some sf::Texts. I tend to use the titlebar for quick feedback information) if you can't 'watch' them using your debugger.

Could it be linked to this (in that linked article):
Quote
Finally, in order to avoid jarring transitions when crossing segment boundaries we must ensure dx is initialized with an interpolated value for the current base segments curve.
« Last Edit: November 27, 2015, 02:51:00 am by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: problem wih Pseudo 3D for car-racing[SOLVED]
« Reply #6 on: November 27, 2015, 08:19:51 am »
Quote
Linear interpolation is finding points between two other points in the straight line between those points.
Curves can be used for interpolation instead of a straight line and this is often used for easing.
Examples: http://easings.net/

thanks once again for clarifying, i keep reading "interpolation" in most of tutorials that i have read in this regard. but i wasn't able to summary its meaning in my head. now it makes more sense.

Quote
If it isn't working as expected, you need to make sure that every variable used in that calculation is at the value you expect it to be. Try outputting them (I'd recommend real-time updates for these so you'll probably need some sf::Texts. I tend to use the titlebar for quick feedback information) if you can't 'watch' them using your debugger.
yes, thats exactly i have missed. most of time i relied on console window by using std::cout, but the problems were the framerate dropped badly. fortunately, i figured it out where is the problem cause the "jarring"
Could it be linked to this (in that linked article):
Quote
Finally, in order to avoid jarring transitions when crossing segment boundaries we must ensure dx is initialized with an interpolated value for the current base segments curve.
i was reading this over and over. i couldn't know what the problem. every thing seems Okay. until i started debug the code line by line which finally found where i have missed. it was silly typo mistake in code, i was getting wrong array index every frame. i have fixed it.


one again thanks for valuable advises and informative info.

 

anything