Click here to Skip to main content
15,305,625 members
Articles / Desktop Programming / MFC
Posted 25 Feb 2004


24 bookmarked

Miner3D_viewer ActiveX control (for Miner3D game)

Rate me:
Please Sign up or sign in to vote.
4.33/5 (6 votes)
25 Feb 2004CPOL3 min read
A solution for writing game 3D using VC combined with VB.

Sample Image


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:


  • 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:

    • At "Run..." type : regsvr32.
    • Open Explorer and drag this OCX into Run dialog.

      (Some thing like this : regsvr32 d:\Miner3D_viewer.ocx)

    • "Enter".
  1. 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
  • 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!

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!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Junior)
Vietnam Vietnam
My subject is Information technology. I like programming and learn more about everything.

Comments and Discussions

GeneralI want to create a 3D game Pin
vikas amin15-Sep-05 0:50
Membervikas amin15-Sep-05 0:50 
GeneralRe: I want to create a 3D game Pin
ICE_WIZARD15-Sep-05 20:49
MemberICE_WIZARD15-Sep-05 20:49 
Generalnewbie Pin
tarzanviet7-Jun-04 15:52
Membertarzanviet7-Jun-04 15:52 
GeneralRe: newbie Pin
Kenan Hrustanovic19-Aug-04 12:24
MemberKenan Hrustanovic19-Aug-04 12:24 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
werter13-May-04 21:18
Memberwerter13-May-04 21:18 
GeneralGet 3D Coordinates from Screen Location Pin
Ted9442-Mar-04 2:09
MemberTed9442-Mar-04 2:09 
GeneralRe: Get 3D Coordinates from Screen Location Pin
MyBlindy2-Mar-04 19:00
MemberMyBlindy2-Mar-04 19:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.