15,115,261 members
Articles / Desktop Programming / MFC
Article
Posted 25 Feb 2004

69.1K views
4.5K downloads
24 bookmarked

# Miner3D_viewer ActiveX control (for Miner3D game)

Rate me:
4.33/5 (6 votes)
25 Feb 2004CPOL3 min read
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 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

#### Properties:

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

#### Event:

• `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
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!

## License

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
My subject is Information technology. I like programming and learn more about everything.

## Comments and Discussions

 First Prev Next
 I want to create a 3D game vikas amin15-Sep-05 1:50 vikas amin 15-Sep-05 1:50
 Re: I want to create a 3D game ICE_WIZARD15-Sep-05 21:49 ICE_WIZARD 15-Sep-05 21:49
 Go to http://www.gamedev.net/ and find it! [IMG]http://sinhvienufa.vietnam-it.com/forums/html/avatars/dethuong/Avatar7A1F.gif[/IMG]
 newbie tarzanviet7-Jun-04 16:52 tarzanviet 7-Jun-04 16:52
 Re: newbie Kenan Hrustanovic19-Aug-04 13:24 Kenan Hrustanovic 19-Aug-04 13:24
 How to run 2 different(or same) OpenGL objects in one DialogBox? werter13-May-04 22:18 werter1 3-May-04 22:18
 Get 3D Coordinates from Screen Location Ted9442-Mar-04 3:09 Ted944 2-Mar-04 3:09
 Re: Get 3D Coordinates from Screen Location MyBlindy2-Mar-04 20:00 MyBlindy 2-Mar-04 20:00
 Last Visit: 31-Dec-99 19:00     Last Update: 29-Nov-21 15:01 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

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