Hi everybody have not posted in a while. In all truth i am stuck but very close to finding the collision answer.

Note 1 (Most of this skelton was premade for the assignment).
Some variables i don;t even know what they do like Vy1. Incx, Incy.
Stuff like the file stream was added by me to try and get my collisions to work as qt hates intersectwith comes up with an error. using the console to find the location of my squares seems a good idea.

Please can someone point out how to form a collision using intersectswith in opengl as i have tried the standard way. Or help me create a collision between my squares in some way.

I am also thinking about calling the routine i store in the text file back into the QT editior while i compare the values as they are called from the file.

-------------------------------------------------------------------------------------

opengl skelton. header

---------------------------------------------------

#ifndef OGLSKEL_H
#define OGLSKEL_H
#include <QGLWidget>
#include <String>


class OGLSkel : public QGLWidget
{
    Q_OBJECT


public:



    OGLSkel(QWidget *parent = 0);
    float x[8];
    float y[8];
    float z[8];
    float incx;
    float incy;
    float vx1;
    float vy1;
    float xs1;
    float ys1;
    float xs2;
    float ys2;
    float Scale;
    float vi;
    float pi;
    float timeS;
    float xt[1000],yt[1000],Zt[1000];
    int xd[2];
    int yd[2];
    int zd[2];
    float B1x;
    float B2x;
    float B3x;
    float B4x;
    float B1y;
    float B2y;
    
   // char strXShape1;-------------
  //  char strXShape2;
 //   char strXShape3;
//    char strYShape1;-------------
//    char strYShape2;
//    char strYShape3;

    float XShape1;
    float YShape1;
    float XShape2;
    float YShape2;
    float XShape3;
    float YShape3;

    //---------------------------------------------------------------------------

 float r;
 float P;
 float L;
 float N;
    float ys3;
    float xs3;
float DifCollisonX;
float DifCollisonX2;
float Bondary1;


    //---------------------------------------------------------------------------

    float B3y;
    float B4y;
    float B1z;
    float B2z;
    float B3z;
    float B4z;
int MyVariable;
    float ShapeX[1000];
    float ShapeY[1000];
    float ShapeZ[1000];



    bool Go;
protected:
    void initializeGL();
    void resizeGL(int width, int height);
    void paintGL();
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseDoubleClickEvent(QMouseEvent *event);
    void timerEvent(QTimerEvent *event);


private:
    void draw();

};




#endif // OGLSKEL_H


// The OGL.CPP
--------------------------------------------------

#include <QtGui>
#include <QtOpenGL>


#include <iostream> //
#include <stdlib.h> // this was a nightmare to put in

#include "OGLSkel.h"
#include <fstream>
#include <String> // its not needed yet.


using namespace std;


OGLSkel::OGLSkel(QWidget *parent)
    : QGLWidget(parent)
{
    setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
    startTimer(10);

}

void OGLSkel::initializeGL()
 {
     incx=0.0;
     incy=0.0;
     Go=false;
     Scale=3.0;
     yt[0]=0.0;
     xt[0]=0.0;
     yt[1]=0.0;
     xt[1]=0.0;
     xt[2]=0.0;
     xt[2]=0.0;

     //r = 50;






     Bondary1 =0;

     vx1=1.0;
     vy1=1.0;
     ys1=0.0; // (was 0 intially)
     xs1=200.0;
     xs2=200.0;
     ys2=0.0;



     xd[0]=1;
     xd[1]=1;
     yd[0]=1;
     yd[1]=1;
     zd[0]=1;
     zd[1]=1;

    // Boundaries
    B1x=1000.0;
    B2x=0.0;
    B3x=0.0;
    B4x=0.0;
    B1y=0.0;
    B2y=1000.0;
    B3y=0.0;
    B4y=0.0;
    B1z=0;
    B2z=0;
    B3z=1000.0;
    B4z=0;

    // starting positions !!!!!
    ShapeX[0]=20.0;
    ShapeY[0]=100.0;
    ShapeX[1]=400.0;
    ShapeY[1]=600.0;
    ShapeX[2]=600.0;
    ShapeY[2]=800.0;

    // x and y for boxes
    x[0]=0.0;x[1]=0.0;x[2]=100.0;x[3]=100.0;x[4]=0.0;x[5]=0.0;x[6]=100.0;x[7]=100.0;
    y[0]=0.0;y[1]=100.0;y[2]=100.0;y[3]=0.0;y[4]=0.0;y[5]=100.0;y[6]=100.0;y[7]=0.0;
    z[0]=0.0;z[1]=0.0;z[2]=0.0;z[3]=0.0;z[4]=100.0;z[5]=100.0;z[6]=100.0;z[7]=100.0;

    qglClearColor(Qt::black);

}

