The Second Video in the How to Debug C++ Programs Is On YouTube

How to Debug C++ Programs Lecture 02

The second video in this series is now up on YouYube. In this video, I show you how to use the basic features of the debugger to find the errors in programs. Step Into and Step Over are explained along with Continue and how to set and remove breakpoints at key locations. The Watch window, Auto, and Local windows are used effectively to keep track of variable contents.

See how to use these in combination to more effectively and rapidly find the errors in your C++ programs. Watch the video. Subscribe to the channel to get automatic updates when subsequent videos in the series are released.

You can also comment on them and I am open to your suggestions on what other topics you would like to see hints and tip on – just let me know.

Here’s the fast link to the video:
Debugging Lecture 02

Share Button

The First Debugging C++ Programs Video Is Up on YouTube

Debugging C++ Programs Video Series

I’ve begun a series of videos on Debugging C++ Programs . Debugging: is it an art or science? When I’m helping my students with theirs, some claim that it could well be a magical art ! This series is intended to illustrate many methods for locating run time errors in many kinds of C++ programs. Perhaps, it is a bit of both. This series will help you learn more about the tools that are available to you, how to use them to track down errors, and something about the “art” as well.

The first step is “an ounce of prevention.” In this video on debugging C++ programs, I show you positive steps that you can take in your coding practices to keep bugs minimized. Of course, if you love to debug, then ignore and skip this video and just look at the ones to follow. In this video, I show you two excellent methods to prevent run time errors, including using the C++ error handler (i.e. try-catch logic).

Link to video

Let me know what you think of this series. Also, I’m open to suggestions for further “how to” videos that you’d like to see. Let me know your ideas and we can make a fun project of learning.

Vic

Share Button

Adding Realism to Your Game Programming in C++

Adding Realism to Your Game Programming in C++

Making the motions of objects in your game realistic and believable is one of the keys to a good, well-designed game that others will enjoy playing. Fast moving cars that instantly turn a corner, weapons whose projectiles always hit the target no matter what, avatars that jump across wide chasms defying gravity — you’ve seen them and probably like me say something like, “Now that’s impossible!” And we’re right. An alien space ship flying a thousand miles and hour instantly does a ninety degree turn to come after you — oh no! The g-forces on the crew are gargantuan (if you don’t know that word, look it up).

Realism in gaming is all about following the known laws of motion, the physics at work in our universe, the universe we all know on a daily basis. Granted, the physics and math levels needed to fully understand and develop such real-world solutions can be very challenging, perhaps mind-boggling to those who have had little exposure to basic physics and calculus. However, in my book, Game Theory Programming in C++, I do all that work, giving you more or less canned implementations that you can tweak and use in your games to add higher levels of realism. Let’s look at what I’m talking about.

Suppose that we were driving down the Interstate at sixty miles per hour. We drive at this constant rate for an hour (thanks to cruise control). How far will we have gone? If you answer sixty miles, you are correct. That is one of the basic laws of motion at work.
Distance traveled = velocity times time

We can refine it a bit further. If we are initially at location X, then after that hour of driving, our new location is at X + 60 miles.

Notice here that I used the word velocity and not speed. What’s the difference? Speed is just a number, 60 mph. It does not have any direction associated with it. Where would we be, distance wise, if during that hour of driving, I drove around in a large circle, such as the Interstate loops around large cities? My final location could well be right back where I started from. A vector is both a speed and a direction, that is, we say it has a magnitude plus a direction. Physics of motion is heavily involved with vectors.

So our first key equation gives us our new position:
new position = original position + amount of time * (velocity)

Newton’s Third Law of Motion is: For every action there is an equal, but opposite reaction. For every force acting on a body, there is an equal and opposite reacting force. Suppose you are standing in line to buy a ticket for a show and someone comes up behind you and gives your back a push (force). Which way does your body tend to go? Forward. Suppose someone on your right gives you a shove (force), your body tends to go to the left. Now suppose you are simultaneously shoved both from behind and from the right? You tend to go off at an angle, to the left and forward. Vectors at work here.

This vitally important relationship is summed up as: (* indicates multiplication)
Force = Mass * Acceleration
though it is usually written as: F = m * a.

Of course, the acceleration is a vector, a magnitude with a direction, as is the force being applied. But just what is this acceleration anyway? It is the rate of change of velocity over time, enter calculus. It is usually written this way.
a = dv / dt, where dv is the change in velocity and dt is the interval of time.

For example, your car is going sixty miles per hour and you run into a brick wall. Your velocity goes to zero during a duration of let’s say a second. What’s the result? The acceleration on your body is terrific! Splat! Forget about air bags this time.

So where does all this get us? To create realism in an object’s motion, we must take into account all of the forces acting on the object, such as friction, air resistance, and so on. This gives us one of the fundamental principles:
Principle 6: The resultant force is the vector sum of each individual force acting on the object.
This is written: m * a = sum of all F
or rewriting it:
a = sum of all F / m

Okay, okay, so where does this get us? How does this help us to make realistic motions of our game objects? We resort to a calculus principle. To find the overall result, we integrate the equations of motion over time. Huh? It’s okay if you haven’t had calculus. I take care of the details for you. The principle is simple. Take the overall time span and divide it into tiny, infinitesimal units, called delta t. For each tiny interval of time, we know or can estimate the total forces acting upon an object at that point. Given the forces, we can find the resulting acceleration: a = sum of all F / m. Now knowing the acceleration during that infinitesimal bit of time, we can then find the velocity and distance traveled during that small period of time from:    a = dv / dt, rewritten as dv = a * dt
From dv, we get the new position:  new position = original position + dt * dv

