using System.Collections.Generic;
2.之後再宣告就可以使用嚕。
使用前記得要把變數new出來就是了。
//宣告 protected Dictionary<int, csBehaviorBase> m_dicObjBehaviors; //建立 m_dicObjBehaviors = new Dictionary<int, csBehaviorBase>();
using System.Collections.Generic;
//宣告 protected Dictionary<int, csBehaviorBase> m_dicObjBehaviors; //建立 m_dicObjBehaviors = new Dictionary<int, csBehaviorBase>();
using UnityEngine;
using System.Collections;
public class InputTest : MonoBehaviour {
protected float m_JoyX = 0.0f;
protected float m_JoyY = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
m_JoyX = Input.GetAxis("Horizontal");
m_JoyY = Input.GetAxis("Vertical");
Debug.Log("Get Horizontal input from Joystick = " + m_JoyX.ToString());
Debug.Log("GetVertical input from Joystick = " + m_JoyY.ToString());
}
}
using UnityEngine;
using System.Collections;
public class InputTest : MonoBehaviour {
protected float m_JoyX = 0.0f;
protected float m_JoyY = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
m_JoyX = Input.GetAxis("Horizontal");
m_JoyY = Input.GetAxis("Vertical");
if( Input.GetButton("Horizontal") )
{
Debug.Log("Get Horizontal input from Joystick = " + m_JoyX.ToString());
}else if(Input.GetButton("Vertical")) {
Debug.Log("GetVertical input from Joystick = " + m_JoyY.ToString());
}
if( Input.GetKey(KeyCode.JoystickButton11) ){
print("Get Joystick Button 0");
}
//Debug.Log("Get Horizontal input from Joystick = " + m_JoyX.ToString());
}
}
using UnityEngine;
using System.Collections;
public class InputTest : MonoBehaviour {
protected float m_JoyX = 0.0f;
protected float m_JoyY = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
m_JoyX = Input.GetAxis("Horizontal_Joy");
m_JoyY = Input.GetAxis("Vertical_Joy");
if( Input.GetButton("Horizontal") )
{
print("Get Horizontal input from keyboard = " + Input.GetAxis("Horizontal").ToString());
}else if( Input.GetButton("Vertical") ){
print("Get Vertical input from keyboard = " + Input.GetAxis("Vertical").ToString());
}else if( Input.GetButton("Horizontal_Joy") ){//m_JoyX != 0.0f ){
Debug.Log("GetHorizontal input from Joystick = " + m_JoyX.ToString());
}else if( m_JoyY != 0.0f ){
Debug.Log("GetVertical input from Joystick = " + m_JoyY.ToString());
}
if( Input.GetKey(KeyCode.JoystickButton11) ){
print("Get Joystick Button 0");
}
}
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//Show Tips
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, &CTestDlg::OnToolTipText) // the ID of a tool tip is always 0.
END_MESSAGE_MAP()
....
afx_msg BOOL OnToolTipText(UINT ID, NMHDR *pNMHDR, LRESULT *pResult);
....
BOOL CDSEnvItemEdtDlg::OnToolTipText(UINT ID, NMHDR *pNMHDR, LRESULT *pResult)
{
BOOL IsOK = FALSE;
TOOLTIPTEXT *pToolTipText = (TOOLTIPTEXT*) pNMHDR;
UINT nID = (UINT)pNMHDR->idFrom; //得到相對應的Dialog的ID,有可能是HWND。
if ( !(pToolTipText->uFlags & TTF_IDISHWND) ) { //確認是否為HWND
return FALSE; };
nID = (UINT)::GetDlgCtrlID((HWND)nID); //取得目前停留的子空見ID。
switch (nID)
{
case IDC_EDT_TEXT:
pToolTipText->lpszText = this->m_edtPicFilePath.GetBuffer();
this->m_edtPicFilePath.ReleaseBuffer();
IsOK = TRUE;
break;
default:
break;
} //End of switch (nID)
return IsOK;
}
....
GLuint m_glTextureList[DS_GL_MAX_TEXTURE];
....
//----------- L.6 ----------------
//Now immediately after the above code, and before ReSizeGLScene(), we want to add the following section of code.
// The job of this code is to load in a bitmap file. If the file doesn't exist NULL is sent back meaning the texture couldn't be loaded.
// Before I start explaining the code there are a few VERY important things you need to know about the images you plan to use as textures.
// The image height and width MUST be a power of 2.
// The width and height must be at least 64 pixels, and for compatability reasons, shouldn't be more than 256 pixels.
// If the image you want to use is not 64, 128 or 256 pixels on the width or height, resize it in an art program.
// There are ways around this limitation, but for now we'll just stick to standard texture sizes.
//First thing we do is create a file handle. A handle is a value used to identify a resource so that our program can access it.
// We set the handle to NULL to start off.
//----------- L.6 ----------------
AUX_RGBImageRec *COpenGLDrawer::LoadBMP(const char *szFilePath)
{
if ( CDSFileIO::IsFileExisted(szFilePath) ) {
return auxDIBImageLoad(szFilePath); // Load The Bitmap And Return A Pointer
} //End of if ( CDSFileIO::IsFileExisted(szFilePath) )
return NULL; // If Load Failed Return NULL
}
//The follwing code has also changed very little from the code used in previous tutorials.
// If you're not sure what each of the following lines do, go back and review.
//Note that TextureImage[ ] is going to hold 2 rgb image records.
// It's very important to double check code that deals with loading or storing our textures.
// One wrong number could result in a memory leak or crash!
// Load Bitmaps And Convert To Textures
int COpenGLDrawer::LoadGLTextures(std::vector<std::string> vstrFilePaths)
{
int Status = TRUE;
AUX_RGBImageRec *TextureImage[DS_GL_MAX_TEXTURE]; // Create Storage Space For The Textures
//The next line is the most important line to watch. If you were to replace the 2 with any other number, major problems will happen.
// Double check! This number should match the number you used when you set up TextureImages[ ].
//The two textures we're going to load are font.bmp (our font), and bumps.bmp.
// The second texture can be replaced with any texture you want.
// I wasn't feeling very creative, so the texture I decided to use may be a little drab.
/* memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL */
memset(TextureImage,0,sizeof(void *)*DS_GL_MAX_TEXTURE); // Set The Pointer To NULL
for ( unsigned int i = 0 ; i < vstrFilePaths.size() ; i++ )
{
if ( !(TextureImage[i] = this->LoadBMP(vstrFilePaths[i].c_str())) ) //有一個讀不到就不繼續執行,不然就是要改塞白色。
{
Status = FALSE;
}
} //End of for ( unsigned int i = 0 ; i < vstrFilePaths.size() ; i++ )
if ( !Status ) {
return Status; };
//Another important line to double check.
// I can't begin to tell you how many emails I've received from people asking "why am I only seeing one texture,
// or why are my textures all white!?!".
// Usually this line is the problem.
// If you were to replace the 2 with a 1, only one texture would be created and the second texture would appear all white.
// If you replaced the 2 with a 3 you're program may crash!
//You should only have to call glGenTextures() once. After glGenTextures() you should generate all your textures.
// I've seen people put a glGenTextures() line before each texture they create.
// Usually they causes the new texture to overwrite any textures you've already created.
// It's a good idea to decide how many textures you need to build, call glGenTextures() once, and then build all the textures.
// It's not wise to put glGenTextures() inside a loop unless you have a reason to.
//--------- L.6 ------------
//Now that we've loaded the image data into TextureImage[0], we will build a texture using this data.
// The first line glGenTextures(1, &texture[0]) tells OpenGL we want to generate one texture name
// (increase the number if you load more than one texture).
// Remember at the very beginning of this tutorial we created room for one texture with the line GLuint texture[1].
// Although you'd think the first texture would be stored at &texture[1] instead of &texture[0], it's not.
// The first actual storage area is 0.
// If we wanted two textures we would use GLuint texture[2] and the second texture would be stored at texture[1].
//The second line glBindTexture(GL_TEXTURE_2D, texture[0]) tells OpenGL to bind the named texture texture[0] to a texture target.
// 2D textures have both height (on the Y axes) and width (on the X axes).
// The main function of glBindTexture is to assign a texture name to texture data.
// In this case we're telling OpenGL there is memory available at &texture[0].
// When we create the texture, it will be stored in the memory that &texture[0] references.
//--------- L.6 ------------
glGenTextures((GLsizei)DS_GL_MAX_TEXTURE, &this->m_glTextureList[0]); //Create n Texture
for ( unsigned int i = 0 ; i < this->m_vstrTextureFilePath.size() ; i++ ) // Loop Through All The Textures
{
//Build All The Textures
glBindTexture(GL_TEXTURE_2D, this->m_glTextureList[i]);
//----------- L.6 ---------------
//The next two lines tell OpenGL what type of filtering to use when the image is larger (GL_TEXTURE_MAG_FILTER) or
// stretched on the screen than the original texture, or when it's smaller (GL_TEXTURE_MIN_FILTER) on the screen than the actual texture.
// I usually use GL_LINEAR for both. This makes the texture look smooth way in the distance, and when it's up close to the screen.
// Using GL_LINEAR requires alot of work from the processor/video card, so if your system is slow, you might want to use GL_NEAREST.
// A texture that's filtered with GL_NEAREST will appear blocky when it's stretched. You can also try a combination of both.
// Make it filter things up close, but not things in the distance.
//----------- L.6 ---------------
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//----------- L.6 ---------------
//Next we create the actual texture. The following line tells OpenGL the texture will be a 2D texture (GL_TEXTURE_2D).
// Zero represents the images level of detail, this is usually left at zero. Three is the number of data components.
// Because the image is made up of red data, green data and blue data, there are three components.
// TextureImage[0]->sizeX is the width of the texture. If you know the width, you can put it here,
// but it's easier to let the computer figure it out for you.
// TextureImage[0]->sizey is the height of the texture. zero is the border.
// It's usually left at zero. GL_RGB tells OpenGL the image data we are using is made up of red, green and blue data in that order.
// GL_UNSIGNED_BYTE means the data that makes up the image is made up of unsigned bytes, and finally...
// TextureImage[0]->data tells OpenGL where to get the texture data from.
// In this case it points to the data stored in the TextureImage[0] record.
//----------- L.6 ---------------
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[i]->sizeX, TextureImage[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[i]->data);
} //End of for ( int i = 0 ; i < DS_GL_MAX_TEXTURE ; i++ )
/* } */
//The following lines of code check to see if the bitmap data we loaded to build our textures is using up ram.
// If it is, the ram is freed. Notice we check and free both rgb image records.
// If we used 3 different images to build our textures, we'd check and free 3 rgb image records.
//---------- L.6 ---------------
//Now we free up any ram that we may have used to store the bitmap data. We check to see if the bitmap data was stored in TextureImage[0].
// If it was we check to see if the data has been stored. If data was stored, we erase it.
// Then we free the image structure making sure any used memory is freed up.
//---------- L.6 ---------------
for ( int i = 0 ; i < this->m_vstrTextureFilePath.size() ; i++ )
{
if ( TextureImage[i] ) // If Texture Exists
{
if ( TextureImage[i]->data ) { //If Texture Image Exists
free(TextureImage[i]->data); }; //Free the Texture Image Memory
free(TextureImage[i]); //Free The Image Structure
} //End of if ( TextureImage[i] )
} //End of for ( int i = 0 ; i < DS_GL_MAX_TEXTURE ; i++ )
return Status; // Return The Status
}
void COpenGLDrawer::glInitialize(void)
{
....
if ( !this->LoadGLTextures(this->m_vstrTextureFilePath) ) {
return; };
....
}
void CDSGLDrawer::glDrawScene(void)
{
//Show Texture
//The next line of code selects which texture we want to use.
// If there was more than one texture you wanted to use in your scene,
// you would select the texture using glBindTexture(GL_TEXTURE_2D, texture[number of texture to use]).
// If you wanted to change textures, you would bind to the new texture.
// One thing to note is that you can NOT bind a texture inside glBegin() and glEnd(), you have to do it before or after glBegin().
// Notice how we use glBindTextures to specify which texture to create and to select a specific texture.
glBindTexture(GL_TEXTURE_2D, this->m_glTextureList[0]); // Select Our Texture
//To properly map a texture onto a quad, you have to make sure the top right of the texture is mapped to the top right of the quad.
// The top left of the texture is mapped to the top left of the quad,
// the bottom right of the texture is mapped to the bottom right of the quad, and finally,
// the bottom left of the texture is mapped to the bottom left of the quad.
// If the corners of the texture do not match the same corners of the quad, the image may appear upside down, sideways, or not at all.
//The first value of glTexCoord2f is the X coordinate.
// 0.0f is the left side of the texture. 0.5f is the middle of the texture, and 1.0f is the right side of the texture.
// The second value of glTexCoord2f is the Y coordinate. 0.0f is the bottom of the texture.
// 0.5f is the middle of the texture, and 1.0f is the top of the texture.
//So now we know the top left coordinate of a texture is 0.0f on X and 1.0f on Y, and the top left vertex of a quad is -1.0f on X,
// and 1.0f on Y.
// Now all you have to do is match the other three texture coordinates up with the remaining three corners of the quad.
//Try playing around with the x and y values of glTexCoord2f.
// Changing 1.0f to 0.5f will only draw the left half of a texture from 0.0f (left) to 0.5f (middle of the texture).
// Changing 0.0f to 0.5f will only draw the right half of a texture from 0.5f (middle) to 1.0f (right).
//--------------- L.6 -------------------
//If everything went OK, and the texture was created, we enable 2D texture mapping.
// If you forget to enable texture mapping your object will usually appear solid white, which is definitely not good.
//--------------- L.6 -------------------
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glPolygonMode(GL_FRONT, GL_FILL); //Set polygon rasterization mode
glColor3f(1.0f, 1.0f, 1.0f); //用來重設顏色,如果前面這個位置有被繪製圖形,就必須做此動作。反之則無所謂。
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(this->m_vcdsGrid[0].LB.x, this->m_vcdsGrid[0].LB.y); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f);
glVertex2f(this->m_vcdsGrid[0].RB.x, this->m_vcdsGrid[0].RB.y); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f);
glVertex2f(this->m_vcdsGrid[0].RT.x, this->m_vcdsGrid[0].RT.y); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f);
glVertex2f(this->m_vcdsGrid[0].LT.x, this->m_vcdsGrid[0].LT.y); // Top Left Of The Texture and Quad
glEnd();
glDisable(GL_TEXTURE_2D); //Disable texture mapping
}
HBITMAP hBMP= (HBITMAP)LoadImage(NULL,"c:\\temp\\noname.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if ( !hBMP ) {
CDSMsgShower::ShowMsgByErrorBox(this->m_hWnd, "ERROR", MB_OK, "Fail to load bmp file. Error =%d", ::GetLastError());
}
CBitmap *pBMP = new CBitmap;
pBMP->Attach(hBMP);
if (!m_cImageList.Create(16,16, ILC_COLOR16|ILC_MASK, 6, 6))
AfxMessageBox("Problem in creating ImageList");
this->m_cImageList.Add(pBMP, RGB(255, 255, 255)); //Mask部分如沒有其他顏色要過濾掉的話,就設成白色
this->GetMenu()->GetSubMenu(nSubMenuIndex)->EnableMenuItem(ID_SUB_MENU_ITEM, MF_GRAYED);
this->GetMenu()->EnableMenuItem(1, MF_GRAYED|MF_BYPOSITION);
void COpenGLDrawer::OnObjectSelection(CPoint point, COLORREF clrPickColor)
{
GLuint buffer[512]; // Set Up A Selection Buffer
GLint hits = 0; // The Number Of Objects That We Selected
//Now we set up a viewport. viewport[] will hold the current x, y, length and width of the current viewport (OpenGL Window).
//glGetIntegerv(GL_VIEWPORT, viewport) gets the current viewport boundries and stores them in viewport[].
// Initially, the boundries are equal the the OpenGL window dimensions.
// glSelectBuffer(512, buffer) tells OpenGL to use buffer for it's selection buffer.
// The Size Of The Viewport. [0] Is <x>, [1] Is <y>, [2] Is <length>, [3] Is <width>
GLint viewport[4];
// This Sets The Array <viewport> To The Size And Location Of The Screen Relative To The Window
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(512, buffer); // Tell OpenGL To Use Our Array For Selection
//All of the code below is very important. The first line puts OpenGL in selection mode.
// In selection mode, nothing is drawn to the screen.
// Instead, information about objects rendered while in selection mode will be stored in the selection buffer.
//Next we initialize the name stack by calling glInitNames() and glPushName(0).
// It's important to note that if the program is not in selection mode, a call to glPushName() will be ignored.
// Of course we are in selection mode, but it's something to keep in mind.
// Puts OpenGL In Selection Mode. Nothing Will Be Drawn. Object ID's and Extents Are Stored In The Buffer.
(void) glRenderMode(GL_SELECT);
glInitNames(); // Initializes The Name Stack
glPushName(0); // Push 0 (At Least One Entry) Onto The Stack
//After preparing the name stack, we have to to restrict drawing to the area just under our crosshair.
// In order to do this we have to select the projection matrix. After selecting the projection matrix we push it onto the stack.
// We then reset the projection matrix using glLoadIdentity().
//We restrict drawing using gluPickMatrix().
// The first parameter is our current mouse position on the x-axis, the second parameter is the current mouse position on the y-axis,
// then the width and height of the picking region. Finally the current viewport[].
// The viewport[] indicates the current viewport boundaries. mouse_x and mouse_y will be the center of the picking region.
glMatrixMode(GL_PROJECTION); // Selects The Projection Matrix
glPushMatrix(); // Push The Projection Matrix
glLoadIdentity(); // Resets The Matrix
// This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is.
/*gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y), 1.0f, 1.0f, viewport);*/
gluPickMatrix((GLdouble) point.x, (GLdouble) (viewport[3]-point.y), 1.0f, 1.0f, viewport); //輸入為Windows Coordinate of DrawScene
//Calling gluPerspective() multiplies the perspective matrix by the pick matrix which restricts the drawing to the area requested by
// gluPickMatrix().
//We then switch to the modelview matrix and draw our targets by calling DrawTargets().
// We draw the targets in DrawTargets() and not in Draw() because we only want selection to check for hits with objects (targets) and
// not the sky, ground or crosshair.
//After drawing our targets, we switch back to the projection matrix and pop the stored matrix off the stack.
// We then switch back to the modelview matrix.
//The last line of code below switches back to render mode so that objects we draw actually appear on the screen.
// hits will hold the number of objects that were rendered in the viewing area requested by gluPickMatrix().
// Apply The Perspective Matrix
/* gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f); */
gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
DrawTargets(); // Render The Targets To The Selection Buffer
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPopMatrix(); // Pop The Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
hits=glRenderMode(GL_RENDER); // Switch To Render Mode, Find Out How Many
//Now we check to see if there were more than 0 hits recorded.
// If so, we set choose to equal the name of the first object drawn into the picking area.
// depth holds how deep into the screen, the object is.
//Each hit takes 4 items in the buffer. The first item is the number of names on the name stack when the hit occured.
// The second item is the minimum z value of all the verticies that intersected the viewing area at the time of the hit.
// The third item is the maximum z value of all the vertices that intersected the viewing area at the time of the hit and the last item
// is the content of the name stack at the time of the hit (name of the object).
// We are only interested in the minimum z value and the object name in this tutorial.
if (hits > 0) // If There Were More Than 0 Hits
{
int choose = buffer[3]; // Make Our Selection The First Object
int depth = buffer[1]; // Store How Far Away It Is
//We then loop through all of the hits to make sure none of the objects are closer than the first object hit.
// If we didn't do this, and two objects were overlapping, the first object hit might behind another object,
// and clicking the mouse would take away the first object, even though it was behind another object. When you shoot at something,
// the closest object should be the object that gets hit.
//So, we check through all of the hits.
// Remember that each object takes 4 items in the buffer, so to search through each hit we have to multiply the current loop value by 4.
// We add 1 to get the depth of each object hit.
// If the depth is less than the the current selected objects depth,
// we store the name of the closer object in choose and we store the depth of the closer object in depth.
// After we have looped through all of our hits, choose will hold the name of the closest object hit,
// and depth will hold the depth of the closest object hit.
/*
for (int loop = 1; loop < hits; loop++) // Loop Through All The Detected Hits
{
// If This Object Is Closer To Us Than The One We Have Selected
if (buffer[loop*4+1] < GLuint(depth))
{
choose = buffer[loop*4+3]; // Select The Closer Object, sample use the offset 3.
depth = buffer[loop*4+1]; // Store How Far Away It Is
}
} //End of for (int loop = 1; loop < hits; loop++)
*/
//All we have to do is mark the object as being hit. We check to make sure the object has not already been hit.
// If it has not been hit, we mark it as being hit by setting hit to TRUE.
// We increase the players score by 1 point, and we increase the kills counter by 1.
/*
if (!object[choose].hit) // If The Object Hasn't Already Been Hit
{
object[choose].hit=TRUE; // Mark The Object As Being Hit
score+=1; // Increase Score
kills+=1; // Increase Level Kills
*/
this->m_vcdsGrid4AStar[choose].IsWarkable = !this->m_vcdsGrid4AStar[choose].IsWarkable;
this->m_vcdsGrid4AStar[choose].clrSelectedColor = clrPickColor;
//I use kills to keep track of how many objects have been destroyed on each level.
// I wanted each level to have more objects (making it harder to get through the level).
// So I check to see if the players kills is greater than the current level multiplied by 5.
// On level 1, the player only has to kill 5 objects (1*5).
// On level 2 the player has to kill 10 objects (2*5), progressively getting harder each level.
//So, the first line of code checks to see if kills is higher than the level multiplied by 5. If so, we set miss to 0.
// This sets the player morale back to 10 out of 10 (the morale is 10-miss).
// We then set kills to 0 (which starts the counting process over again).
//Finally, we increase the value of level by 1 and check to see if we've hit the last level.
// I have set the maximum level to 30 for the following two reasons... Level 30 is insanely difficult.
// I am pretty sure no one will ever have that good of a game. The second reason... At the top of the code, we only set up 30 objects.
// If you want more objects, you have to increase the value accordingly.
//It is VERY important to note that you can have a maximum of 64 objects on the screen (0-63).
// If you try to render 65 or more objects, picking becomes confused, and odd things start to happen.
// Everything from objects randomly exploding to your computer crashing. It's a physical limit in OpenGL (just like the 8 lights limit).
//If by some chance you are a god, and you finish level 30, the level will no longer increase, but your score will.
// Your morale will also reset to 10 every time you finish the 30th level.
/*
if (kills>level*5) // New Level Yet?
{
miss=0; // Misses Reset Back To Zero
kills=0; // Reset Level Kills
level+=1; // Increase Level
if (level>30) // Higher Than 30?
level=30; // Set Level To 30 (Are You A God?)
}
} //End of if (!object[choose].hit)
*/
} //End of if (hits > 0)
}
void COpenGLDrawer::DrawTargets(void)
{
glLoadIdentity(); // Reset The Modelview Matrix
/* glTranslatef(0.0f,0.0f, -10.0f); // Move Into The Screen 20 Units //NOTE:This is the KEY for Picking!!! */
glTranslatef( this->m_fPosX, this->m_fPosY, -20);
/*for (int loop=0; loop<level; loop++) // Loop Through 9 Objects*/
for ( unsigned int loop = 0 ; loop < this->m_vcdsGrid.size() ; loop++ )
{
//The first line of code is the secret to picking individual objects.
// What it does is assigns a name (number) to each object. The first object drawn will be 0.
// The second object will be 1, etc... If the loop was to hit 29, the last object drawn would be given the name 29.
// After assigning a name to the object, we push the modelview matrix onto the stack.
// It's important to note the calls to glLoadName() are ignored if the program is not in selection mode.
//We then move to the location on the screen where we want our object to be drawn.
// We use object[loop].x to position on the x-axis, object[loop].y to position on the y-axis and object[loop].distance to position
// the object on the z-axis (depth into the screen).
// We have already translated 10 units into the screen, so the actual distance at which the object will be drawn is going to
// be object[loop].distance-10.0f.
glLoadName(loop); // Assign Object A Name (ID)
glPushMatrix(); // Push The Modelview Matrix
/*glTranslatef(object[loop].x,object[loop].y,object[loop].distance); // Position The Object (x,y)*/
//Before we draw the object, we have to check if it's been hit or not.
// We do this by checking to see if object[loop].hit is TRUE.
// If it is, we jump to Explosion(loop) which will draw the explosion animation instead of the actual object.
// If the object was not hit, we spin the object on it's z-axis by object[loop].spin degrees before we call Object().
//Object takes 3 parameters. The first one is the width, the second one is the height and the third one is the number of the texture to use.
// To get the width and height, we use the array size[object[loop].texid].w and size[object[loop].texid].h.
// This looks up the width and height from our predefined object size array at the beginning of this program.
// The reason we use object[loop].texid is because it represents the type of object we are drawing.
// A texid of 0 is always the blueface... a texid of 3 is always the coke can, etc.
//After drawing an object, we pop the matrix resetting the view, so our next object is drawn at the proper location on the screen.
/* if (object[loop].hit) // If Object Has Been Hit
{
Explosion(loop); // Draw An Explosion
}
else // Otherwise
{
glRotatef(object[loop].spin,0.0f,0.0f,1.0f); // Rotate The Object
Object(size[object[loop].texid].w,size[object[loop].texid].h,object[loop].texid); // Draw The Object
}
*/
//if ( !this->m_vcdsGrid4AStar[loop].IsWarkable )
//{
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// glBegin(GL_QUADS);
// glColor3f(0.48f, 0.44f, 1.0f); //Light Slate Blue
// glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.LB.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.LB.y);
// glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.RB.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.RB.y);
// glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.RT.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.RT.y);
// glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.LT.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.LT.y);
// glEnd();
//} //End of if ( !this->m_vcdsGrid4AStar[loop].IsWarkable )
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Set polygon rasterization mode
//Must fill it and the
glBegin(GL_QUADS); //Start to draw squares
glColor3f(0.0f, 0.0f, 0.0f); //Black
for ( unsigned int i = 0 ; i < this->m_vcdsGrid.size() ; i++ )
{
//3D
//glVertex3f(this->m_vcdsGrid[i].LB.x, this->m_vcdsGrid[i].LB.y, this->m_vcdsGrid[i].LB.z);
//glVertex3f(this->m_vcdsGrid[i].RB.x, this->m_vcdsGrid[i].RB.y, this->m_vcdsGrid[i].RB.z);
//glVertex3f(this->m_vcdsGrid[i].RT.x, this->m_vcdsGrid[i].RT.y, this->m_vcdsGrid[i].RT.z);
//glVertex3f(this->m_vcdsGrid[i].LT.x, this->m_vcdsGrid[i].LT.y, this->m_vcdsGrid[i].LT.z);
//2D
//glVertex2f(this->m_vcdsGrid[i].LB.x, this->m_vcdsGrid[i].LB.y);
//glVertex2f(this->m_vcdsGrid[i].RB.x, this->m_vcdsGrid[i].RB.y);
//glVertex2f(this->m_vcdsGrid[i].RT.x, this->m_vcdsGrid[i].RT.y);
//glVertex2f(this->m_vcdsGrid[i].LT.x, this->m_vcdsGrid[i].LT.y);
glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.LB.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.LB.y);
glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.RB.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.RB.y);
glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.RT.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.RT.y);
glVertex2f(this->m_vcdsGrid4AStar[loop].cdsGridInfo.LT.x, this->m_vcdsGrid4AStar[loop].cdsGridInfo.LT.y);
} //End of for ( unsigned int i = 0 ; i < this->m_vcpGrid.size() ; i++ )
glEnd();
glPopMatrix(); // Pop The Modelview Matrix
} //End of for (int loop=0; loop<level; loop++)
}
....
glColor3f(GetRValue(clrSelectedColor*1.0f/255,
GetGValue(clrSelectedColor)*1.0f/255,
GetBValue(clrSelectedColor)*1.0f/255);
....
CDSVector3d COpenGLDrawer::ConvertWinPos2OGLPos(int x, int y)
{
//Reference:http://nehe.gamedev.net/data/articles/article.asp?article=13
//1. Viewport Origin And Extent
// We need to grab the current viewport.
// The information we need is the starting X and Y position of our GL viewport along with the viewport width and height.
// Once we get this information using glGetIntegerv(GL_VIEWPORT, viewport), viewport will hold the following information:
// viewport[0]=x
// viewport[1]=y
// viewport[2]=width
// viewport[3]=height
GLint glnViewPort[4]; //Where the Viewport will be stored
::glGetIntegerv(GL_VIEWPORT, glnViewPort); //Retrieves the Viewport values (X, Y, Width, Height)
//2. The Modelview Matrix
// Once we have the viewport information, we can grab the Modelview information.
// The Modelview Matrix determines how the vertices of OpenGL primitives are transformed to eye coordinates.
GLdouble gldModelView[16]; //Where the 16 doubles of the Modelview matrix are to be stored
::glGetDoublev(GL_MODELVIEW_MATRIX, gldModelView); //Retrieve the Modelview Matrix
//3. The Projection Matrix
// After that, we need to get the Projection Matrix. The Projection Matrix transforms vertices in eye coordinates to clip coordinates.
GLdouble gldProjection[16]; //Where the 16 doubles of the Projection Matrix are to be strored
::glGetDoublev(GL_PROJECTION_MATRIX, gldProjection); //Retrieve the Projetion Matrix
//4. The Windows Screen Coordinates
// After we have done all of that, we can grab the Windows screen coordinates. We are interested in the current mouse position.
GLfloat glfWinX = 0.0f, glfWinY = 0.0f, glfWinZ = 0.0f; //Holds Our X, y and Z coordinates
glfWinX = (float)x; //Holds the mouse X Coordinate
glfWinY = (float)y; //Holds the mouse Y Corrdinate
//Now Windows coordinates start with (0, 0) being at the top left whereas OpenGL coords start at the lower left. To convert to OpenGL coordinates we do the following:
glfWinY = (float)(glnViewPort[3] - glfWinY); //Subtract the current Mouse Y Corrdinate from the screen height.
//Get z corrdinate
::glReadPixels(glfWinX, glfWinY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &glfWinZ);
//5. Variables Where The Output OpenGL Coords Will Be Stored
// All that is left to do is calculate our final OpenGL coordinates.
GLdouble gldPosX, gldPosY, gldPosZ; //Hold the Final value
::gluUnProject( glfWinX, glfWinY, glfWinZ, gldModelView, gldProjection, glnViewPort, &gldPosX, &gldPosY, &gldPosZ);
return CDSVector3d(gldPosX, gldPosY, gldPosZ);
}
....
CImageList m_cImageList;
....
if ( !m_cImageList.Create(IDB_BMP_ICON, 16, 2, RGB(0, 0, 0)) ) {
CDSMsgShower::ShowMsgByErrorBox(this->m_hWnd, "ACCERT", MB_OK, "Fail to create image list."); };
this->m_treEnvItems.SetImageList(&m_cImageList, TVSIL_NORMAL);
....
this->m_treEnvItems.SetItemImage(hEnvItemsTree, 0, 1);
Build docker image from multiple build contexts ...