void OGLSkel::resizeGL(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);
}

void OGLSkel::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    draw();
}

void OGLSkel::mousePressEvent(QMouseEvent *event)
{
    Go=true;
    
    //lastPos = event->pos();
}


void OGLSkel::mouseMoveEvent(QMouseEvent *event)
{

       updateGL();

   // lastPos = event->pos();
}

void OGLSkel::mouseDoubleClickEvent(QMouseEvent *event)
{

            // updateGL();
            Go=false;

}

void OGLSkel::draw()
{

               glClearColor (0.0f, 0.4f, 0.3f, 0.0f);
               glClear (GL_COLOR_BUFFER_BIT);

               glMatrixMode( GL_PROJECTION );
               glLoadIdentity();
               glOrtho(0.0,1000.0,0.0,1000.0,-500.0,500.0);
               //if(Go)
               //{


              for (int i=0;i<=2;i++)
              {
             glPushMatrix();
             glTranslatef(ShapeX[i]+xt[i],ShapeY[i]+yt[i],0.0);


               //glRotatef(incx,1.0,1.0,1.0);
               glBegin(GL_LINES);

                //1
            glVertex3f(x[0],y[0],z[0]);
            glVertex3f(x[1],y[1],z[1]);

                //2
                glVertex3f(x[1],y[1],z[1]);
                glVertex3f(x[2],y[2],z[2]);


                //3
                glVertex3f(x[2],y[2],z[2]);
                glVertex3f(x[3],y[3],z[3]);

                //4
                glVertex3f(x[3],y[3],z[3]);
                glVertex3f(x[0],y[0],z[0]);
                //5
                glVertex3f(x[0],y[0],z[0]);
                glVertex3f(x[4],y[4],z[4]);
                //6
                glVertex3f(x[1],y[1],z[1]);
                glVertex3f(x[5],y[5],z[5]);
                //7
                glVertex3f(x[2],y[2],z[2]);
                glVertex3f(x[6],y[6],z[6]);
                //8
                glVertex3f(x[3],y[3],z[3]);
                glVertex3f(x[7],y[7],z[7]);
                //9
                glVertex3f(x[4],y[4],z[4]);
                glVertex3f(x[5],y[5],z[5]);
                //10
                glVertex3f(x[5],y[5],z[5]);
                glVertex3f(x[6],y[6],z[6]);
                //11
                glVertex3f(x[6],y[6],z[6]);
                glVertex3f(x[7],y[7],z[7]);
                //12
                glVertex3f(x[4],y[4],z[4]);
                glVertex3f(x[7],y[7],z[7]);

// i would have used quads


            glEnd();
            glPopMatrix();
        }



     // glEnd();
 //glPopMatrix();
   }

