Jump to content

  • Log In with Google      Sign In   
  • Create Account


sujandasmahapatra

Member Since 14 Apr 2009
Offline Last Active Aug 09 2014 11:24 AM

Topics I've Started

rotating 2 objects 1 remains static problem opengl

05 March 2013 - 02:32 AM

I want to rotate 2 objects out of 3. One object should remain static. But it’s not happening. Please help. I using glPushMatrix() and glPopMatrix() for the objects that I want to rotate.

 

void CopenGLCoordView::DrawScene(CDC *pDC)
{
    wglMakeCurrent(pDC->m_hDC, m_hrc);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
    drawLine();
 
    glLoadIdentity();
    glPushMatrix();
    glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
    glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
    glRotatef(rot[2], 0.0f, 0.0f, 1.0f);
    drawAxes();
    glPrintX("X");
    glPrintY("Y");
    glPrintZ("Z");
    glPopMatrix();
 
    
 
    glFlush();
    SwapBuffers(pDC->m_hDC);    
    wglMakeCurrent(NULL, NULL);
}

 

With the above code nothing is rotating. I want the drawLine() line should be static while the axis and x,y,z should rotate. Please help how can I achieve this?..Thanks Sujan


Please give me some idea 3D surface of revolution

22 September 2011 - 08:13 AM

Dear Friends
I have a dataset like below. 1 means Straight line with startPointX,startPointY,endPointX,endPointY.

//////////////////////////////////////////////////////////////
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -178.200000 52.000000 -138.200000 52.000000
1 0.000000 24.600000 0.000000 19.000000
1 -125.421613 36.515000 -138.200000 52.000000
1 -123.421613 36.515000 -107.873000 36.515000
1 -100.000000 19.000000 0.000000 19.000000
1 -105.873000 36.515000 -94.557821 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -100.000000 19.000000 0.000000 19.000000
1 0.000000 19.000000 0.000000 24.600000
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -94.557821 36.515000 -105.873000 36.515000
1 -107.873000 36.515000 -123.421613 36.515000
1 -125.421613 36.515000 -138.200000 52.000000
1 -138.200000 52.000000 -178.200000 52.000000
1 -115.000000 0.000000 -115.000000 15.000000
1 -115.000000 15.000000 -100.000000 15.000000
1 -100.000000 15.000000 -100.000000 19.000000
1 -100.000000 19.000000 0.200000 19.000000
1 0.200000 19.000000 0.000000 19.000000
1 0.000000 19.000000 0.000000 24.574923
1 0.000000 24.574923 -0.000000 24.600000
1 0.000000 24.600000 -15.500000 28.575000
1 -15.500000 28.575000 -37.700000 28.575000
1 -37.700000 28.575000 -37.700000 36.515000
1 -37.700000 36.515000 -59.920000 36.515000
1 -59.920000 36.515000 -66.103821 36.515000
1 -66.103821 36.515000 -88.374000 36.515000
1 -88.374000 36.515000 -94.557821 36.515000
1 -94.557821 36.515000 -105.873000 36.515000
1 -105.873000 36.515000 -107.873000 36.515000
1 -107.873000 36.515000 -123.421613 36.515000
1 -123.421613 36.515000 -125.421613 36.515000
1 -125.421613 36.515000 -138.200000 52.000000
1 -138.200000 52.000000 -178.200000 52.000000
1 -178.200000 52.000000 -178.200000 52.500000
1 -178.200000 52.500000 -178.200000 55.000000
1 -178.200000 55.000000 -190.000000 55.000000
1 5.000000 0.000000 5.000000 55.000000
1 5.000000 55.000000 -190.000000 55.000000
//////////////////////////////////////////////////////////////

I have to construct a profile which I can easily do by making a GL_LINES.

After that I need rotate the profile by x-axis and construct a surface of revolution. Please giveme some idea how can I achieve this. I have done something but I am not getting the surface.


Like I am storing the original startPoints and endPoints in an array with assuming z=0.
Then rotating each point by x-axis. so x-values will be same and y and z values I am calculating using this formula.
y = y cosq - z sinq;
z = ysinq + zcosq;

