Beispiel #1
0
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            GL.glLoadIdentity();

            if (Weaponchanged)
            {
                //if WeaponIndex changed create lists again!
                Robot.PrepareAndDraw();
                Robot.PrepareAndDrawShadow();
                Weaponchanged = false;
            }

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);

            #region Mouse Control
            GL.glTranslatef(-X, -Y, -Z);
            GL.glRotatef(rotX, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(rotY, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(rotZ, 0.0f, 0.0f, 1.0f);
            #endregion


            //move camera to initial position - center of cube and above floor
            GL.glTranslatef(0.0f, 0.0f, -1.0f);
            GL.glTranslatef(0.0f, 5.0f, 0.0f);
            GL.glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);


            //update light position
            LightPosition[0] = ScrollValue[10];
            LightPosition[1] = ScrollValue[11];
            LightPosition[2] = ScrollValue[12];
            LightPosition[3] = 1.0f;

            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            GL.glLoadIdentity(); // make it identity matrix

            MoveRobotByDirection();

            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);
            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix
            GL.glMultMatrixd(CurrentRotationTraslation);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            GL.glMultMatrixd(AccumulatedRotationsTraslations);


            //draw actual cube
            cube.Scale(xMaxOfCube, yMaxOfCube, zMaxOfCube);
            cube.Draw(1);

            GL.glRotatef(180, 0, 1, 0);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);

            GL.glPushMatrix();
            GL.glLoadIdentity();
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            GL.glMultMatrixd(AccumulatedRotationsTraslations);


            //!!!!!!!!!!! draw orginal Robot
            GL.glPushMatrix();
            RotateRobotByDirection();
            GL.glCullFace(GL.GL_BACK);
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glEnable(GL.GL_LIGHTING);
            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
            Robot.Draw(false);
            GL.glPopMatrix();


            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix

            RobotPlace[0]        = AccumulatedRotationsTraslations[12];
            RobotPlaceForward[0] = RobotPlaceBackward[0] = RobotPlaceRight[0] = RobotPlaceLeft[0] = AccumulatedRotationsTraslations[12];
            RobotPlace[1]        = AccumulatedRotationsTraslations[14];
            RobotPlaceForward[1] = RobotPlaceBackward[1] = RobotPlaceRight[1] = RobotPlaceLeft[1] = AccumulatedRotationsTraslations[14];

            switch (WhatWillDirection)
            {
            case arrow.forward:
                //Look future to get wallk forward
                RobotPlaceForward = WillPlace(2.1f, 0, 0);
                break;

            case arrow.backward:
                //Look future to get wallk backward
                RobotPlaceBackward = WillPlace(-2.1f, 0, 0);
                break;

            case arrow.right:
                //Look future to get wallk right
                RobotPlaceRight = WillPlace(0, 0, 2.1f);
                break;

            case arrow.left:
                //Look future to get wallk left
                RobotPlaceLeft = WillPlace(0, 0, -2.1f);
                break;
            }

            if (((RobotPlace[0] < ((car.Drive % 46) - 23) + 7) && (RobotPlace[0] > ((car.Drive % 46) - 23) - 4)) && //in car length
                RobotPlace[1] > 5 && RobotPlace[1] < 10 && !Robot.IsJumping)     //in car width & not jumping
            {
                Robot.IsCrashWithCar = true;
            }

            //!!!!!!!!!!!
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();
            GL.glRotatef(-180, 0, 1, 0);

            #region Reflaction to cube
            StartReflaction(-1, 1, -1);     //Reflaction to cube

            cube.Scale(xMaxOfCube - 0.002f, yMaxOfCube - 0.002f, zMaxOfCube - 0.002f);
            cube.Draw(-1);       //decrease 0.002 from each dimension of cube to avoid unexpected lines and -1 for mirrow efect
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();
            #endregion

            // really draw mirror
            //( half-transparent ( see its color's alpha byte)))
            // in order to see reflected objects
            //GL.glPushMatrix();
            //GL.glTranslatef(0, -4, 0);
            //GL.glDepthMask((byte)GL.GL_FALSE);
            //GL.glRotatef(90,0,1,0);
            //DrawMirror();
            //GL.glDepthMask((byte)GL.GL_TRUE);
            //GL.glPopMatrix();

            GL.glScalef(-1, 1, 1);//Some rotation for normal Cube direction
            GL.glRotatef(180, 0, 1, 0);

            #region Reflaction to Robot
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            StartReflaction(-1, 1, 1);  //Start Reflaction to Robot
            GL.glLoadIdentity();
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);
            GL.glLoadMatrixd(AccumulatedRotationsTraslations);
            GL.glMultMatrixd(CurrentRotationTraslation);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            GL.glMultMatrixd(AccumulatedRotationsTraslations);



            //draw reflected Robot
            GL.glPushMatrix();
            RotateRobotByDirection();
            GL.glCullFace(GL.GL_BACK);
            GL.glCullFace(GL.GL_FRONT);
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
            Robot.Draw(false);
            GL.glPopMatrix();
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();


            //draw all Robot shadows in the mirror!!
            MakeShadow(ModelVievMatrixBeforeSpecificTransforms, CurrentRotationTraslation);
            DrawLight();   //draw reflected light
            GL.glDisable(GL.GL_STENCIL_TEST);
            #endregion

            GL.glScalef(1, 1, -1);                                                          //Some rotation for normal Cube direction
            GL.glRotatef(180, 0, 1, 0);
            DrawLight();                                                                    //draw actual light
            MakeShadow(ModelVievMatrixBeforeSpecificTransforms, CurrentRotationTraslation); //draw all Robot shadows


            car.Drive += 0.5f;    //for animation of car moving

            //draw car reflection
            StartReflaction(-1, 1, 1);
            car.Draw(false);

            //draw car reflection shadow on floor
            StartReflaction(-1, 1, 1);
            GL.glDisable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            MakeShadowMatrix(floorCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw car reflection shadow on back wall
            StartReflaction(-1, 1, 1);
            GL.glDisable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            MakeShadowMatrix(backWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw car reflection shadow on front wall
            StartReflaction(-1, 1, 1);
            GL.glDisable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            MakeShadowMatrix(frontWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();
            GL.glDisable(GL.GL_STENCIL_TEST);

            //draw the Frame of mirror
            mirror.DrawFrame();

            //draw mirror again to cover car from being shown on the other side of mirror
            GL.glPushMatrix();
            GL.glTranslatef(0, -4, 0);
            GL.glRotatef(90, 0, 1, 0);
            mirror.Draw();
            GL.glPopMatrix();

            //draw car
            car.Draw(false);

            //draw shadow car on floor
            GL.glPushMatrix();
            MakeShadowMatrix(floorCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw shadow car on back wall
            GL.glPushMatrix();
            MakeShadowMatrix(backWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw shadow car on front wall
            GL.glPushMatrix();
            MakeShadowMatrix(frontWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();


            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Beispiel #2
0
        void DrawMirrors()
        {
            //only wall, draw only to STENCIL buffer
            GL.glEnable(GL.GL_BLEND);
            GL.glEnable(GL.GL_STENCIL_TEST);
            GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE); // change stencil according to the object color
            GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF);               // draw wall always
            GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
            GL.glDisable(GL.GL_DEPTH_TEST);
            // add mirrors for STENCIL buffer
            backMirrorSurface.Draw(backMinusArray);
            rightMirrorSurface.Draw(rightMinusArray);
            leftMirrorSurface.Draw(leftMinusArray);

            // restore regular settings
            GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
            GL.glEnable(GL.GL_DEPTH_TEST);


            // reflection is drawn only where STENCIL buffer value equal to 1
            GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
            GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); // keep object origenal color

            GL.glEnable(GL.GL_STENCIL_TEST);

            // draw reflected scene for back mirror
            GL.glPushMatrix();
            GL.glScalef(1, 1, -1); //swap on Z axis
            GL.glTranslated(0, 0, mirrorWidth);
            rubiksCube.Draw();
            GL.glPopMatrix();

            // draw reflected left mirror scene for right mirror scene
            GL.glPushMatrix();
            //GL.glScalef(-1, 1, 1); //swap on Z axis
            GL.glTranslated(mirrorWidth * 2, 0, 0);
            rubiksCube.Draw();
            GL.glPopMatrix();

            // draw reflected scene for right mirror
            GL.glPushMatrix();
            GL.glScalef(-1, 1, 1); //swap on X axis
            GL.glTranslated(-mirrorWidth, 0, 0);
            leftMirrorSurface.Draw(leftMinusArray);
            rubiksCube.Draw();
            GL.glPopMatrix();

            // draw reflected right mirror scene for left mirror scene
            GL.glPushMatrix();
            //GL.glScalef(-1, 1, 1); //swap on Z axis
            GL.glTranslated(-mirrorWidth * 2, 0, 0);
            rubiksCube.Draw();
            GL.glPopMatrix();

            // draw reflected scene for left mirror
            GL.glPushMatrix();
            GL.glScalef(-1, 1, 1); //swap on X axis
            GL.glTranslated(mirrorWidth, 0, 0);
            rightMirrorSurface.Draw(rightMinusArray);
            rubiksCube.Draw();
            GL.glPopMatrix();

            // really draw wall
            //( half-transparent ( see its color's alpha byte)))
            // in order to see reflected objects
            GL.glDepthMask((byte)GL.GL_FALSE);

            backMirrorSurface.Draw(backMinusArray);

            Console.WriteLine((((-1.0 / 15) * (-90 - rightMirrorSurface.AngleY))));
            Console.WriteLine(rightMirrorSurface.AngleY);

            if (ScrollValue[1] < (3 + 5 * ((-1.0 / 15) * (-90 - rightMirrorSurface.AngleY))) && ScrollValue[1] > -(3 + 5 * ((-1.0 / 15) * (-90 - rightMirrorSurface.AngleY))))  // TODO: need to consider with --> cGL.rightMirrorSurface.AngleY >= -90
            {
                rightMirrorSurface.Draw(rightMinusArray);
                leftMirrorSurface.Draw(leftMinusArray);
            }
            else if (ScrollValue[1] < (3 + 5 * ((-1.0 / 15) * (-90 - rightMirrorSurface.AngleY))))
            {
                leftMirrorSurface.DrawAsWall(leftWallColorArray, leftMinusArray);
                rightMirrorSurface.Draw(rightMinusArray);
            }
            else
            {
                rightMirrorSurface.DrawAsWall(rightWallColorArray, rightMinusArray);
                leftMirrorSurface.Draw(leftMinusArray);
            }

            GL.glDepthMask((byte)GL.GL_TRUE);
            // Disable GL.GL_STENCIL_TEST to show All, else it will be cut on GL.GL_STENCIL
            GL.glDisable(GL.GL_STENCIL_TEST);

            // GL.glEnable(GL.GL_DEPTH_TEST);
            //GL.glDisable(GL.GL_DEPTH_TEST);
            //GL.glClear(GL.GL_DEPTH_BUFFER_BIT);
            //GL.glDepthFunc(GL.GL_LESS);
            //GL.glDepthFunc(GL.GL_GREATER);

            //   GL.glDisable(GL.GL_BLEND);
        }