void OGLSkel::timerEvent(QTimerEvent *)
        {
    int i=0;

    if(Go){

        //L = ((xs1-xs2)*(xs1-xs2)+ (ys1-ys2)*(ys1-ys2));
        
        //if (ShapeX[i]+xt[i]+50.0 )

       cerr << "ShapeX[0]+xt[0]+50.0= " << ShapeX[0]+xt[0]+50.0<< endl;
      cerr << "ShapeX[1]+xt[1]+50.0= " << ShapeX[1]+xt[1]+50.0<< endl;
      cerr << "ShapeX[2]+xt[2]=50.0  " << ShapeX[2]+xt[2]+50.0<< endl;
      cerr << "ShapeY[0]+yt[0]+50.0= " << ShapeY[0]+yt[0]+50.0<< endl;
      cerr << "ShapeY[1]+yt[1]+50.0= " << ShapeY[1]+yt[1]+50.0<< endl;
      cerr << "ShapeY[2]+yt[2]+50.0= " << ShapeY[2]+yt[2]+50.0<< endl;
        //std::cerr << "xt[0]= " << xt[0] << std::endl;


      XShape1 = ShapeX[0]+xt[0]+50.0;
      YShape1 = ShapeY[0]+yt[0]+50.0;

      XShape2 =ShapeX[1]+xt[1]+50.0;
      YShape2 = ShapeY[1]+yt[1]+50.0;

      XShape3 =ShapeX[2]+xt[2]+50.0;
      YShape3 = ShapeY[1]+yt[1]+50.0;



        ofstream File;

        File.open("XLocationSqr1.txt",ios::app);
        File << XShape1;
        File <<",";
        File.close();

        File.open("YLocationSqr1.txt",ios::app);
        File << YShape1;
        File <<",";
        File.close();

        File.open("XLocationSqr2.txt",ios::app);
        File << XShape2;
        File <<",";
        File.close();

        File.open("YLocationSqr2.txt",ios::app);
        File << YShape2;
        File <<",";
        File.close();

        File.open("XLocationSqr3.txt",ios::app);
        File << XShape3;
        File <<",";
        File.close();

        File.open("YLocationSqr3.txt",ios::app);
        File << YShape3;
        File <<",";
        File.close();

        if (Qt::
        
        
        
        
    }
            for( i=0;i<=2;i++)


            {
            if(ShapeX[i]+xt[i]+50.0>=B1x)
            {
             xd[i]=xd[i]*-1;

   //          std::cerr << "yt[0]= " << yt[0]<< std::endl;
    //         std::cerr << "xt[0]= " << xt[0] << std::endl;

            }
            if(ShapeX[i]+xt[i]+50.0<=B3x)
              {
               xd[i]=xd[i]*-1;
     //          std::cerr << "yt[0]= " << yt[0]<< std::endl;
        //       std::cerr << "xt[0]= " << xt[0] << std::endl;

              }

            if(ShapeY[i]+yt[i]+50.0>=B2y)
            {
             yd[i]=yd[i]*-1;
         //    std::cerr << "yt[0]= " << yt[0]<< std::endl;
        //     std::cerr << "xt[0]= " << xt[0] << std::endl;
            }
            if(ShapeY[i]+yt[i]+50.0<=B4y)
            {
               yd[i]=yd[i]*-1;
        //       std::cerr << "yt[0]= " << yt[0]<< std::endl;
        //       std::cerr << "xt[0]= " << xt[0] << std::endl;
             }

//DifCollisonX == ShapeX[0]+xt[0]+50.0 - ShapeY[0]+xt[0]+50.0;
//DifCollisonX2 == ShapeX[1]+xt[1]+50.0 - ShapeY[0]+xt[0]+50.0;
//DifCollisonX == ShapeX[1]+xt[1]+50.0 - ShapeX[0]+xt[0]+50.0;
//DifCollisonX2== ShapeX[0]+xt[1]=50.0 - ShapeX[0]+xt[0]+50.0;
//DifCollisonX == ShapeX[0]+xt[0]+50.0 - ShapeY[0]+yt[0]+50.0;
//DifCollisonX2 == ShapeX[1]+xt[1]+50.0 - ShapeY[0]+yt[0]+50.0;

//if (DifCollisonX == DifCollisonX2 )



// ---------------Problem Section -------------------------

           if (XShape1.IntersectsWith(XShape2)) -
   {
         xd[i]=xd[i]*-1;
   }
-------------------------------------------------------------
            //if (ShapeX[0] == ShapeX[1])

          //      if (ShapeX[0]+xt[0]+50.0 + ShapeY[0]+xt[0]+50.0 < MyVariable);

            //    DifCollisonX == ShapeX[1]+xt[1]+50.0 - ShapeX[0]+xt[0]+50.0;


             //    if(DifCollisonX > Bondary1)
         //        {
        //    std::cerr<<"A collison" <<std::endl;
        //         }



     // if points are same there is a collision however they are always the same - because they both move at same speed porportial to each other.
     // need to find way to make squares match.
     //may be i should cycle through an array - that stores differences to work out square collision.

         xt[i]=xt[i]+xd[i]*6.0;
         yt[i]=yt[i]+yd[i]*3.0;
     }
     }
              updateGL();
     }

Edited 6 Years Ago by __avd: Corrected [code] tags.

why has this thread being moved to c.

its c++ not c.
--------------------------------------------------------------------

This article has been dead for over six months. Start a new discussion instead.