Is this correct...?? Then I am defining a number of loops and in loop I am creating GL_QUADS for each startPoint and endPoint...
1st loop 1ststartPoint, 1stLoop 1stendPoint
2nd loop 1stStartPoint, 2nd loop 1stEndPoint...


But I am not getting any 3D surface. Please help me.........Check the code below.


//////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct point3D{
float x;
float y;
float z;
}POINT3D;

int count1;
POINT3D *startPoints, *endPoints;

void CRevolutionProjView::drawProfile(CString filename)
{
pFrame->m_wndStatusBar.SetPaneText(0,L"DrawProfile !!");

// profile to be drawn

GLfloat PI = 4 * atan(1.0);

//file needs be open
double startPX, startPY, endPX, endPY;
double cenX, cenY, cenZ, rad, startA, endA;
ifstream indata; // indata is like cin
int id; // variable for input value
indata.open(filename); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
count1=0;
while ( !indata.eof() ) { // keep reading until end-of-file
indata >> id;
cout << "The id is " << id << endl;
if(id==1)
{
indata >> startPX >> startPY >> endPX >> endPY;
glBegin(GL_LINES);
glVertex2f(startPX, startPY); // origin of the line
glVertex2f(endPX, endPY); // ending point of the line
glEnd();

if(count1==0)
{
startPoints = (POINT3D *)malloc(sizeof(POINT3D));
endPoints = (POINT3D *)malloc(sizeof(POINT3D));
}
else
{
startPoints = (POINT3D *)realloc(startPoints,sizeof(POINT3D)*(count1+1));
endPoints = (POINT3D *)realloc(endPoints,sizeof(POINT3D) * (count1+1));

}
startPoints[count1].x = startPX;
startPoints[count1].y = startPY;
startPoints[count1].z = 0.0f;
endPoints[count1].x = endPX;
endPoints[count1].y = endPY;
endPoints[count1].z = 0.0f;
count1++;
}
}
indata.close();
cout << "End-of-file reached.." << endl;

}