This is saying that we can accurately plot the path that an object will take through time, viola realistic motion!

Just how small does this infinitesimal unit of time need to be? Ah, this is an adjustable parameter. If you are doing a fast action type of game, then the time interval might be quite small. The smaller, the more accurate the simulation, but the more calculations needed to determine the series of successive locations for the object and thus the more calculation time needed, which can slow down the entire game. One adjusts the actual amount of time to meet the needs of playability of the game.

Keeping it simple, the overall process is then as follows:
1. Calculate the object’s mass properties.
2. Find and codify all forces that are acting upon the object at this instant in time.
3. Vector sum all forces.
4. Solve the equation of motion for acceleration.
5. Integrate with respect to our small unit of time to find the velocity.
6. Integrate with respect to our small unit of time to find the new position.
7. Check for and handle any collisions, if this has meaning in your game.
8. Display or use the new position in some manner.

In my book, Game Theory Programming in C++, I handle the physics and math for a wide range of objects and situations, both in 2-d and in 3-d simulations. Yes, the physics and math can get pretty involved, but I’m taking care of those details for you, presenting you with easy to use, complete coding that you can cannibalize and use in your own games.

Above all, have fun developing your game.

Vic

Share Button

What Is the Right Sequence For You To Study?

What Is the Right Sequence For You To Study?

I am often asked, “okay, so you write great C++ programming books, but what one should i get? I want to be able to program this….” My answer is always it depends upon what you wish to achieve, what you wish to be able to do, based upon your current skill set. This blog reply will give you an answer. You can always contact me for more specific information.

All too often, writers of beginning books on C++ programming try to merge object oriented programming features as they introduce the basic elements of the language. With so much confusing information, it is no wonder that the student has enormous trouble with learning to program well in C++. No, the starting point is to learn the basic C++ language. Build a solid platform on which to build knowledge. This platform must also explain the “whys” behind the scene, such as the Stack Frame and how it works, which suddenly makes the Storage Classes in C++ programming make sense to the student.

So assuming that you are new to C++ programming or have tried it and gotten yourself totally confused, the starting point is C++ Programming for Computer Science and Engineering. This initial book will give you that solid foundation of basic C++ programming. With that caveat out of the way, let’s look at some routes.

 

I just need to learn C++ Object Oriented Programming:

  1. C++ Programming for Computer Science and Engineering
  2. Beginning Data Structures in C++
  3. Object Oriented Programming in C++

Examine the detailed table of contents starting with #1 above to see where you need to begin your study. For example, if you have mastered all topics in #1, go on to #2, and so on.

 

I need to learn to write Windows applications:

  1. C++ Programming for Computer Science and Engineering
  2. Beginning Data Structures in C++
  3. Object Oriented Programming in C++
  4. Windows MFC Programming I
  5. Windows MFC Programming II

Again, examine the detailed table of contents starting with #1 above to see where you need to begin your study. For example, if you have mastered all topics in #1, go on to #2, and so on.

 

I want to write a cool game:

  1. C++ Programming for Computer Science and Engineering
  2. Beginning Data Structures in C++
  3. Object Oriented Programming in C++
  4. Windows MFC Programming I
  5. Game Theory Programming in C++
  6. Programming Non-graphical Games in C++
  7. Windows MFC Programming II (Optional)

Again, examine the detailed table of contents starting with #1 above to see where you need to begin your study. For example, if you have mastered all topics in #1, go on to #2, and so on.

Not every single game needs to be written using the Direct-X platform, which is incredibly complex and certainly total overkill for many games. True, for first-person shooter games, it’s needed. But for my WWII game? Hardly. Direct-X is needed using the off-screen video buffers directly for fast frame rates where extensive calculations are needed for each frame to be shown. Many, many games just need a simple Windows application. My suggestion is to try using the basic Windows platform first and see if it can handled your needs. You will find the coding vastly simpler and without having to do total rewrites when the next Direct-X version comes out.

 

What about advanced data structures?

Of necessity, Advanced Data Structures in C++ had to have a lot of overlap with Object Oriented Programming in C++, since when it was written, the students taking that course usually had not yet had the OOP course. It does not fully cover OOP nor with the same depth, just enough to get on with the more advanced data structures. So if you find that you have need for some of these more advanced structures in your programs, go ahead and study it. If your goal is to get a working knowledge of advanced data structures, here is your sequence.

  1. C++ Programming for Computer Science and Engineering
  2. Beginning Data Structures in C++
  3. Advanced Data Structures in C++

 

I hope this helps you work out your path to becoming a great C++ programmer and achieve your goals!

Contact me if you have more questions.

by Vic Broquard

 

Share Button

We won Best of Small Business Award!

We’ve won the Best of Small Businesses in East Peoria this year! Check out the award for our ebook business here. It’s nice to be recognized for good work and good services and products.

by Vic Broquard

Share Button

Hello Everyone

Hi Everyone,

Here’s our new www.Broquard-eBooks.com website!

It’s a drastic change in website design and I hope you like the new look as much as I do. It is many times easier for me to maintain and is supposed to be setup to be viewed on any device, including mobile ones too.

Some things have changed. For previous book buyers, the biggest change is that there is no longer a way to log in and download books that you previously purchases. That old log in-pw system is gone. If you need to re-download an ebook, contact me via email. See the Buyer’s Guide for more details. So yes, you can still re-download the books that you have purchased in the past.

In case you are interested, the site uses cookies, since I just couldn’t modernize the old database version. Okay, I know, everyone uses cookies these days, lol.

by Vic Broquard

 

Share Button