OpenGLVisual Studio 6Visual Basic 6Visual C++ 6.0MFCIntermediateDevVisual StudioWindowsC++Visual Basic
Miner3D_viewer ActiveX control (for Miner3D game)






4.33/5 (6 votes)
A solution for writing game 3D using VC combined with VB.
Introduction
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.
Miner3D_viewer control:
Methods:
AddChar
: Paint a numberAddColorTile
: Paint a cube with color definedAddColorWireTile
: Paint a wire frame cube with color definedAddFace
: Paint a rectangleAddPoint
: Paint a light pointAddTile
: Paint a cube with default color (BLUE)AddWireTile
: Paint a wire frame cube with default colorChangeTileColor
: Change color of a cubeClear All
: Remove all things in the screenGetCamDirX
: Return the X dimension of camera directionGetCamDirY
: Return the Y dimension of camera directionGetCamDirZ
: Return the Z dimension of camera directionGetHandleActiveWindow
: Return the handle of active window this timeGetTilePos
: Get position of cubeOpenTile
: Do open a cubePick
: Determine what cube is in that point of screenPlayMidiFile
: Play a MIDI fileRefresh
: Paint againStopPlayMidi
: Turn off the sound
Properties:
BackColor
: back ground colorCamAxz
: angle follow xz faceCamAzy
: angle follow zy faceCamPosX
: X dimension of cameraCamPosY
: Y dimension of cameraCamPosZ
: Z dimension of cameraCharRotateDegree
: the degree of rotated numbersFogColor
: color of the fogFogDensity
: the density of the fogInterval
: like timer but adding refresh screenLight1
: the light ray from up to downPickLessExact
: less exact when pickSeeAngle
: see angleSeeFarthest
: see farthestSeeNearest
: see nearest
Event:
EndPlayMidi
: when finish, play a MIDI fileLeftButtonDown
: when click left mouse (x, y follow pixel of screen)RightButtonDown
: when click right mouse (x, y follow pixel of screen)Timer
: like timerVcKeyDown
: like key down but catch adding arrow keyVcKeyUp
: like key up but catch adding arrow key
To run this you have to register this OCX by two ways:
-
- At "Run..." type : regsvr32.
- Open Explorer and drag this OCX into Run dialog.
(Some thing like this : regsvr32 d:\Miner3D_viewer.ocx)
- "Enter".
- 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:glNewList(1,GL_COMPILE); // call this by : glCallList(1); ... // code painting here glEndList();
- 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 chithien@hotpop.com!
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!