void CRevolutionProjView::drawSurface()
{

double PI = 4.0 * atan(1.0);

//I have x and y points;

//count1 = numberof points

//theta = 0 to 360 degs.

//nsweep = number of sweeps. 360/nsweep = each angle;
int nsweep=4;

//no of profiles = nsweep + 1...

//each profile will have count1 no of lines...so count1 startpoints and count1 endPoints...

//so...total startPoints and endPoints for (nsweep+1) profiles = (nsweep+1) * count1...

POINT3D *totalStartPoints, *totalEndPoints;
totalStartPoints = new POINT3D[(nsweep+1)*count1];
totalEndPoints = new POINT3D[(nsweep+1)*count1];
int cnt1=0;
double theta, inter;
inter = (360/nsweep) * (PI/180);
theta = 0;
for(int i=0; i<(nsweep+1); i++)
{
for(int j=0; j<count1; j++)
{
totalStartPoints[cnt1].x = startPoints[j].x;
totalStartPoints[cnt1].y = startPoints[j].y * cos(theta) - startPoints[j].z * sin(theta);
totalStartPoints[cnt1].z = startPoints[j].y * sin(theta) + startPoints[j].z * cos(theta);

totalEndPoints[cnt1].x = endPoints[j].x;
totalEndPoints[cnt1].y = endPoints[j].y * cos(theta) - endPoints[j].z * sin(theta);
totalEndPoints[cnt1].z = endPoints[j].y * sin(theta) + endPoints[j].z * cos(theta);
cnt1++;
}

theta = theta + inter;
}

cnt1=0;
glColor3f(1.0f,0.0f,0.0f);
for(int i=0; i<nsweep; i++)
{
for(int j=0; j<count1; j++) {

GLfloat *v0, *v1, *v2, *v3;

v0 = new GLfloat[3];
v1 = new GLfloat[3];
v2 = new GLfloat[3];
v3 = new GLfloat[3];

v0[0] = totalStartPoints[cnt1].x;
v0[1] = totalStartPoints[cnt1].y;
v0[2] = totalStartPoints[cnt1].z;

v1[0] = totalEndPoints[cnt1].x;
v1[1] = totalEndPoints[cnt1].y;
v1[2] = totalEndPoints[cnt1].z;

v2[0] = totalEndPoints[cnt1+count1].x;
v2[1] = totalEndPoints[cnt1+count1].y;
v2[2] = totalEndPoints[cnt1+count1].z;

v3[0] = totalStartPoints[cnt1+count1].x;
v3[1] = totalStartPoints[cnt1+count1].y;
v3[2] = totalStartPoints[cnt1+count1].z;


glBegin(GL_QUADS); // draw a cube with 6 quads
glVertex3fv(v0); // front face
glVertex3fv(v1);
glVertex3fv(v2);
glVertex3fv(v3);
glEnd();
delete v0;
delete v1;
delete v2;
delete v3;
cnt1++;
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////

MFC OpenGL Invalidate Flickering

14 September 2011 - 10:20 AM

Dear Friends
I am wirting an application for drawing a rectangle on the screen using opengl and mfc. So I implemented the OnPaint function, OnDraw function is also giving the same problem. It's drawing fine. I want to implement pan, zoom, and rotate functionalities. Now everytime the mouse moves I am calling Invalidate() or otherwise I can call Invalidate() in the ::OnDraw function. Pan, zoom and rotate everything is happening but its heavily flickering. I have serached a lot and tried all means like return 1 in the OnEraseBackground() functio for WM_ERASEBACKGROUND etc. But I am getting still flickering . Please help getting rid of this problem. Check the code snippet below.



void CRevolutionProjView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect RectAff;
GetClientRect(RectAff);
glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glPushMatrix( ) ;
glTranslatef(trans[0], trans[1], trans[2]);
glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
drawcube();
glPopMatrix( ) ;
glFinish( ) ;
glFlush();
SwapBuffers(hDC);
Invalidate(false);
// Do not call CView::OnPaint() for painting messages
}

void CRevolutionProjView::OnMouseMove(UINT nFlags, CPoint point)
{
newP = point;
// TODO: Add your message handler code here and/or call default
int dx = oldP.x - newP.x;
int dy = newP.y - oldP.y;
switch(STATE)
{
case PAN:
{
trans[0] -= dx/100.0f;
trans[1] -= dy/100.0f;
// Invalidate();
}
break;
case ZOOM:
{
trans[2] -= (dx+dy) / 100.0f;
// Invalidate();
}
break;
case ROTATE:
{
rot[0] += (dy * 180.0f) / 500.0f;
rot[1] -= (dx * 180.0f) / 500.0f;
#define clamp(x) x = x > 360.0f ? x-360.0f : x < -360.0f ? x+=360.0f : x
clamp(rot[0]);
clamp(rot[1]);
// Invalidate();

}
break;
}

oldP = newP;

CView::OnMouseMove(nFlags, point);
}




Aero-mechanical software designs and development

30 November 2010 - 03:40 PM

Dear All
I am a freelancer software developer using QT C++ OPENGL(for 3D Graphics) PythonQt (for scripting automation and session file generation). If anyone interested to explore your project with me please contact at the following details. My specialized areas are CAD/CAE/CAM/CFD AERO MECHANICAL PROBLEMS & DESIGN I can provide remote service.
Thanks & Regards
Sujan Dasmahapatra
B.E. (Aeronautics)
Bangalore, India
Ph:91-9900839788
mail id : sujan.dasmahapatra@gmail.com
yahoo msn : dasmahapatra.aerodynamics@yahoo.co.in
icq # 556023244
skype:sujan.dasmahapatra@skyepe.com
msn: sujan.dasmahapatra@hotmail.com

VC++ MFC QT QWT OPENGL based application JOB WANTED CAD/CAM/CAE/FEA/CFD

29 April 2010 - 07:32 PM

Hi I am looking for work from projects for developing any engineering software CAD/CAM/CAE/FEA/CFD, I am an expert in CC++, VC++,MFC,OPENGL,QT,QWT...in CAD/CAM/CAE/CFD atc... if anyone interested please call me @919900839788

PARTNERS