Jump to content
  • Advertisement
Sign in to follow this  
GTuan

OpenGL How to draw with mouse

This topic is 2531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I move the mouse into the world with gluUnProject.I am still thinking how to enable the relocation Z.Now I'm using OpenGL CSgl but I think the code is nothing else csgl.How can I draw a straight line with a mouse?
This line can be converted to curves then.Since then a small model was built.

Share this post


Link to post
Share on other sites
Advertisement
i blame myselfbut for doing such things i use colors not depth reading stuff




look at this"









//panel verts
//X1----X2
//
//
//X4----X3
void __fastcall TInteractiveDisplayPanel_missle_lock_system::OnClickEvent(int X, int Y,int wholescreenheight, int wholescreenwidth, float glopa, float headinga, t3dpoint olda)
{
FoundObject = -1;
glPushMatrix();
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);


SUPERPOINT.x = 100000.0f*(sin(glopa*imopi)*cos(headinga*imopi));
SUPERPOINT.z = 100000.0f*(cos(glopa*imopi)*cos(headinga*imopi));
SUPERPOINT.y = 100000.0f*(sin(headinga*imopi));







gluLookAt(olda.x,olda.y,olda.z,olda.x+SUPERPOINT.x,
olda.y-SUPERPOINT.y,olda.z-SUPERPOINT.z,
0.0f,1.0f,0.0f);

int R;
int G;
int B;
int A;
// PanelModel->DrawSimpleModel();
glColor3f(0.0,1.0,0.0);
glBegin(GL_QUADS);
glVertex3f(PanelModel->VBO_V[0].x,PanelModel->VBO_V[0].y,PanelModel->VBO_V[0].z);
glVertex3f(PanelModel->VBO_V[1].x,PanelModel->VBO_V[1].y,PanelModel->VBO_V[1].z);
glVertex3f(PanelModel->VBO_V[2].x,PanelModel->VBO_V[2].y,PanelModel->VBO_V[2].z);
glVertex3f(PanelModel->VBO_V[3].x,PanelModel->VBO_V[3].y,PanelModel->VBO_V[3].z);
glEnd();
glColor3f(1.0,1.0,1.0);
// ZAPISZ_WIDOK_DO_PLIKU_BITMAPY("E:\\tp1.bmp",wholescreenwidth,wholescreenheight);
READ_RGBA_FROM_OGL_WINDOW(X,wholescreenheight,Y,R,G,B,A);

if ( (R == 0) && (G == 255) && (B == 0) ) { //clicked at panel

glBegin(GL_QUADS); // Get Y coordinate
glColor3f(1.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[0].x,PanelModel->VBO_V[0].y,PanelModel->VBO_V[0].z);
glColor3f(1.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[1].x,PanelModel->VBO_V[1].y,PanelModel->VBO_V[1].z);
glColor3f(0.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[2].x,PanelModel->VBO_V[2].y,PanelModel->VBO_V[2].z);
glColor3f(0.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[3].x,PanelModel->VBO_V[3].y,PanelModel->VBO_V[3].z);
glEnd();
// ZAPISZ_WIDOK_DO_PLIKU_BITMAPY("E:\\tp2.bmp",wholescreenwidth,wholescreenheight);
READ_RGBA_FROM_OGL_WINDOW(X,wholescreenheight,Y,R,G,B,A);

//float supY = wholescreenheight * float®/255.0f;
PanelCurY = 240.0f * (float® / 255.0f);
glDisable(GL_DEPTH_TEST);


glBegin(GL_QUADS); // Get X coordinate
glColor3f(0.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[0].x,PanelModel->VBO_V[0].y,PanelModel->VBO_V[0].z);
glColor3f(1.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[1].x,PanelModel->VBO_V[1].y,PanelModel->VBO_V[1].z);
glColor3f(1.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[2].x,PanelModel->VBO_V[2].y,PanelModel->VBO_V[2].z);
glColor3f(0.0,0.0,0.0);
glVertex3f(PanelModel->VBO_V[3].x,PanelModel->VBO_V[3].y,PanelModel->VBO_V[3].z);
glEnd();
// ZAPISZ_WIDOK_DO_PLIKU_BITMAPY("E:\\tp3.bmp",wholescreenwidth,wholescreenheight);
READ_RGBA_FROM_OGL_WINDOW(X,wholescreenheight,Y,R,G,B,A);


//float supX = wholescreenwidth * float®/255.0f;

glEnable(GL_DEPTH_TEST);
PanelCurX = 320.0f * (float® / 255.0f);
FoundObject = OpticalRecognitionTHREAD->FindObjectByCoords(PanelCurX,PanelCurY); //muahahaha :D
}//if we hit teh panel

glPopMatrix();



}









[/quote]




he he







or you can create your own cursor and







