C++ Graphics (graphics.h)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 20
Reputation: Savage221 is an unknown quantity at this point 
Solved Threads: 0
Savage221 Savage221 is offline Offline
Newbie Poster

C++ Graphics (graphics.h)

 
0
  #1
Dec 5th, 2005
I just had a pretty basic question regarding graphics in C++ using the header graphics.h. How would you take a shape or just regular text and randomly move it around the screen like you would see in a screen saver? Just looping it to randomly display it in different areas is simple enough, but I'm trying to go for that constant moving effect. Any help would be greatly apprechiated.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: C++ Graphics (graphics.h)

 
0
  #2
Dec 5th, 2005
compare the current coordinates of text or picture with screen coordinate...and if it's larger than that...then take suitable action to correct it
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 149
Reputation: Geek-Master is an unknown quantity at this point 
Solved Threads: 6
Geek-Master's Avatar
Geek-Master Geek-Master is offline Offline
Junior Poster

Re: C++ Graphics (graphics.h)

 
0
  #3
Dec 9th, 2005
Originally Posted by Savage221
I just had a pretty basic question regarding graphics in C++ using the header graphics.h. How would you take a shape or just regular text and randomly move it around the screen like you would see in a screen saver? Just looping it to randomly display it in different areas is simple enough, but I'm trying to go for that constant moving effect. Any help would be greatly apprechiated.
Here are some steps I would take:

1. Setup Coordinate Parameters and Direction Flags

If you are in full screen mode then all you will need to do is obtain the screen size i.e.(800x600).

If you are dealing with a rectangle box, then you will need to set up 4 variables that will determine when the object needs to "bounce off" and change direction.

You will also need to set up 2 flags that will determine the movement along the x and y axis.

Not only will you have to take in consideration of your "borders", but your objects size. This can be done by subtracting the size of your object, which is another rectangle too, from your parameters. This will make sure your object doesn't slide off the screen, since the object's coords will come from the top-left point.

2. Test your object with these parameters

You will need to set up some conditions to test if your object didn't "hit" the parameter you set up.

When the object hits a parameter then you will need to turn off or turn on one of the direction flags.

Depending on what direction you are in you will need to decrement or increment the value of your object's coordiantes.

Moving the object by one pixel will give it the smooth motion effect you want.

3. Draw your object in its new location

You can adjust the speed of the object by how often the trigger goes off on the Draw function, which will probably be in milliseconds.

Sorry I can't give any example code for this. I've only worked with graphics using VB.NET on a version of PONG. So I think the theory can get you rolling further.
If in doubt, reach into the trash can and remove the user guide.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC