Last month, I have written an article about OpenGL selection (You can find it in this section). And now you can see my full code!
Using the code
First, you need to know about using MFC ActiveX Control Wizard. You can visit here for a tutorial.
AddChar: Paint a number
AddColorTile: Paint a cube with color defined
AddColorWireTile: Paint a wire frame cube with color defined
AddFace: Paint a rectangle
AddPoint: Paint a light point
AddTile: Paint a cube with default color (BLUE)
AddWireTile: Paint a wire frame cube with default color
ChangeTileColor: Change color of a cube
Clear All: Remove all things in the screen
GetCamDirX: Return the X dimension of camera direction
GetCamDirY: Return the Y dimension of camera direction
GetCamDirZ: Return the Z dimension of camera direction
GetHandleActiveWindow: Return the handle of active window this time
GetTilePos: Get position of cube
OpenTile: Do open a cube
Pick: Determine what cube is in that point of screen
PlayMidiFile: Play a MIDI file
Refresh: Paint again
StopPlayMidi: Turn off the sound
BackColor: back ground color
CamAxz: angle follow xz face
CamAzy: angle follow zy face
CamPosX: X dimension of camera
CamPosY: Y dimension of camera
CamPosZ: Z dimension of camera
CharRotateDegree: the degree of rotated numbers
FogColor: color of the fog
FogDensity: the density of the fog
Interval: like timer but adding refresh screen
Light1: the light ray from up to down
PickLessExact: less exact when pick
SeeAngle: see angle
SeeFarthest: see farthest
SeeNearest: see nearest
EndPlayMidi: when finish, play a MIDI file
LeftButtonDown: when click left mouse (x, y follow pixel of screen)
RightButtonDown: when click right mouse (x, y follow pixel of screen)
Timer: like timer
VcKeyDown: like key down but catch adding arrow key
VcKeyUp: like key up but catch adding arrow key
To run this you have to register this OCX by two ways:
- Compile the VC code!
After that you can run the the game or view the VB source!
Now I explain some parts of my code:
CMiner3D_viewerCtrl is what you have to write!
- I make a list to save the way I paint the number:
MakeCharList(). You can understand my number as an object and you can make it by this way:
- For the selection I use function:
CMiner3D_viewerCtrl::pick(double x,double y, BOOL FAR* miss)
I don't know why the Z dimension is not work so I have to calculate the square of each distance to determine what object is nearest, and some time it throws "divided by zero" exception! If you know why, please tell me! Thank you!
- Change RGB color to OpenGL color: The RGB
COLORREF you can know as this:
color = 0x00112233
- 11 : Blue component. You can get it by (color & 0xff0000).
- 22 : Green component. You can get it by (color & 0xff00).
- 33 : Red component. You can get it by (color & 0xff).
After that, divide 255 to get OpenGL color!
- I will explain more if I have time, or you can mail to firstname.lastname@example.org!
Points of Interest
- I have tried to write a 3D game and find the way to combine VC with VB. I have done it!
- I had used texture and blend function but my computer is too slow for it, and I have removed it!