TPolygon CreatePoly(t3dpoint p,t3dpoint punkt_na_plaszczyznie, float SIZE)
{
// SIZE = 16384.0;
TPolygon Result;
t3dpoint n, tmp;
float a, b, c,d;

d = getplaneD(p,punkt_na_plaszczyznie);
// Create a huge polygon on the given plane.

//Result.Count := 4;

a = abs(p.x);
b = abs(p.y);
c = abs(p.z);

if ((a >= b) && (a >= c) ) {
// Plane is mostly YZ-aligned.
Result.V[0] = triplesingletoT3DPOINT(-(p.y*-SIZE + p.z*-SIZE + d)/p.x, -SIZE, -SIZE);
Result.V[1] = triplesingletoT3DPOINT(-(p.y*SIZE + p.z*-SIZE + d)/p.x, SIZE, -SIZE);
Result.V[2] = triplesingletoT3DPOINT(-(p.y*SIZE + p.z*SIZE + d)/p.x, SIZE, SIZE);
Result.V[3] = triplesingletoT3DPOINT(-(p.y*-SIZE + p.z*SIZE + d)/p.x, -SIZE, SIZE);
}
if ( (b >= a) && (b >= c) ) {
// Plane is mostly XZ-aligned.
Result.V[0] = triplesingletoT3DPOINT(-SIZE, -(p.x*-SIZE + p.z*-SIZE +d)/p.y, -SIZE);
Result.V[1] = triplesingletoT3DPOINT(SIZE, -(p.x*SIZE + p.z*-SIZE + d)/p.y, -SIZE);
Result.V[2] = triplesingletoT3DPOINT(SIZE, -(p.x*SIZE + p.z*SIZE + d)/p.y, SIZE);
Result.V[3] = triplesingletoT3DPOINT(-SIZE, -(p.x*-SIZE + p.z*SIZE + d)/p.y, SIZE);
}
if ( (c >= a) && (c >= b) ) {
// Plane is mostly XY-aligned.
Result.V[0] = triplesingletoT3DPOINT(-SIZE, -SIZE, -(p.x*-SIZE + p.y*-SIZE + d)/p.z);
Result.V[1] = triplesingletoT3DPOINT(SIZE, -SIZE, -(p.x*SIZE + p.y*-SIZE + d)/p.z);
Result.V[2] = triplesingletoT3DPOINT(SIZE, SIZE, -(p.x*SIZE + p.y*SIZE + d)/p.z);
Result.V[3] = triplesingletoT3DPOINT(-SIZE, SIZE, -(p.x*-SIZE + p.y*SIZE + d)/p.z);

}
n = vectorcross(vectors_substract_v1minusv2(Result.V[0], Result.V[1]),
vectors_substract_v1minusv2(Result.V[2], Result.V[1]));
Result.normal = p;
Result.Count = 4;
if (Dot(p, n) <= 0 ) {
tmp = Result.V[1];
Result.V[1] = Result.V[3];
Result.V[3] = tmp;
}
return Result;
}



[/quote]

Share this post


Link to post
Share on other sites
Sorry,I late.A traffic accident.I t forced me to rest.Thank for help.I have a code using csgl.But 'csgl' similar to the C + + console.

public void Draw(float xt,float yt,float zt)
{
GL.glLoadIdentity ();
GL.glTranslatef(0.0F, 0.0F, 0.0F);
GL.glRotatef(r, 0.0F, 1.0F, 0.0F);
OpenGL.glPointSize(20);
GL.glColor3f (1.0F, 1.0F, 0.0F);
GL.glBegin (Convert.ToUInt32 (GLFlags.GL_LINE_STRIP));
for (int iz = 0; iz <=i; iz++)
{
GL.glVertex3f(_posX[iz], _posY[iz], _posZ[iz]);//_posX,_posY,_posZ is float
}
GL.glEnd();

}


//mousedown to get mouse postion
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
mposWinX1 = e.X;//Xmouse
mposWinY1 = e.Y;//Ymouse
convert2dto3d(int.Parse(mposWinX1.ToString()), int.Parse(mposWinY1.ToString()), 1);
_posX = float.Parse(mposWldX.ToString());
_posY = float.Parse(mposWldY.ToString());
_posZ = float.Parse(mposWldZ.ToString());

}
//convert mouse to world
public void convert2dto3d(int _winX,int _winY,int _winZ)
{
int[] viewp = new int[4];
double[] modelview = new double[16];
double[] proj = new double[16];
int winX;
int winY, winZ;
GL.glGetDoublev(Convert.ToUInt32(GLFlags.GL_MODELVIEW_MATRIX), modelview);
GL.glGetDoublev (Convert.ToUInt32 (GLFlags.GL_PROJECTION_MATRIX),proj);
GL.glGetIntegerv(Convert.ToUInt32(GLFlags.GL_VIEWPORT), viewp);
winX = _winX;
winY = viewp[3]-_winY;
winZ = _winZ;
GL.gluUnProject(winX, winY, winZ, modelview, proj, viewp,out mposWldX,out mposWldY,out mposWldZ);
}



//It like glDisplayFunc(void);
public override void glDraw()
{
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Clear The Screen And The Depth Buffer
GL.glLoadIdentity(); // Reset The Current Modelview Matrix
// TODO: Draw a box or something
Draw(float.Parse(mposWldX.ToString()), float.Parse(mposWldY.ToString()), float.Parse(mposWldZ.ToString()));
this.SwapBuffer(); // swap Buffers
if (bRot)
{
r += 3.0F;
}
}

I can draw a straight line.When rotated, it does not rotate around its center.Why?:huh:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!