You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- Working with Objects
 


Working with Objects Using Classes Page 4 of 4
< Previous Jump to Page: 1 | 2 | 3 | 4 Next >

Subclassing the BasicObject Class

Creating a subclass of our BasicObject class is simple. Lets make one for our player


class Player : public BasicObject {
public:
	// angles
	int ax, ay;

	// movement according to angles, calculated with sin or cos
	float mx, my, mz;

	// update the mx, my, and mz according to the player's angle
	// the sin and cos functions only work if you have #included
	// "math.h" somewhere in your project
	void UpdateDirection() {
		mx = sin(ay * 0.0174532925) * cos(ax * 0.0174532925);
		mz = cos(ay * 0.0174532925) * cos(ax * 0.0174532925);
		my = sin(ax * 0.0174532925);
	}
	
};

Now if we create an instance of the class Player, it will have every property of the BasicObject class, plus any properties we define specific to the Player class.

That's all for now. I hope this has helped you rather than confused you. =]

Working with Objects Using Classes Page 4 of 4
< Previous Jump to Page: 1 | 2 | 3 | 4 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!