void wireBox(GLfloat length, GLfloat side){
	glBegin(GL_LINES);

	glVertex3f(0.0f, side/2.0, side/2.0);
	glVertex3f(0.0f, side/2.0, -side/2.0);
	glVertex3f(0.0f, side/2.0, -side/2.0);
	glVertex3f(0.0f, -side/2.0, -side/2.0);
	glVertex3f(0.0f, -side/2.0, -side/2.0);
	glVertex3f(0.0f, -side/2.0, side/2.0);
	glVertex3f(0.0f, -side/2.0, side/2.0);
	glVertex3f(0.0f, side/2.0, side/2.0);
	glVertex3f(length, -side/2.0, side/2.0);
	glVertex3f(length, -side/2.0, -side/2.0);
	glVertex3f(length, -side/2.0, -side/2.0);
	glVertex3f(length, side/2.0, -side/2.0);
	glVertex3f(length, side/2.0, -side/2.0);
	glVertex3f(length, side/2.0, side/2.0);
	glVertex3f(length, side/2.0, side/2.0);
	glVertex3f(length, -side/2.0, side/2.0);
	glVertex3f(0.0f, side/2.0, side/2.0);
	glVertex3f(length, side/2.0, side/2.0);
	glVertex3f(0.0f, side/2.0, -side/2.0);
	glVertex3f(length, side/2.0, -side/2.0);
	glVertex3f(0.0f, -side/2.0, -side/2.0);
	glVertex3f(length, -side/2.0, -side/2.0);
	glVertex3f(0.0f, -side/2.0, side/2.0);
	glVertex3f(length, -side/2.0, side/2.0);

	glEnd();
}
Exemple #2
0
void draw()
{
    // Clear Screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Place Camera
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(eyeX, eyeY, eyeZ,   0, 0, 0,   upX, upY, upZ);

    // Set Perspective
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, 1.33, 1.6, 10);
    glMatrixMode(GL_MODELVIEW);

    // Draw Faces Far and Near
    glBegin(GL_QUADS);
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(0.8, 0.8, -0.8);
    glVertex3f(0.8, -0.8, -0.8);
    glVertex3f(-0.8, -0.8, -0.8);
    glVertex3f(-0.8, 0.8, -0.8);

    glColor3f(0.0, 1.0, 0.0);
    glVertex3f(0.8, 0.8, 0.8);
    glVertex3f(0.8, -0.8, 0.8);
    glVertex3f(-0.8, -0.8, 0.8);
    glVertex3f(-0.8, 0.8, 0.8);
    glEnd();

    // Draw Faces Right and Left
    glBegin(GL_QUADS);
    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(0.8, -0.8, -0.8);
    glVertex3f(0.8, 0.8, -0.8);
    glVertex3f(0.8, 0.8, 0.8);
    glVertex3f(0.8, -0.8, 0.8);

    glColor3f(1.0, 1.0, 0.0);
    glVertex3f(-0.8, -0.8, -0.8);
    glVertex3f(-0.8, 0.8, -0.8);
    glVertex3f(-0.8, 0.8, 0.8);
    glVertex3f(-0.8, -0.8, 0.8);
    glEnd();

    // Draw Faces Top and Bottom
    glBegin(GL_QUADS);
    glColor3f(0.0, 1.0, 1.0);
    glVertex3f(-0.8, 0.8, -0.8);
    glVertex3f(-0.8, 0.8, 0.8);
    glVertex3f(0.8, 0.8, 0.8);
    glVertex3f(0.8, 0.8, -0.8);

    glColor3f(1.0, 0.0, 1.0);
    glVertex3f(-0.8, -0.8, -0.8);
    glVertex3f(-0.8, -0.8, 0.8);
    glVertex3f(0.8, -0.8, 0.8);
    glVertex3f(0.8, -0.8, -0.8);
    glEnd();

    glfwSwapBuffers();
}
Exemple #3
0
void VR_ShowCrosshair ()
{
	vec3_t forward, up, right;
	vec3_t start, end, impact;
	float size;
	if( (sv_player && (int)(sv_player->v.weapon) == IT_AXE) )
		return;

	// setup gl
	glDisable (GL_DEPTH_TEST);
	glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
	GL_PolygonOffset (OFFSET_SHOWTRIS);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable (GL_TEXTURE_2D);
	glDisable (GL_CULL_FACE);

	// calc the line and draw
	VectorCopy (cl.viewent.origin, start);
	start[2] -= cl.viewheight - 10;
	AngleVectors (cl.aimangles, forward, right, up);

	size = CLAMP (1.0, vr_crosshair_size.value, 5.0);

	switch((int) vr_crosshair.value)
	{	
		default:
		case VR_CROSSHAIR_POINT:
			if (vr_crosshair_depth.value <= 0) {
				 // trace to first wall
				VectorMA (start, 4096, forward, end);
				TraceLine (start, end, impact);
			} else {
				// fix crosshair to specific depth
				VectorMA (start, vr_crosshair_depth.value * meters_to_units, forward, impact);
			}

			glEnable(GL_POINT_SMOOTH);
			glColor4f (1, 0, 0, 0.5);
			glPointSize( size * glwidth / 1280.0f );

			glBegin(GL_POINTS);
			glVertex3f (impact[0], impact[1], impact[2]);
			glEnd();
			glDisable(GL_POINT_SMOOTH);
			break;

		case VR_CROSSHAIR_LINE:
			// trace to first entity
			VectorMA (start, 4096, forward, end);
			TraceLineToEntity (start, end, impact, sv_player);

			glColor4f (1, 0, 0, 0.4);
			glLineWidth( size * glwidth / (1280.0f) );
			glBegin (GL_LINES);
			glVertex3f (start[0], start[1], start[2]);
			glVertex3f (impact[0], impact[1], impact[2]);
			glEnd ();
			break;
	}

	// cleanup gl
	glColor3f (1,1,1);
	glEnable (GL_TEXTURE_2D);
	glEnable (GL_CULL_FACE);
	glDisable(GL_BLEND);
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
	GL_PolygonOffset (OFFSET_NONE);
	glEnable (GL_DEPTH_TEST);
}
Exemple #4
0
void GLCanvas::renderSkeleton()
{
    Vector3 lookAt = _cameraPosition + _cameraFront;
    gluLookAt(_cameraPosition.x(), _cameraPosition.y(), _cameraPosition.z(),
              lookAt.x()         , lookAt.y()         , lookAt.z(),
              _cameraUp.x()      , _cameraUp.y()      , _cameraUp.z());

    if (_style & DRAW_GRID)
    {
        drawGrid();
    }
    if (_skeleton == nullptr)
    {
        return;
    }

    for (auto it = _skeleton->beginBones(); it != _skeleton->endBones(); ++it)
    {
        glPushMatrix();
        Bone bone = *(it->second);

        int boneId = bone.getId();

        // don't draw any bone without valid id
        if (boneId < 0)
        {
            continue;
        }

        // get the bone id as color for SELECTION_MODE
        GLubyte boneIdColor[4] = {GLubyte((boneId >> 8) & 255), GLubyte((boneId >> 8) & 255), GLubyte(boneId & 255), 255};

        const GLubyte* boneColor1 = boneStandardColor1;
        const GLubyte* boneColor2 = boneStandardColor2;

        if (_style & SELECTION_MODE)
        {
            boneColor1 = boneIdColor;
            boneColor2 = boneIdColor;
        }
        else if (_style & HIGHLIGHT_SELECTED_BONE && bone.getId() == _skeleton->getSelectedBoneId())
        {
            boneColor1 = boneHighlightedColor1;
            boneColor2 = boneHighlightedColor2;
        }

        Vector3 startPos = bone.getStartPos();

        glTranslatef(startPos.x(), startPos.y(), startPos.z());

        float length = bone.getLength();

        Vector3 dir = bone.getDirection();
        Vector3 up = bone.getUpDirection();
        Vector3 right = bone.getRightDirection();

        Vector3 endPos = dir*length;

        startPos = Vector3(0, 0, 0);

        float length_10 = length * 0.1f;
        Vector3 endPos_10 = endPos * 0.1f;

        Vector3 upPoint = up*length_10 + endPos_10;
        Vector3 downPoint = - up*length_10 + endPos_10;
        Vector3 rightPoint = right*length_10 + endPos_10;
        Vector3 leftPoint = - right*length_10 + endPos_10;

        if (!(_style & SELECTION_MODE))
        {
            //set point size to 10 pixels
            glPointSize(10.0f);
            glColor4ubv(pointColor);

            // TODO(JK#9#): maybe don't draw points for bones (or add render style flag)
            glBegin(GL_POINTS);
                glVertex3f(endPos.x(), endPos.y(), endPos.z());
            glEnd();
        }

        // set line width
        glLineWidth(_lineWidth);

        // draw local coordinate system
        if (_style & DRAW_LOCAL_COORDINATE_SYSTEM)
        {
            glBegin(GL_LINES);
                glColor4ubv(red);

                glVertex3f(endPos.x(), endPos.y(), endPos.z());
                glVertex3f(endPos.x() + dir.x()*0.1f, endPos.y() + dir.y()*0.1f, endPos.z() + dir.z()*0.1f);

                glColor4ubv(green);

                glVertex3f(endPos.x(), endPos.y(), endPos.z());
                glVertex3f(endPos.x() + up.x()*0.1f, endPos.y() + up.y()*0.1f, endPos.z() + up.z()*0.1f);

                glColor4ubv(blue);

                glVertex3f(endPos.x(), endPos.y(), endPos.z());
                glVertex3f(endPos.x() + right.x()*0.1f, endPos.y() + right.y()*0.1f, endPos.z() + right.z()*0.1f);
            glEnd();
        }

        if (_style & DRAW_ROTATION_AXIS)
        {
            Vector3 rotAxis = bone.getRelOrientation().getRotationAxis();

            glBegin(GL_LINES);
                glColor4ubv(yellow);

                glVertex3f(-rotAxis.x()*0.2f, -rotAxis.y()*0.2f, -rotAxis.z()*0.2f);
                glVertex3f(rotAxis.x()*0.2f, rotAxis.y()*0.2f, rotAxis.z()*0.2f);
            glEnd();
        }

        // draw bone
        glPolygonMode(GL_FRONT, GL_FILL);

        glColor4ubv(boneColor1);

        glBegin(GL_TRIANGLE_FAN);
            glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
            glVertex3f(leftPoint.x(), leftPoint.y(), leftPoint.z());
            glVertex3f(downPoint.x(), downPoint.y(), downPoint.z());
            glVertex3f(rightPoint.x(), rightPoint.y(), rightPoint.z());
            glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
        glEnd();


        glColor4ubv(boneColor2);

        glBegin(GL_TRIANGLE_FAN);
            glVertex3f(endPos.x(), endPos.y(), endPos.z());
            glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
            glVertex3f(rightPoint.x(), rightPoint.y(), rightPoint.z());
            glVertex3f(downPoint.x(), downPoint.y(), downPoint.z());
            glVertex3f(leftPoint.x(), leftPoint.y(), leftPoint.z());
            glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
        glEnd();

        if (!(_style & SELECTION_MODE))
        {
            // draw black mesh lines around bones
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            glColor4ubv(black);

            glBegin(GL_TRIANGLE_FAN);
                glVertex3f(0.0f, 0.0f, 0.0f);
                glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
                glVertex3f(leftPoint.x(), leftPoint.y(), leftPoint.z());
                glVertex3f(downPoint.x(), downPoint.y(), downPoint.z());
                glVertex3f(rightPoint.x(), rightPoint.y(), rightPoint.z());
                glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
            glEnd();

            glBegin(GL_TRIANGLE_FAN);
                glVertex3f(endPos.x(), endPos.y(), endPos.z());
                glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
                glVertex3f(rightPoint.x(), rightPoint.y(), rightPoint.z());
                glVertex3f(downPoint.x(), downPoint.y(), downPoint.z());
                glVertex3f(leftPoint.x(), leftPoint.y(), leftPoint.z());
                glVertex3f(upPoint.x(), upPoint.y(), upPoint.z());
            glEnd();

            // draw labels
            if (_style & DRAW_LABEL)
            {
                // glDisable(GL_DEPTH_TEST);
                GLImage* image = _labels.find(boneId)->second;
                image->setPosition(0.5f * bone.getLength() * dir - 0.06f * bone.getLength() * _cameraFront);
                image->render();
                // glEnable(GL_DEPTH_TEST);
            }
        }

        // reset line width
        glLineWidth(1.0f);

        if (_style & DRAW_SPIN_ARROWS && bone.getId() == _skeleton->getSelectedBoneId())
        {
            drawSpinArrows(endPos - 0.2 * bone.getLength() * dir, dir, up, right);
        }
        glPopMatrix();

        // append trace point and draw trace
        if (_traceLength > 0)
        {
            Vector3 globalEndPos = bone.getEndPos();
            std::map<int, std::vector<Vector3> >::iterator traceIt = _boneIdsWithTracePoints.find(boneId);
            if (traceIt != _boneIdsWithTracePoints.end())
            {
                if (traceIt->second.size() < _traceLength)
                {
                    traceIt->second.push_back(globalEndPos);
                }
                else
                {
                    traceIt->second[_tracePos] = globalEndPos;
                }

                glBegin(GL_LINES);
                    glColor4ubv(yellow);

                    for (size_t i = 0; i < traceIt->second.size() - 1; ++i)
                    {
                        if (i != _tracePos)
                        {
                            glVertex3f(traceIt->second[i].x(), traceIt->second[i].y(), traceIt->second[i].z());
                            glVertex3f(traceIt->second[i+1].x(), traceIt->second[i+1].y(), traceIt->second[i+1].z());
                        }
                    }
                    // draw gab between end and beginning of the vector data
                    if (traceIt->second.size() > 1 && _tracePos != traceIt->second.size() - 1)
                    {
                        glVertex3f(traceIt->second.back().x(), traceIt->second.back().y(), traceIt->second.back().z());
                        glVertex3f(traceIt->second[0].x(), traceIt->second[0].y(), traceIt->second[0].z());
                    }

                glEnd();
            }
        }
    }

    // draw joints (after everything else, as they are transparent and need everything else be rendered)
    if (_style & DRAW_JOINT_CONSTRAINTS)
    {
        for (auto it = _skeleton->beginBones(); it != _skeleton->endBones(); ++it)
        {
            glPushMatrix();
            Bone bone = *(it->second);

            Vector3 startPos = bone.getStartPos();
            glTranslatef(startPos.x(), startPos.y(), startPos.z());

            JointConstraint constraint = bone.getJointConstraint();

            drawJoint(constraint);

            glPopMatrix();
        }
    }

    // update trace position
    if (++_tracePos >= _traceLength)
    {
        _tracePos = 0;
    }

    if (!(_style & SELECTION_MODE) && _style & DRAW_AABB)
    {
        drawAABB(_skeleton->getAABB());
    }
}

void GLCanvas::drawSpinArrows(Vector3 pos, Vector3 dir, Vector3 up, Vector3 right) const
{
    float length = 0.03f;
    float offset = 0.05f;

    GLubyte red[4] = {255, 0, 0, 255};
    GLubyte green[4] = {0, 255, 0, 255};
    GLubyte blue[4] = {0, 0, 255, 255};
    GLubyte black[4] = {0, 0, 0, 255};

    // set arroe ids to next available free ids
    int idArrowDir = _skeleton->getNextFreeId();
    int idArrowUp = _skeleton->getNextFreeId() + 1;
    int idArrowRight = _skeleton->getNextFreeId() + 2;

    GLubyte idArrowDirColor[4] = {GLubyte((idArrowDir >> 8) & 255), GLubyte((idArrowDir >> 8) & 255), GLubyte(idArrowDir & 255), 255};
    GLubyte idArrowUpColor[4] = {GLubyte((idArrowUp >> 8) & 255), GLubyte((idArrowUp >> 8) & 255), GLubyte(idArrowUp & 255), 255};
    GLubyte idArrowRightColor[4] = {GLubyte((idArrowRight >> 8) & 255), GLubyte((idArrowRight >> 8) & 255), GLubyte(idArrowRight & 255), 255};

    const GLubyte* arrowDirColor = red;
    const GLubyte* arrowUpColor = green;
    const GLubyte* arrowRightColor = blue;

    // base points of the arrow pyramids
    Vector3 basePointUp = pos + up * offset;
    Vector3 basePointRight = pos + right * offset;
    Vector3 basePointDown = pos - up * offset;
    Vector3 basePointLeft = pos - right * offset;

    dir *= length;
    up *= length;
    right *= length;

    Vector3 dirHalf = dir * 0.5;
    Vector3 rightHalf = right * 0.5;

    // base vertices of the circle like arrow
    Vector3 upperCircle[4];
    upperCircle[0] = basePointDown;
    upperCircle[1] = basePointDown - right;
    upperCircle[2] = basePointLeft - up;
    upperCircle[3] = basePointLeft;

    Vector3 lowerCircle[4];
    lowerCircle[0] = basePointDown - up;
    lowerCircle[1] = basePointDown - right*1.4 - up;
    lowerCircle[2] = basePointLeft - right - up*1.4;
    lowerCircle[3] = basePointLeft - right;

    // the arrow rendering is done twice, one iteration for filling color, one for having black corner lines
    int numIterations = 2;
    if (_style & SELECTION_MODE)
    {
        // do not draw the corner lines in selection mode
        numIterations = 1;
        // draw the arrows with their id color
        arrowDirColor = idArrowDirColor;
        arrowUpColor = idArrowUpColor;
        arrowRightColor = idArrowRightColor;
    }
    // draw vertices twice, one run with filling and one with black lines
    for (int j = 0; j < numIterations; ++j)
    {
        if (j == 0)
        {
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        }
        else
        {
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            glColor4f(0.0, 0.0, 0.0, 1.0);
            arrowDirColor = arrowUpColor = arrowRightColor = black;
        }

        if (j == 0)
        {
            glColor4ubv(arrowUpColor);
        }
        glColor4ubv(arrowUpColor);

        // arrow pointing upwards
        glBegin(GL_TRIANGLE_FAN);
            glVertex3f(basePointUp.x() + up.x()*2.0, basePointUp.y() + up.y()*2.0, basePointUp.z() + up.z()*2.0);
            glVertex3f(basePointUp.x() + dir.x(), basePointUp.y() + dir.y(), basePointUp.z() + dir.z());
            glVertex3f(basePointUp.x() + right.x(), basePointUp.y() + right.y(), basePointUp.z() + right.z());
            glVertex3f(basePointUp.x() - dir.x(), basePointUp.y() - dir.y(), basePointUp.z() - dir.z());
            glVertex3f(basePointUp.x() - right.x(), basePointUp.y() - right.y(), basePointUp.z() - right.z());
            glVertex3f(basePointUp.x() + dir.x(), basePointUp.y() + dir.y(), basePointUp.z() + dir.z());
        glEnd();

        // arrow pointing downwards
    /*    glBegin(GL_TRIANGLE_FAN);
            glVertex3f(basePointDown.x() - up.x(), basePointDown.y() - up.y(), basePointDown.z() - up.z());
            glVertex3f(basePointDown.x() + dir.x(), basePointDown.y() + dir.y(), basePointDown.z() + dir.z());
            glVertex3f(basePointDown.x() + right.x(), basePointDown.y() + right.y(), basePointDown.z() + right.z());
            glVertex3f(basePointDown.x() - dir.x(), basePointDown.y() - dir.y(), basePointDown.z() - dir.z());
            glVertex3f(basePointDown.x() - right.x(), basePointDown.y() - right.y(), basePointDown.z() - right.z());
            glVertex3f(basePointDown.x() + dir.x(), basePointDown.y() + dir.y(), basePointDown.z() + dir.z());
        glEnd();
    */
        if (j == 0)
        {
            glColor4f(0.0, 0.0, 1.0, 1.0);
        }
        glColor4ubv(arrowRightColor);

        // arrow pointing to the right
        glBegin(GL_TRIANGLE_FAN);
            glVertex3f(basePointRight.x() + right.x()*2.0, basePointRight.y() + right.y()*2.0, basePointRight.z() + right.z()*2.0);
            glVertex3f(basePointRight.x() + dir.x(), basePointRight.y() + dir.y(), basePointRight.z() + dir.z());
            glVertex3f(basePointRight.x() - up.x(), basePointRight.y() - up.y(), basePointRight.z() - up.z());
            glVertex3f(basePointRight.x() - dir.x(), basePointRight.y() - dir.y(), basePointRight.z() - dir.z());
            glVertex3f(basePointRight.x() + up.x(), basePointRight.y() + up.y(), basePointRight.z() + up.z());
            glVertex3f(basePointRight.x() + dir.x(), basePointRight.y() + dir.y(), basePointRight.z() + dir.z());
        glEnd();

        // arrow pointing to the left
        /*    glBegin(GL_TRIANGLE_FAN);
                glVertex3f(basePointLeft.x() - right.x(), basePointLeft.y() - right.y(), basePointLeft.z() - right.z());
                glVertex3f(basePointLeft.x() + dir.x(), basePointLeft.y() + dir.y(), basePointLeft.z() + dir.z());
                glVertex3f(basePointLeft.x() - up.x(), basePointLeft.y() - up.y(), basePointLeft.z() - up.z());
                glVertex3f(basePointLeft.x() - dir.x(), basePointLeft.y() - dir.y(), basePointLeft.z() - dir.z());
                glVertex3f(basePointLeft.x() + up.x(), basePointLeft.y() + up.y(), basePointLeft.z() + up.z());
                glVertex3f(basePointLeft.x() + dir.x(), basePointLeft.y() + dir.y(), basePointLeft.z() + dir.z());
            glEnd();
        */

        if (j == 0)
        {
            glColor4f(1.0, 0.0, 0.0, 1.0);
        }
        glColor4ubv(arrowDirColor);

        glBegin(GL_TRIANGLE_FAN);
            // top of arrow
            glVertex3f(basePointLeft.x() - rightHalf.x() + up.x()*2.0, basePointLeft.y() - rightHalf.y() + up.y()*2.0, basePointLeft.z() - rightHalf.z() + up.z()*2.0);
            glVertex3f(basePointLeft.x() + rightHalf.x(), basePointLeft.y() + rightHalf.y(), basePointLeft.z() + rightHalf.z());
            glVertex3f(basePointLeft.x() - rightHalf.x() + dir.x(), basePointLeft.y() - rightHalf.y() + dir.y(), basePointLeft.z() - rightHalf.z() + dir.z());
            glVertex3f(basePointLeft.x() - right.x() - rightHalf.x(), basePointLeft.y() - right.y() - rightHalf.y(), basePointLeft.z() - right.z() - rightHalf.z());
            glVertex3f(basePointLeft.x() - rightHalf.x() - dir.x(), basePointLeft.y() - rightHalf.y() - dir.y(), basePointLeft.z() - rightHalf.z() - dir.z());
            glVertex3f(basePointLeft.x() + rightHalf.x(), basePointLeft.y() + rightHalf.y(), basePointLeft.z() + rightHalf.z());
        glEnd();

        // draw arrows base
        glBegin(GL_QUAD_STRIP);
            for (int i = 0; i < 4; ++i)
            {
                glVertex3f(upperCircle[i].x() + dirHalf.x(), upperCircle[i].y() + dirHalf.y(), upperCircle[i].z() + dirHalf.z());
                glVertex3f(upperCircle[i].x() - dirHalf.x(), upperCircle[i].y() - dirHalf.y(), upperCircle[i].z() - dirHalf.z());
            }

            for (int i = 3; i >= 0; --i)
            {
                glVertex3f(lowerCircle[i].x() + dirHalf.x(), lowerCircle[i].y() + dirHalf.y(), lowerCircle[i].z() + dirHalf.z());
                glVertex3f(lowerCircle[i].x() - dirHalf.x(), lowerCircle[i].y() - dirHalf.y(), lowerCircle[i].z() - dirHalf.z());
            }

            glVertex3f(upperCircle[0].x() + dirHalf.x(), upperCircle[0].y() + dirHalf.y(), upperCircle[0].z() + dirHalf.z());
            glVertex3f(upperCircle[0].x() - dirHalf.x(), upperCircle[0].y() - dirHalf.y(), upperCircle[0].z() - dirHalf.z());
        glEnd();

        glBegin(GL_QUAD_STRIP);
            for (int i = 0; i < 4; ++i)
            {
                glVertex3f(lowerCircle[i].x() + dirHalf.x(), lowerCircle[i].y() + dirHalf.y(), lowerCircle[i].z() + dirHalf.z());
                glVertex3f(upperCircle[i].x() + dirHalf.x(), upperCircle[i].y() + dirHalf.y(), upperCircle[i].z() + dirHalf.z());
            }

            for (int i = 3; i >= 0; --i)
            {
                glVertex3f(lowerCircle[i].x() - dirHalf.x(), lowerCircle[i].y() - dirHalf.y(), lowerCircle[i].z() - dirHalf.z());
                glVertex3f(upperCircle[i].x() - dirHalf.x(), upperCircle[i].y() - dirHalf.y(), upperCircle[i].z() - dirHalf.z());
            }
        glEnd();
    }
/*    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    glColor4f(0.0, 0.0, 0.0, 1.0);
    // arrow pointing upwards
    glBegin(GL_TRIANGLE_FAN);
        glVertex3f(basePointUp.x() + up.x()*2.0, basePointUp.y() + up.y()*2.0, basePointUp.z() + up.z()*2.0);
        glVertex3f(basePointUp.x() + dir.x(), basePointUp.y() + dir.y(), basePointUp.z() + dir.z());
        glVertex3f(basePointUp.x() + right.x(), basePointUp.y() + right.y(), basePointUp.z() + right.z());
        glVertex3f(basePointUp.x() - dir.x(), basePointUp.y() - dir.y(), basePointUp.z() - dir.z());
        glVertex3f(basePointUp.x() - right.x(), basePointUp.y() - right.y(), basePointUp.z() - right.z());
        glVertex3f(basePointUp.x() + dir.x(), basePointUp.y() + dir.y(), basePointUp.z() + dir.z());
    glEnd();

    // arrow pointing to the right
    glBegin(GL_TRIANGLE_FAN);
        glVertex3f(basePointRight.x() + right.x()*2.0, basePointRight.y() + right.y()*2.0, basePointRight.z() + right.z()*2.0);
        glVertex3f(basePointRight.x() + dir.x(), basePointRight.y() + dir.y(), basePointRight.z() + dir.z());
        glVertex3f(basePointRight.x() - up.x(), basePointRight.y() - up.y(), basePointRight.z() - up.z());
        glVertex3f(basePointRight.x() - dir.x(), basePointRight.y() - dir.y(), basePointRight.z() - dir.z());
        glVertex3f(basePointRight.x() + up.x(), basePointRight.y() + up.y(), basePointRight.z() + up.z());
        glVertex3f(basePointRight.x() + dir.x(), basePointRight.y() + dir.y(), basePointRight.z() + dir.z());
    glEnd();*/
}

void GLCanvas::renderSingleSensor() const
{
//    Vector3 lookAt = Vector3(0.0f, 0.0f, 0.0f);
    // Vector3 lookAt = _cameraPosition + _cameraFront;
//    gluLookAt(_cameraPosition.x(), _cameraPosition.y(), _cameraPosition.z(),
//              lookAt.x()         , lookAt.y()         , lookAt.z(),
//              _cameraUp.x()      , _cameraUp.y()      , _cameraUp.z());

    gluLookAt(0.0f, 0.0f, _cameraPosition.z(),
              0.0f, 0.0f, 0.0f,
              0.0f, 1.0f, 0.0f);

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    Vector3 dir = _sensorOrientation.rotate(Vector3(1.0f, 0.0f, 0.0f));
    Vector3 up = 0.25 * _sensorOrientation.rotate(Vector3(0.0f, 1.0f, 0.0f));
    Vector3 right = 0.5 * _sensorOrientation.rotate(Vector3(0.0f, 0.0f, 1.0f));

    Vector3 frontUpRight = dir + up + right;
    Vector3 frontDownRight = dir - up + right;
    Vector3 frontUpLeft = dir + up - right;
    Vector3 frontDownLeft = dir - up - right;
    Vector3 backUpRight = -dir + up + right;
    Vector3 backDownRight = -dir - up + right;
    Vector3 backUpLeft = -dir + up - right;
    Vector3 backDownLeft = -dir - up - right;


    glBegin(GL_QUADS);
        glColor3f(0.8, 0.5, 0.5);
        glVertex3f(frontUpLeft.x(), frontUpLeft.y(), frontUpLeft.z());
        glVertex3f(frontUpRight.x(), frontUpRight.y(), frontUpRight.z());
        glVertex3f(frontDownRight.x(), frontDownRight.y(), frontDownRight.z());
        glVertex3f(frontDownLeft.x(), frontDownLeft.y(), frontDownLeft.z());

        glColor3f(0.5, 0.7, 0.5);
        glVertex3f(backUpRight.x(), backUpRight.y(), backUpRight.z());
        glVertex3f(frontUpRight.x(), frontUpRight.y(), frontUpRight.z());
        glVertex3f(frontUpLeft.x(), frontUpLeft.y(), frontUpLeft.z());
        glVertex3f(backUpLeft.x(), backUpLeft.y(), backUpLeft.z());

        glColor3f(0.5, 0.5, 0.7);
        glVertex3f(backDownRight.x(), backDownRight.y(), backDownRight.z());
        glVertex3f(frontDownRight.x(), frontDownRight.y(), frontDownRight.z());
        glVertex3f(frontUpRight.x(), frontUpRight.y(), frontUpRight.z());
        glVertex3f(backUpRight.x(), backUpRight.y(), backUpRight.z());

        glColor3f(0.7, 0.7, 0.7);
        glVertex3f(backUpRight.x(), backUpRight.y(), backUpRight.z());
        glVertex3f(backUpLeft.x(), backUpLeft.y(), backUpLeft.z());
        glVertex3f(backDownLeft.x(), backDownLeft.y(), backDownLeft.z());
        glVertex3f(backDownRight.x(), backDownRight.y(), backDownRight.z());

        glVertex3f(backDownLeft.x(), backDownLeft.y(), backDownLeft.z());
        glVertex3f(frontDownLeft.x(), frontDownLeft.y(), frontDownLeft.z());
        glVertex3f(frontDownRight.x(), frontDownRight.y(), frontDownRight.z());
        glVertex3f(backDownRight.x(), backDownRight.y(), backDownRight.z());

        glVertex3f(backUpLeft.x(), backUpLeft.y(), backUpLeft.z());
        glVertex3f(frontUpLeft.x(), frontUpLeft.y(), frontUpLeft.z());
        glVertex3f(frontDownLeft.x(), frontDownLeft.y(), frontDownLeft.z());
        glVertex3f(backDownLeft.x(), backDownLeft.y(), backDownLeft.z());
    glEnd();

    // scale slightly to ensure the lines are visible
    glScalef(1.001f, 1.001f, 1.001f);

    glLineWidth(1.0f);
    glColor3f(0.0, 0.0, 0.0);
    glBegin(GL_LINE_STRIP);
        glVertex3f(backUpRight.x(), backUpRight.y(), backUpRight.z());
        glVertex3f(backUpLeft.x(), backUpLeft.y(), backUpLeft.z());
        glVertex3f(backDownLeft.x(), backDownLeft.y(), backDownLeft.z());
        glVertex3f(backDownRight.x(), backDownRight.y(), backDownRight.z());
        glVertex3f(backUpRight.x(), backUpRight.y(), backUpRight.z());

        glVertex3f(frontUpRight.x(), frontUpRight.y(), frontUpRight.z());
        glVertex3f(frontUpLeft.x(), frontUpLeft.y(), frontUpLeft.z());
        glVertex3f(frontDownLeft.x(), frontDownLeft.y(), frontDownLeft.z());
        glVertex3f(frontDownRight.x(), frontDownRight.y(), frontDownRight.z());
        glVertex3f(frontUpRight.x(), frontUpRight.y(), frontUpRight.z());
    glEnd();

    glBegin(GL_LINES);
        glVertex3f(backUpLeft.x(), backUpLeft.y(), backUpLeft.z());
        glVertex3f(frontUpLeft.x(), frontUpLeft.y(), frontUpLeft.z());

        glVertex3f(backDownLeft.x(), backDownLeft.y(), backDownLeft.z());
        glVertex3f(frontDownLeft.x(), frontDownLeft.y(), frontDownLeft.z());

        glVertex3f(backDownRight.x(), backDownRight.y(), backDownRight.z());
        glVertex3f(frontDownRight.x(), frontDownRight.y(), frontDownRight.z());
    glEnd();

    glLineWidth(2.0f);
    // draw global coordinate system
    glBegin(GL_LINES);
        glColor3f(1.0, 0.0, 0.0);
        glVertex3f(-1.5, -1.0, -1.0);
        glVertex3f(1.0, -1.0, -1.0);

        glColor3f(0.0, 1.0, 0.0);
        glVertex3f(-1.5, -1.0, -1.0);
        glVertex3f(-1.5, 1.0, -1.0);

        glColor3f(0.0, 0.0, 1.0);
        glVertex3f(-1.5, -1.0, -1.0);
        glVertex3f(-1.5, -1.0, 1.0);
    glEnd();

    // draw global coordinate system
//    glBegin(GL_LINES);
//        glColor3f(1.0, 0.0, 0.0);
//        glVertex3f(0.0, 0.0, 0.0);
//        glVertex3f(1.5, 00.0, 0.0);
//
//        glColor3f(0.0, 1.0, 0.0);
//        glVertex3f(0.0, 0.0, 0.0);
//        glVertex3f(0.0, 1.5, 0.0);
//
//        glColor3f(0.0, 0.0, 1.0);
//        glVertex3f(0.0, 0.0, 0.0);
//        glVertex3f(0.0, 0.0, 1.5);
//    glEnd();

    glLineWidth(1.0f);
}


void GLCanvas::renderSingleJoint() const
{
    Vector3 lookAt = _cameraPosition + _cameraFront;
    gluLookAt(_cameraPosition.x(), _cameraPosition.y(), _cameraPosition.z(),
              lookAt.x()         , lookAt.y()         , lookAt.z(),
              _cameraUp.x()      , _cameraUp.y()      , _cameraUp.z());

    glBegin(GL_LINES);
        glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
        glVertex3f(0.0f, 0.0f, 0.0f);
        glVertex3f(1.0f, 0.0f, 0.0f);

        glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
        glVertex3f(0.0f, 0.0f, 0.0f);
        glVertex3f(0.0f, 1.0f, 0.0f);

        glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
        glVertex3f(0.0f, 0.0f, 0.0f);
        glVertex3f(0.0f, 0.0f, 1.0f);
    glEnd();

    if (_constraint != nullptr)
    {
        drawJoint(*_constraint, 1.0f);
    }
}

// Initialization of all OpenGL specific parameters.
void GLCanvas::InitGL()
{
    SetCurrent(*_GLRC);
	glClearColor(0.0, 0.0, 0.0, 0.0);
    //glClearColor(1.0, 1.0, 1.0, 1.0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_BLEND);
    glEnable(GL_CULL_FACE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glShadeModel(GL_SMOOTH);
}
Exemple #5
0
void scene::createCube()
{
    glNormal3f(0.f, 0.f, 1.f);
    
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, 0.f, 0.5f);
    glVertex3f(0.f, 0.f, 0.5f);
    glVertex3f(0.f,  0.5f, 0.5f);
    glVertex3f(-0.5f,  0.5f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.f, 0.f, 0.5f);
    glVertex3f(0.5f, 0.f, 0.5f);
    glVertex3f(0.5f,  0.5f, 0.5f);
    glVertex3f(0.f,  0.5f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f(0.f, -0.5f, 0.5f);
    glVertex3f(0.f,  0.f, 0.5f);
    glVertex3f(-0.5f,  0.f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.f, -0.5f, 0.5f);
    glVertex3f(0.5f, -0.5f, 0.5f);
    glVertex3f(0.5f,  0.f, 0.5f);
    glVertex3f(0.f,  0.f, 0.5f);
    glEnd();
    
    glNormal3f(0.f, 0.f, -1.f);
    
    glBegin(GL_QUADS);
    glVertex3f(0.f, 0.f, -0.5f);
    glVertex3f(-0.5f, 0.f, -0.5);
    glVertex3f(-0.5f,  0.5f, -0.5);
    glVertex3f(0.f,  0.5f, -0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, 0.f, -0.5f);
    glVertex3f(0.f, 0.f, -0.5f);
    glVertex3f(0.f,  0.5f, -0.5f);
    glVertex3f(0.5f,  0.5f, -0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.f, -0.5f, -0.5f);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f(-0.5f,  0.f, -0.5);
    glVertex3f(0.f,  0.f, -0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, -0.5f, -0.5f);
    glVertex3f(0.f, -0.5f, -0.5f);
    glVertex3f(0.f,  0.f, -0.5f);
    glVertex3f(0.5f,  0.f, -0.5f);
    glEnd();
    
    glNormal3f(1.f, 0.f, 0.f);
    
    glBegin(GL_QUADS);
    glVertex3f(0.5f, 0.f, 0.5f);
    glVertex3f(0.5f, 0.f, 0.f);
    glVertex3f(0.5f,  0.5f, 0.f);
    glVertex3f(0.5f,  0.5f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, -0.5f, 0.5f);
    glVertex3f(0.5f, -0.5f, 0.f);
    glVertex3f(0.5f,  0.f, 0.f);
    glVertex3f(0.5f,  0.f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, -0.5f, 0.f);
    glVertex3f(0.5f, -0.5f, -0.5f);
    glVertex3f(0.5f,  0.f, -0.5f);
    glVertex3f(0.5f,  0.f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, 0.f, 0.f);
    glVertex3f(0.5f, 0.f, -0.5f);
    glVertex3f(0.5f, 0.5f, -0.5f);
    glVertex3f(0.5f, 0.5f, 0.f);
    glEnd();
    
    glNormal3f(-1.f, 0.f, 0.f);
    
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, 0.f, 0.f);
    glVertex3f(-0.5f, 0.f, 0.5f);
    glVertex3f(-0.5f,  0.5f, 0.5f);
    glVertex3f(-0.5f,  0.5f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, -0.5f, 0.f);
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glVertex3f(-0.5f,  0.f, 0.5f);
    glVertex3f(-0.5f,  0.f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f(-0.5f, -0.5f, 0.f);
    glVertex3f(-0.5f,  0.f, 0.f);
    glVertex3f(-0.5f,  0.f, -0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, 0.f, -0.5f);
    glVertex3f(-0.5f, 0.f, 0.f);
    glVertex3f(-0.5f, 0.5f, 0.);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    glEnd();
    
    glNormal3f(0.f, -1.f, 0.f);
    
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, -0.5f, -0.5f);
    glVertex3f(0.f, -0.5f, -0.5f);
    glVertex3f(0.f, -0.5f, 0.f);
    glVertex3f(-0.5f, -0.5f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.f, -0.5f, -0.5f);
    glVertex3f(0.5f, -0.5f, -0.5f);
    glVertex3f(0.5f, -0.5f, 0.f);
    glVertex3f(0.f, -0.5f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, -0.5f, 0.f);
    glVertex3f(0.f, -0.5f, 0.f);
    glVertex3f(0.f, -0.5f, 0.5f);
    glVertex3f(-0.5f, -0.5f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.f, -0.5f, 0.f);
    glVertex3f(0.5f, -0.5f, 0.f);
    glVertex3f(0.5f, -0.5f, 0.5f);
    glVertex3f(0.f, -0.5f, 0.5f);
    glEnd();
    
    glNormal3f(0.f, 1.f, 0.f);
    
    glBegin(GL_QUADS);
    glVertex3f(0.f, 0.5f, -0.5f);
    glVertex3f(-0.5f, 0.5f, -0.5f);
    glVertex3f(-0.5f, 0.5f, 0.f);
    glVertex3f(0.f, 0.5f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, 0.5f, -0.5f);
    glVertex3f(0.f, 0.5f, -0.5f);
    glVertex3f(0.f, 0.5f, 0.f);
    glVertex3f(0.5f, 0.5f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.f, 0.5f, 0.f);
    glVertex3f(-0.5f, 0.5f, 0.f);
    glVertex3f(-0.5f, 0.5f, 0.5f);
    glVertex3f(0.f, 0.5f, 0.5f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.5f, 0.5f, 0.f);
    glVertex3f(0.f, 0.5f, 0.f);
    glVertex3f(0.f, 0.5f, 0.5f);
    glVertex3f(0.5f, 0.5f, 0.5f);
    glEnd();
}
Exemple #6
0
//nbr_vertices: nombre de vertex du profile
//profile[]: tableau 2d contenant les vertex du profile
//vector[] : vecteur d'extrusion
void extrude(int nbr_vertices, GLfloat profile[], GLfloat vector[]) {

int v;

float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;

for(v=0; v<nbr_vertices-1; v++) {

x1 = profile[v*2];
y1 = profile[v*2+1];
z1 = 0;

x2 = profile[v*2+2];
y2 = profile[v*2+3];
z2 = 0;

x3 = profile[v*2+2]+vector[0];
y3 = profile[v*2+3]+vector[1];
z3 = vector[2];

x4 = profile[v*2]+vector[0];
y4 = profile[v*2+1]+vector[1];
z4 = vector[2];

// calcul de la normale au plan par produit vectoriel

float v1x,v1y,v1z, // V1
      v2x,v2y,v2z, // V2
      nx,ny,nz;    // normale à la face

v1x = x2 - x1;
v1y = y2 - y1;
v1z = z2 - z1;

v2x = x3 - x2;
v2y = y3 - y2;
v2z = z3 - z2;

nx = (v1y * v2z) - (v1z * v2y);
ny = (v1z * v2x) - (v1x * v2z);
nz = (v1x * v2y) - (v1y * v2x);

// Affichage de la face avec les normales associées à chaque sommet
glBegin(GL_POLYGON);
glNormal3f(nx,ny,nz); 
glVertex3f(x1,y1,z1);
glNormal3f(nx,ny,nz); 
glVertex3f(x2,y2,z2);
glNormal3f(nx,ny,nz); 
glVertex3f(x3,y3,z3);
glNormal3f(nx,ny,nz); 
glVertex3f(x4,y4,z4);
glEnd();

}

// Calcul des faces laterales

// face 1
int w;
glBegin(GL_POLYGON);

for(w=0; w<nbr_vertices-1; w++)
{
glNormal3f(0.0,0.0,-1.0);
glVertex3f(profile[w*2],profile[w*2+1],0.0);
}

glEnd();

// face 2
glBegin(GL_POLYGON);

for(w=0; w<nbr_vertices-1; w++)
{
glNormal3f(0.0,0.0,-1.0);
glVertex3f(profile[w*2]+vector[0],profile[w*2+1]+vector[1],+vector[2]);
}

glEnd();



}
Exemple #7
0
static int
draw_sphere(int pos, int tick)
{
    int pos2 = (pos+1) % NPOSITIONS;
    GLfloat x1 = ball_positions[pos*3];
    GLfloat y1 = ball_positions[pos*3+1];
    GLfloat z1 = ball_positions[pos*3+2];
    GLfloat x2 = ball_positions[pos2*3];
    GLfloat y2 = ball_positions[pos2*3+1];
    GLfloat z2 = ball_positions[pos2*3+2];
    GLfloat frac = tick / (GLfloat) SPHERE_TICKS;
    GLfloat x = x1 + (x2 - x1) * frac;
    GLfloat y = y1 + (y2 - y1) * frac + (2 * sin (M_PI * frac));
    GLfloat z = z1 + (z2 - z1) * frac;
    int polys = 0;

	glPushMatrix();

# ifdef DEBUG_PATH
    glVertex3f(x, y, z);
    if (tick == 0) {
      glVertex3f(x, y-7.5, z);
      glVertex3f(x, y, z); glVertex3f(x, y, z-0.6);
      glVertex3f(x, y, z); glVertex3f(x, y, z+0.6);
      glVertex3f(x, y, z); glVertex3f(x+0.6, y, z);
      glVertex3f(x, y, z); glVertex3f(x-0.6, y, z);
      glVertex3f(x, y, z);
    }

# else /* !DEBUG_PATH */
    y += 0.5;
    glTranslatef(x, y, z);

    glScalef (0.5, 0.5, 0.5);

    /* make ball a little smaller on the gap to obscure distance */
	if (pos == NPOSITIONS-1)
      glScalef (0.95, 0.95, 0.95);

	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
    glDisable (GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glFrontFace(GL_CCW);
    polys += unit_sphere (32, 32, False);
	glShadeModel(GL_FLAT);
    glEnable (GL_TEXTURE_2D);
#endif /* !DEBUG_PATH */

	glPopMatrix();
    return polys;
}
void renderSpace(sf::RenderTarget& window, sf::Vector3f cameraPosition, float yaw, float pitch, float roll)
{
    window.pushGLStates();

    glClearDepth(1.f);
    glClear(GL_DEPTH_BUFFER_BIT);
    glDepthMask(GL_TRUE);
    glEnable(GL_CULL_FACE);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    _glPerspective(60.f, 320.0/240.0, 1.f, 16000.f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glRotatef(90, 1, 0, 0);
    glScalef(1,1,-1);
    glRotatef(-roll, 0,1, 0);
    glRotatef(-pitch, 0, 1, 0);
    glRotatef(-yaw, 0, 0, 1);
  
    textureManager.getTexture("Stars")->setSmooth(true);
    sf::Texture::bind(textureManager.getTexture("Stars"), sf::Texture::Pixels);
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(1024,    0); glVertex3f( 100, 100, 100);
    glTexCoord2f(   0,    0); glVertex3f( 100, 100,-100);
    glTexCoord2f(1024, 1024); glVertex3f(-100, 100, 100);
    glTexCoord2f(   0, 1024); glVertex3f(-100, 100,-100);
    glEnd();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(1024,    0); glVertex3f(-100, 100, 100);
    glTexCoord2f(   0,    0); glVertex3f(-100, 100,-100);
    glTexCoord2f(1024, 1024); glVertex3f(-100,-100, 100);
    glTexCoord2f(   0, 1024); glVertex3f(-100,-100,-100);
    glEnd();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(1024,    0); glVertex3f(-100,-100, 100);
    glTexCoord2f(   0,    0); glVertex3f(-100,-100,-100);
    glTexCoord2f(1024, 1024); glVertex3f( 100,-100, 100);
    glTexCoord2f(   0, 1024); glVertex3f( 100,-100,-100);
    glEnd();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(1024,    0); glVertex3f( 100,-100, 100);
    glTexCoord2f(   0,    0); glVertex3f( 100,-100,-100);
    glTexCoord2f(1024, 1024); glVertex3f( 100, 100, 100);
    glTexCoord2f(   0, 1024); glVertex3f( 100, 100,-100);
    glEnd();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(1024,    0); glVertex3f( 100,-100, 100);
    glTexCoord2f(   0,    0); glVertex3f(-100,-100, 100);
    glTexCoord2f(1024, 1024); glVertex3f( 100, 100, 100);
    glTexCoord2f(   0, 1024); glVertex3f(-100, 100, 100);
    glEnd();
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(1024,    0); glVertex3f( 100,-100,-100);
    glTexCoord2f(   0,    0); glVertex3f(-100,-100,-100);
    glTexCoord2f(1024, 1024); glVertex3f( 100, 100,-100);
    glTexCoord2f(   0, 1024); glVertex3f(-100, 100,-100);
    glEnd();
    
    for(unsigned int n=0; n<nebulaInfo.size(); n++)
    {
        sf::Texture::bind(textureManager.getTexture(nebulaInfo[n].textureName), sf::Texture::Pixels);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
        glPushMatrix();
        glRotatef(180, nebulaInfo[n].vector.x, nebulaInfo[n].vector.y, nebulaInfo[n].vector.z);
        glColor4f(1,1,1,0.3);
        glBegin(GL_TRIANGLE_STRIP);
        glTexCoord2f(1024,    0); glVertex3f( 100, 100, 100);
        glTexCoord2f(   0,    0); glVertex3f( 100, 100,-100);
        glTexCoord2f(1024, 1024); glVertex3f(-100, 100, 100);
        glTexCoord2f(   0, 1024); glVertex3f(-100, 100,-100);
        glEnd();
        glPopMatrix();
    }
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    sf::Texture::bind(NULL);
    
    sf::Vector2f cameraPosition2D(cameraPosition.x, cameraPosition.y);
    glDisable(GL_DEPTH_TEST);

    //Shade the objects with light from the first sun.
    //TODO: Fix for multiple suns.
    P<Sun> sun = sunList[0];
    
    if (lightShader == NULL)
    {
        lightShader = new sf::Shader();
        lightShader->loadFromFile("resources/perPixelLight.vert", "resources/perPixelLight.frag");
    }
    
    sf::Vector2f viewVector = sf::vector2FromAngle(yaw);
    std::vector<RenderSortInfo> renderList;
    foreach(SpaceObject, obj, spaceObjectList)
    {
        RenderSortInfo info;
        info.obj = *obj;
        info.objectDepth = sf::dot(viewVector, obj->getPosition() - cameraPosition2D);
        
        renderList.push_back(info);
    }
Exemple #9
0
void FenceSegment::render() const
{
   // HAUKAP - need spike::render to reduce code
   glPushMatrix();
   {
      glTranslatef( m_point.x, m_point.y, m_point.z);
      glRotatef( m_fenceAngle, 0.0f, 0.0f, 1.0f);
      glLineWidth(1);
      //glColor3f(0.0f, 0.0f, 0.0f);
      glScalef( m_scale, m_scale, m_scale );

      // first spike 
      glPushMatrix();
      {
         glRotatef( m_spikeAngles[0], 0.0f, 0.0f, 1.0f);         
         glBegin( GL_LINES );
            glVertex3f( 0, 0, 0.0f );
            glVertex3f( 0, 1.0, 0.0f);
         glEnd();  
      }
      glPopMatrix();

      // second spike 
      glPushMatrix();
      {
         glRotatef( m_spikeAngles[1], 0.0f, 0.0f, 1.0f);
         glBegin( GL_LINES );
            glVertex3f( 0, 0, 0.0f );
            glVertex3f( 0, 1.0, 0.0f);
         glEnd();  
      }
      glPopMatrix();
      
      // third spike 
      glPushMatrix();
      {
         glRotatef( m_spikeAngles[2], 0.0f, 0.0f, 1.0f);
         glBegin( GL_LINES );
            glVertex3f( 0, 0, 0.0f );
            glVertex3f( 0, 1.0, 0.0f);
         glEnd();  
      }
      glPopMatrix();

      // fourth spike 
      glPushMatrix();
      {
         glRotatef( m_spikeAngles[3], 0.0f, 0.0f, 1.0f);
         glBegin( GL_LINES );
            glVertex3f( 0, 0, 0.0f );
            glVertex3f( 0, 1.0, 0.0f);
         glEnd();  
      }
      glPopMatrix();

      // fifth spike 
      glPushMatrix();
      {
         glRotatef( m_spikeAngles[4], 0.0f, 0.0f, 1.0f);
         glBegin( GL_LINES );
            glVertex3f( 0, 0, 0.0f );
            glVertex3f( 0, 1.0, 0.0f);
         glEnd();  
      }
      glPopMatrix();
   }
   glPopMatrix();

}
Exemple #10
0
/* draw an ant */
static Bool draw_antinspect_ant(ModeInfo *mi, antinspectstruct * mp, 
                                const float *Material, int mono,
                                Bool (*sphere)(float), Bool (*cone)(float)) 
{
  float       cos1 = cos(mp->ant_step);
  float       cos2 = cos(mp->ant_step + 2 * Pi / 3);
  float       cos3 = cos(mp->ant_step + 4 * Pi / 3);
  float       sin1 = sin(mp->ant_step);
  float       sin2 = sin(mp->ant_step + 2 * Pi / 3);
  float       sin3 = sin(mp->ant_step + 4 * Pi / 3);
  
  if (mono)
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray5);
  else
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Material);
  glEnable(GL_CULL_FACE);
  glPushMatrix();
  glScalef(1, 1.3, 1);
  if (!((*sphere)(0.18)))
    return False;
  glScalef(1, 1 / 1.3, 1);
  glTranslatef(0.00, 0.30, 0.00);
  if (!((*sphere)(0.2)))
    return False;
  
  glTranslatef(-0.05, 0.17, 0.05);
  glRotatef(-90, 1, 0, 0);
  glRotatef(-25, 0, 1, 0);
  if (!((*cone)(0.05)))
    return False;
  glTranslatef(0.00, 0.10, 0.00);
  if (!((*cone)(0.05)))
    return False;
  glRotatef(25, 0, 1, 0);
  glRotatef(90, 1, 0, 0);
  
  glScalef(1, 1.3, 1);
  glTranslatef(0.15, -0.65, 0.05);
  if (!((*sphere)(0.25)))
    return False;
  glScalef(1, 1 / 1.3, 1);
  glPopMatrix();
  glDisable(GL_CULL_FACE);
  
  glDisable(GL_LIGHTING);
  
  /* ANTENNAS */
  glBegin(GL_LINES);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, 0.30, 0.00);
  glColor3fv(MaterialGray);
  glVertex3f(0.40, 0.70, 0.40);
  mi->polygon_count++;
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, 0.30, 0.00);
  glColor3fv(MaterialGray);
  glVertex3f(0.40, 0.70, -0.40);
  mi->polygon_count++;
  glEnd();
  glBegin(GL_POINTS);
  if (mono)
    glColor3fv(MaterialGray6);
  else
    glColor3fv(Material);
  glVertex3f(0.40, 0.70, 0.40);
  mi->polygon_count++;
  glVertex3f(0.40, 0.70, -0.40);
  mi->polygon_count++;
  glEnd();
  
  /* LEFT-FRONT ARM */
  glBegin(GL_LINE_STRIP);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, 0.05, 0.18);
  glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
  mi->polygon_count++;
  glColor3fv(MaterialGray);
  glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
  mi->polygon_count++;
  glEnd();
  
  /* LEFT-CENTER ARM */
  glBegin(GL_LINE_STRIP);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, 0.00, 0.18);
  glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
  mi->polygon_count++;
  glColor3fv(MaterialGray);
  glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
  mi->polygon_count++;
  glEnd();
  mi->polygon_count++;
  
  /* LEFT-BACK ARM */
  glBegin(GL_LINE_STRIP);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, -0.05, 0.18);
  glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
  mi->polygon_count++;
  glColor3fv(MaterialGray);
  glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
  mi->polygon_count++;
  glEnd();
  
  /* RIGHT-FRONT ARM */
  glBegin(GL_LINE_STRIP);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, 0.05, -0.18);
  glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
  mi->polygon_count++;
  glColor3fv(MaterialGray);
  glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
  mi->polygon_count++;
  glEnd();
  
  /* RIGHT-CENTER ARM */
  glBegin(GL_LINE_STRIP);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, 0.00, -0.18);
  glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
  mi->polygon_count++;
  glColor3fv(MaterialGray);
  glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
  mi->polygon_count++;
  glEnd();
  
  /* RIGHT-BACK ARM */
  glBegin(GL_LINE_STRIP);
  if (mono)
    glColor3fv(MaterialGray5);
  else
    glColor3fv(Material);
  glVertex3f(0.00, -0.05, -0.18);
  glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
  mi->polygon_count++;
  glColor3fv(MaterialGray);
  glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
  mi->polygon_count++;
  glEnd();
    
  glEnable(GL_LIGHTING);
  
  return True;
}
Exemple #11
0
/* draw the scene */
static Bool draw_antinspect_strip(ModeInfo * mi) 
{
  antinspectstruct *mp = &antinspect[MI_SCREEN(mi)];
  int         i, j;
  int         mono = MI_IS_MONO(mi);

  int ro = (((int)antposition[1])/(360/(2*ANTCOUNT))) % (2*ANTCOUNT);

  glEnable(GL_TEXTURE_2D);
  position0[1] = 9.6;
  glLightfv(GL_LIGHT0, GL_POSITION, position0);

  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray5);
  glRotatef(-30.0, 0.0, 1.0, 0.0);

  glDisable(GL_TEXTURE_2D);
  glDisable(GL_BLEND);

  /* render ground plane */
  glBegin(GL_TRIANGLES);
  glColor4fv(MaterialShadow);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlack);
  glNormal3f(0.0, 1.0, 0.0);

  /* middle tri */
  glVertex3f(0.0, 0.0, -1.0);
  glVertex3f(-sqrt(3.0)/2.0, 0.0, 0.5);
  glVertex3f(sqrt(3.0)/2.0, 0.0, 0.5);
  mi->polygon_count++;
  glEnd();

  /* rotate */
  for(i = 0; i < 3; ++i) {
    glRotatef(120.0, 0.0, 1.0, 0.0);
    glBegin(GL_TRIANGLES);
    glVertex3f(0.0, 0.0, 1.0 + 3.0);
    glVertex3f(sqrt(3.0)/2.0, 0.0, -0.5 + 3.0);
    glVertex3f(-sqrt(3.0)/2.0, 0.0, -0.5 + 3.0);
    mi->polygon_count++;
    glEnd();
  }

  /* first render shadows -- no depth required */
  if(shadows) {
    GLfloat m[4][4];
    shadowmatrix(m, ground, position0);
    
    glColor4fv(MaterialShadow);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow);
    
    glDisable(GL_BLEND);
    glDisable(GL_LIGHTING);
    
    /* display ant shadow */
    glPushMatrix();
    glTranslatef(0.0, 0.001, 0.0);
    glMultMatrixf(m[0]);

    for(i = 0; i < ANTCOUNT; ++i) {

      /* draw ant */
      glPushMatrix();

      /* center */
      glRotatef(antposition[i], 0.0, 1.0, 0.0);
      glTranslatef(2.4, 0.0, 0.0);
      glTranslatef(0.0, antsphere[i], 0.0);
      glRotatef(90.0, 0.0, 1.0, 0.0);

      /* orient ant */
      glRotatef(10.0, 0.0, 1.0, 0.0);
      glRotatef(40.0, 0.0, 0.0, 1.0);
      glTranslatef(0.0, -0.8, 0.0);
      glRotatef(180.0, 0.0, 1.0, 0.0);
      glRotatef(90.0, 0.0, 0.0, 1.0);

      /* set colour */
      glColor4fv(MaterialShadow);
      glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow);

      if(antposition[i] > 360.0)
	antposition[i] = 0.0;
      draw_antinspect_ant(mi, mp, MaterialShadow, mono, mySphere2, myCone2);

      glDisable(GL_BLEND);
      glDisable(GL_LIGHTING);

      /* draw sphere */
      glRotatef(-20.0, 1.0, 0.0, 0.0);
      glRotatef(-mp->ant_step*2, 0.0, 0.0, 1.0);
      glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow);
      mySphere2(1.2);

      glPopMatrix();
    }
  
    glPopMatrix();
  }

  glEnable(GL_LIGHTING);

  /* truants */
  for(j = 0; j < ANTCOUNT; ++j) {
    /* determine rendering order */
    i = antorder[ro][j];

    glPushMatrix();
    
    /* center */
    glRotatef(antposition[i], 0.0, 1.0, 0.0);
    glTranslatef(2.4, 0.0, 0.0);
    glTranslatef(0.0, antsphere[i], 0.0);    
    glRotatef(90.0, 0.0, 1.0, 0.0);

    /* draw ant */
    glPushMatrix();
    glRotatef(10.0, 0.0, 1.0, 0.0);
    glRotatef(40.0, 0.0, 0.0, 1.0);
    glTranslatef(0.0, -0.8, 0.0);
    glRotatef(180.0, 0.0, 1.0, 0.0);
    glRotatef(90.0, 0.0, 0.0, 1.0);
    if(antposition[i] > 360.0)
      antposition[i] = 0.0;
    glEnable(GL_BLEND);
    draw_antinspect_ant(mi, mp, antmaterial[i], mono, mySphere2, myCone2);
    glDisable(GL_BLEND);
    glPopMatrix();

    /* draw sphere */
    glRotatef(-20.0, 1.0, 0.0, 0.0);
    glRotatef(-mp->ant_step*2, 0.0, 0.0, 1.0);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : antmaterial[i]);
    mySphere2(1.2);
    glEnable(GL_BLEND);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlack);
    mySphere(1.16);
    glDisable(GL_BLEND);
        
    glPopMatrix();

    /* finally, evolve */
    antposition[i] += antvelocity[i];
  }

  /* but the step size is the same! */
  mp->ant_step += 0.2;
  
  mp->ant_position += 1;
  return True;
}
HRESULT COpenGLVideoContext::PrepareFrame(void)
{
	if(!m_pVideoPresenter)	return E_FAIL;
	if(!m_bShow)	return S_OK;

	glTranslatef(0.0f,0.0f,m_zOrder);

	if(m_bPopUp)
	{
		long eclispeTick = 0;
		static long lastTick = GetTickCount();
		static long currTick = GetTickCount();

		static float sFact = 0.0f;
		static float sflag = 1.0f;
		currTick = GetTickCount();
		
		eclispeTick  = currTick -lastTick ;

		sFact  += ((float)eclispeTick/1000.0f)/2.0f*sflag;
		if(sFact > 1.0f)
			sflag = -1.0f;

		if(sFact < 0.0f)
			sflag = 1.0f;

		if(sFact > 1.0f)	sFact = 1.0f;
		else if(sFact < -1.0f)	sFact = -1.0f;

		glScalef(sFact,sFact,1.0f);

		lastTick = GetTickCount();
	}


	LARGE_INTEGER setposEnd;
	QueryPerformanceCounter (&setposEnd);

	long setposEclipse = 1000*(setposEnd.QuadPart - m_tSetposStart.QuadPart)/m_coutFreq.QuadPart ;
	float passPercent = (float)setposEclipse /m_setposSpeed;
	if(passPercent < 1.0f)
	{
	//	glRotatef(360.0f*passPercent,0.0f,1.0f,0.0f);
	}

	if(!m_contentUpdated)
	{
		if(m_textureId == -1)
			return S_OK;
		glBindTexture (GL_TEXTURE_2D, m_textureId);

	}
	else
	{
		EnterCriticalSection(&m_csDisplay);
		m_textureId = m_textureMgr.LoadTextureFromMemory(m_pBuff, m_openOptions.dwWidth, m_openOptions.dwHeight,m_bpp,  m_textureId);
		m_contentUpdated = false;
		LeaveCriticalSection(&m_csDisplay);
	}

	glBegin(GL_QUADS);
	glNormal3f( 0.0f, 0.0f, 1.0);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, -0.5,  0.5);
	glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5, -0.5,  0.5);
	glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5,  0.5,  0.5);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5,  0.5,  0.5);
	glEnd();

	return S_OK;
}
Exemple #13
0
//现在我们绘制贴图『译者注:其实贴图就是纹理映射。将术语换来换去不好,我想少打俩字。^_^』过的立方体。
//这段代码被狂注释了一把,应该很好懂。
//开始两行代码 glClear() 和 glLoadIdentity() 是第一课中就有的代码。
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 清除屏幕并设为我们在 InitGL() 中选定的颜色,本例中是黑色。
//深度缓存也被清除。模型观察矩阵也使用glLoadIdentity()重置。
void MyGLWidget::paintGL()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);			// 清除屏幕和深度缓存
	glLoadIdentity();							// 重置当前的模型观察矩阵
	glTranslatef(0.0f,0.0f,mZ);						// 移入屏幕z个单位
	//下三行代码放置并旋转贴图立方体。glTranslatef(0.0f,0.0f,z)将立方体沿着Z轴移动Z单位。
	//glRotatef(xrot,1.0f,0.0f,0.0f)将立方体绕X轴旋转xrot。
	//glRotatef(yrot,0.0f,1.0f,0.0f)将立方体绕Y轴旋转yrot。
	glRotatef(mXRotate,1.0f,0.0f,0.0f);						// X轴旋转
	glRotatef(mYRotate,0.0f,1.0f,0.0f);						// Y轴旋转

	//下一行与我们在第六课中的类似。有所不同的是,这次我们绑定的纹理是texture[filter],而不是上一课中的texture[0]。
	//任何时候,我们按下F键,filter 的值就会增加。如果这个数值大于2,变量filter 将被重置为0。
	//程序初始时,变量filter 的值也将设为0。使用变量filter 我们就可以选择三种纹理中的任意一种。
	glBindTexture(GL_TEXTURE_2D, mTexture[mFilter]);				// 选择由filter决定的纹理
	//为了将纹理正确的映射到四边形上,您必须将纹理的右上角映射到四边形的右上角,纹理的左上角映射到四边形的左上角,
	//纹理的右下角映射到四边形的右下角,纹理的左下角映射到四边形的左下角。
	//如果映射错误的话,图像显示时可能上下颠倒,侧向一边或者什么都不是。
	//glTexCoord2f 的第一个参数是X坐标。 0.0f 是纹理的左侧。 0.5f 是纹理的中点, 1.0f 是纹理的右侧。
	//glTexCoord2f 的第二个参数是Y坐标。 0.0f 是纹理的底部。 0.5f 是纹理的中点, 1.0f 是纹理的顶部。
	//所以纹理的左上坐标是 X:0.0f,Y:1.0f ,四边形的左上顶点是 X: -1.0f,Y:1.0f 。其余三点依此类推。
	//试着玩玩 glTexCoord2f X, Y坐标参数。把 1.0f 改为 0.5f 将只显示纹理的左半部分,把 0.0f 改为 0.5f 将只显示纹理的右半部分。
	//glNormal3f是这一课的新东西。Normal就是法线的意思,所谓法线是指经过面(多边形)上的一点且垂直于这个面(多边形)的直线。
	//使用光源的时候必须指定一条法线。法线告诉OpenGL这个多边形的朝向,并指明多边形的正面和背面。
	//如果没有指定法线,什么怪事情都可能发生:不该照亮的面被照亮了,多边形的背面也被照亮....。对了,法线应该指向多边形的外侧。
	//看着木箱的前面您会注意到法线与Z轴正向同向。这意味着法线正指向观察者-您自己。这正是我们所希望的。
	//对于木箱的背面,也正如我们所要的,法线背对着观察者。如果立方体沿着X或Y轴转个180度的话,
	//前侧面的法线仍然朝着观察者,背面的法线也还是背对着观察者。换句话说,不管是哪个面,只要它朝着观察者这个面的法线就指向观察者。
	//由于光源紧邻观察者,任何时候法线对着观察者时,这个面就会被照亮。并且法线越朝着光源,就显得越亮一些。
	//如果您把观察点放到立方体内部,你就会法线里面一片漆黑。因为法线是向外指的。如果立方体内部没有光源的话,当然是一片漆黑。
	glBegin(GL_QUADS);
		// 前面
		glNormal3f( 0.0f, 0.0f, 1.0f);					// 法线指向观察者
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// 纹理和四边形的左下
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// 纹理和四边形的右下
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// 纹理和四边形的右上
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// 纹理和四边形的左上
		// 后面
		glNormal3f( 0.0f, 0.0f,-1.0f);					// 法线背向观察者
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// 纹理和四边形的右下
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// 纹理和四边形的右上
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// 纹理和四边形的左上
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// 纹理和四边形的左下
		// 顶面
		glNormal3f( 0.0f, 1.0f, 0.0f);					// 法线向上
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// 纹理和四边形的左上
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// 纹理和四边形的左下
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// 纹理和四边形的右下
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// 纹理和四边形的右上
		// 底面
		glNormal3f( 0.0f,-1.0f, 0.0f);					// 法线朝下
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// 纹理和四边形的右上
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// 纹理和四边形的左上
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// 纹理和四边形的左下
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// 纹理和四边形的右下

		// 右面
		glNormal3f( 1.0f, 0.0f, 0.0f);					// 法线朝右
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// 纹理和四边形的右下
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// 纹理和四边形的右上
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// 纹理和四边形的左上
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// 纹理和四边形的左下

		// 左面
		glNormal3f(-1.0f, 0.0f, 0.0f);					// 法线朝左
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// 纹理和四边形的左下
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// 纹理和四边形的右下
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// 纹理和四边形的右上
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// 纹理和四边形的左上
	glEnd();

}
/**
 * Method draw triangles in patchEnumerator to scene
 */
void Visualizer::start(TriangleSetExt *pTset, TColorInput colorInput)
{
	TriangleSetExt &tset = *pTset;

	glBegin(GL_TRIANGLES);
	for(unsigned int i=0; i<tset.count(); i++) {
		TriangleExt &te = tset[i];
		for(int i=0; i<3; i++) {
			Color &color = te.vertexColor[i];
			Color &color2 = te.vertexColorRaw[i];
			Vertex &vertex = te.vertex[i];
			
			switch (colorInput)
			{
				case INTERPOLATE_RADIOSITY:
					glColor3f(
						color.r,
						color.g,
						color.b);
					break;
				
				case INTERPOLATE_RADIOSITY_RAW:
					glColor3f(
						color2.r,
						color2.g,
						color2.b);
					break;
				
				case RADIOSITY_LAST:
					glColor3f(
						te.radiosityLast.r,
						te.radiosityLast.g,
						te.radiosityLast.b);
					break;
					
				case RADIOSITY:
					glColor3f(
						te.radiosity.r,
						te.radiosity.g,
						te.radiosity.b);
					break;

				case REFLECTIVITY:
					glColor3f(
						te.reflectivity.r, 
						te.reflectivity.g, 
						te.reflectivity.b);
					break;

				case EMISSION:
					glColor3f(
						te.emission.r, 
						te.emission.g, 
						te.emission.b);
				
					break;

				case REFLECT_EMISS:
					glColor3f(
						te.reflectivity.r + te.emission.r, 
						te.reflectivity.g + te.emission.g, 
						te.reflectivity.b + te.emission.b);

					break;
			}
			glVertex3f(
				vertex.x,
				vertex.y,
				vertex.z);
		}
	}	
  	glEnd();
}
Exemple #15
0
/* Focntion de dessin */
void DrawGLScene()
{
// Effacement du buffer de couleur et de profondeur
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		

  glLoadIdentity();
  gluLookAt(0.0,15.0,20.0,0.0,8.0,0.0,0.0,1.0,0.0); 



// 1er Partie du TD
/*

  // Objet par extrusion : segement/pince
  glPushMatrix();
  glColor3f(0.6,0.6,0.6);
  glRotatef(45,1.0,0.0,0.0);
  glTranslatef(0,0,0);
  glScalef(0.5,0.5,0.5);
  extrude(9, Segment_2d, extrusion_vector);
  glPopMatrix();
*/

/*
  // Objet par révolution : base/lampadaire
  glPushMatrix();
  glColor3f(0.6,0.6,0.6);
  glTranslatef(-0,0.0,0);
  glRotatef(0,1.0,0.0,0.0);
  glScalef(0.3,0.3,0.3);
  revolution(7, pied_2d, 360, 16);
  glPopMatrix();				
*/

/*
  // Chargement d'un objet : articluation 
  DessinModele();
*/




  // Objets par listes d'affichage
/*
  Make_CallListes();

  glCallList(OBJET_1); 

  glCallList(OBJET_2); 

  glCallList(OBJET_3); 

  glCallList(OBJET_4); 

  glCallList(OBJET_5); 
*/



//2eme Partie du TD

  // Terain
  glBegin(GL_POLYGON);
  glNormal3f(0,1,0); 
  glVertex3f(-10.0f,0.0f,-10.0f);
  glVertex3f(10.0f,0.0f,-10.0f);
  glVertex3f(10.0f,0.0f,10.0f);
  glVertex3f(-10.0f,0.0f,10.0f);
  glEnd();	


  // Compilation des listes
  Make_CallListes();

  //pied 1
  glPushMatrix();
  glTranslatef(5.0f,0.0f,-8.0f);
  glCallList(OBJET_4);
  glPopMatrix();

  //pied 2
  glPushMatrix();
  glTranslatef(-5.0f,0.0f,-8.0f);
  glCallList(OBJET_4);
  glPopMatrix();

  //pied 3
  glPushMatrix();
  glTranslatef(5.0f,0.0f,0.0f);
  glCallList(OBJET_4);
  glPopMatrix();

  //pied 4
  glPushMatrix();
  glTranslatef(-5.0f,0.0f,0.0f);
  glCallList(OBJET_4);
  glPopMatrix();

  //etablie
  glPushMatrix();
  glTranslatef(0.0f,7.0f,-5.0f);
  glScalef(15.0,0.2,15.0);
  glutSolidCube(1.0);
  glPopMatrix();

  //base robot
  glPushMatrix();
  glTranslatef(5.0f,7.0f,-9.0f);
  glCallList(OBJET_3);
  glPopMatrix();


  //segement 1
  glPushMatrix();
  glTranslatef(-6.0f,7.5f,-10.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(-15.0,0.0,0.0,1.0);
  glCallList(OBJET_1);
  glPopMatrix();

  //segement 2
  glPushMatrix();
  glTranslatef(-3.0f,7.5f,-10.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(-15.0,0.0,0.0,1.0);
  glCallList(OBJET_1);
  glPopMatrix();

  //segement 1
  glPushMatrix();
  glTranslatef(0.0f,7.5f,-10.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(-15.0,0.0,0.0,1.0);
  glCallList(OBJET_1);
  glPopMatrix();


  //pince 1
  glPushMatrix();
  glTranslatef(-5.0f,7.2f,-2.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(45.0,0.0,0.0,1.0);
  glCallList(OBJET_2);
  glPopMatrix();

  //pince 2
  glPushMatrix();
  glTranslatef(-3.0f,7.2f,-2.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(45.0,0.0,0.0,1.0);
  glCallList(OBJET_2);
  glPopMatrix();


  //pince 3
  glPushMatrix();
  glTranslatef(-1.0f,7.2f,-2.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(45.0,0.0,0.0,1.0);
  glCallList(OBJET_2);
  glPopMatrix();


  //pince 4
  glPushMatrix();
  glTranslatef(1.0f,7.2f,-2.0f);
  glRotatef(90.0,1.0,0.0,0.0);
  glRotatef(45.0,0.0,0.0,1.0);
  glCallList(OBJET_2);
  glPopMatrix();


  //articulation 1
  glPushMatrix();
  glTranslatef(6.0f,8.0f,-2.0f);
  glCallList(OBJET_5);
  glPopMatrix();

  //articulation 2
  glPushMatrix();
  glTranslatef(3.0f,8.0f,-2.0f);
  glCallList(OBJET_5);
  glPopMatrix();


  //articulation 3
  glPushMatrix();
  glTranslatef(4.5f,8.0f,0.0f);
  glCallList(OBJET_5);
  glPopMatrix();



  // Permutation des buffers
  glutSwapBuffers();
  //Raffrechissement de l'image
  glutPostRedisplay();
}
Exemple #16
0
///////////////////////////////////////////////////////////
// Draw the skybox. This is just six quads, with texture
// coordinates set to the corners of the cube map
void DrawSkyBox(GLfloat fExtent)
{
	// Sky Box is manually textured
	bool isTexGenEnabled[3] = {0};
	if(glIsEnabled(GL_TEXTURE_GEN_S))
	{
		glDisable(GL_TEXTURE_GEN_S);
		isTexGenEnabled[0] = true;
	}
	if(glIsEnabled(GL_TEXTURE_GEN_T))
	{
		glDisable(GL_TEXTURE_GEN_T);
		isTexGenEnabled[1] = true;
	}
	if(glIsEnabled(GL_TEXTURE_GEN_R))
	{
		glDisable(GL_TEXTURE_GEN_R);
		isTexGenEnabled[2] = true;
	}
	//////////////////////////////////////////////////////////////////////////
	static bool isInitialized = false;
	if(!isInitialized)
	{
		// Six sides of a cube map
		const char *szCubeFaces[6] = { "data/brightday1_posx.bmp", "data/brightday1_negx.bmp", 
			"data/brightday1_posy.bmp", "data/brightday1_negy.bmp", "data/brightday1_posz.bmp", "data/brightday1_negz.bmp" };

		g_CubeMapID = SOIL_load_OGL_cubemap(szCubeFaces[0],szCubeFaces[1],szCubeFaces[2],szCubeFaces[3],szCubeFaces[4],szCubeFaces[5],
			SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS 
			| SOIL_FLAG_COMPRESS_TO_DXT	| SOIL_FLAG_TEXTURE_REPEATS	/*| SOIL_FLAG_INVERT_Y*/);
		// Set up texture maps        
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
		isInitialized = true;
	}

	// Enable cube mapping, and set texture environment to decal
	glEnable(GL_TEXTURE_CUBE_MAP);
	glBindTexture(GL_TEXTURE_CUBE_MAP,g_CubeMapID);	

	glBegin(GL_QUADS);
	//////////////////////////////////////////////
	// Negative X
	glTexCoord3f(-1.0f, -1.0f, 1.0f);
	glVertex3f(-fExtent, -fExtent, fExtent);

	glTexCoord3f(-1.0f, -1.0f, -1.0f);
	glVertex3f(-fExtent, -fExtent, -fExtent);

	glTexCoord3f(-1.0f, 1.0f, -1.0f);
	glVertex3f(-fExtent, fExtent, -fExtent);

	glTexCoord3f(-1.0f, 1.0f, 1.0f);
	glVertex3f(-fExtent, fExtent, fExtent);


	///////////////////////////////////////////////
	//  Postive X
	glTexCoord3f(1.0f, -1.0f, -1.0f);
	glVertex3f(fExtent, -fExtent, -fExtent);

	glTexCoord3f(1.0f, -1.0f, 1.0f);
	glVertex3f(fExtent, -fExtent, fExtent);

	glTexCoord3f(1.0f, 1.0f, 1.0f);
	glVertex3f(fExtent, fExtent, fExtent);

	glTexCoord3f(1.0f, 1.0f, -1.0f);
	glVertex3f(fExtent, fExtent, -fExtent);


	////////////////////////////////////////////////
	// Negative Z 
	glTexCoord3f(-1.0f, -1.0f, -1.0f);
	glVertex3f(-fExtent, -fExtent, -fExtent);

	glTexCoord3f(1.0f, -1.0f, -1.0f);
	glVertex3f(fExtent, -fExtent, -fExtent);

	glTexCoord3f(1.0f, 1.0f, -1.0f);
	glVertex3f(fExtent, fExtent, -fExtent);

	glTexCoord3f(-1.0f, 1.0f, -1.0f);
	glVertex3f(-fExtent, fExtent, -fExtent);


	////////////////////////////////////////////////
	// Positive Z 
	glTexCoord3f(1.0f, -1.0f, 1.0f);
	glVertex3f(fExtent, -fExtent, fExtent);

	glTexCoord3f(-1.0f, -1.0f, 1.0f);
	glVertex3f(-fExtent, -fExtent, fExtent);

	glTexCoord3f(-1.0f, 1.0f, 1.0f);
	glVertex3f(-fExtent, fExtent, fExtent);

	glTexCoord3f(1.0f, 1.0f, 1.0f);
	glVertex3f(fExtent, fExtent, fExtent);


	//////////////////////////////////////////////////
	// Positive Y
	glTexCoord3f(-1.0f, 1.0f, 1.0f);
	glVertex3f(-fExtent, fExtent, fExtent);

	glTexCoord3f(-1.0f, 1.0f, -1.0f);
	glVertex3f(-fExtent, fExtent, -fExtent);

	glTexCoord3f(1.0f, 1.0f, -1.0f);
	glVertex3f(fExtent, fExtent, -fExtent);

	glTexCoord3f(1.0f, 1.0f, 1.0f);
	glVertex3f(fExtent, fExtent, fExtent);


	///////////////////////////////////////////////////
	// Negative Y
	glTexCoord3f(-1.0f, -1.0f, -1.0f);
	glVertex3f(-fExtent, -fExtent, -fExtent);

	glTexCoord3f(-1.0f, -1.0f, 1.0f);
	glVertex3f(-fExtent, -fExtent, fExtent);

	glTexCoord3f(1.0f, -1.0f, 1.0f);
	glVertex3f(fExtent, -fExtent, fExtent);

	glTexCoord3f(1.0f, -1.0f, -1.0f);
	glVertex3f(fExtent, -fExtent, -fExtent);
	glEnd();

	glDisable(GL_TEXTURE_CUBE_MAP);
	// Sky Box is manually textured
	if(isTexGenEnabled[0])
	{
		glEnable(GL_TEXTURE_GEN_S);
	}
	if(isTexGenEnabled[1])
	{
		glEnable(GL_TEXTURE_GEN_T);
	}
	if(isTexGenEnabled[2])
	{
		glEnable(GL_TEXTURE_GEN_R);
	}
}
Exemple #17
0
//nbr_vertices: nombre de vertex du profile
//profile[]: tableau 2d contenant les vertex du profile relativement à l'axe de révolution
//angle: angle d'extension (360 correspond à un tour complet)
//nbr_sections: nombre de sections pour le mesh
void revolution(int nbr_vertices, GLfloat profile[], float angle, int nbr_sections) {

int s, v;
float theta1, theta2, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;

for(s=0; s<nbr_sections; s++) {

// incréments en rotation autour de y
theta1 = (s*1.0)*angle/nbr_sections*3.14/180;
theta2 = (s+1.0)*angle/nbr_sections*3.14/180;

// incréments lorsqu'on parcours le profil de bas en haut

for(v=0; v<nbr_vertices-1; v++) {
x1 = profile[v*2]*cos(theta1);
y1 = profile[v*2+1];
z1 = profile[v*2]*sin(theta1);

x2 = profile[v*2+2]*cos(theta1);
y2 = profile[v*2+3];
z2 = profile[v*2+2]*sin(theta1);

x3 = profile[v*2+2]*cos(theta2);
y3 = profile[v*2+3];
z3 = profile[v*2+2]*sin(theta2);

x4 = profile[v*2]*cos(theta2);
y4 = profile[v*2+1];
z4 = profile[v*2]*sin(theta2);

// calcul de la normale au plan par produit vectoriel

float v1x,v1y,v1z, // V1
      v2x,v2y,v2z, // V2
      nx,ny,nz;    // normale à la face

v1x = x2 - x1;
v1y = y2 - y1;
v1z = z2 - z1;

v2x = x3 - x2;
v2y = y3 - y2;
v2z = z3 - z2;

nx = (v1y * v2z) - (v1z * v2y);
ny = (v1z * v2x) - (v1x * v2z);
nz = (v1x * v2y) - (v1y * v2x);


nx /= sqrt(pow(nx,2)+pow(ny,2)+pow(nz,2));
ny /= sqrt(pow(nx,2)+pow(ny,2)+pow(nz,2));
nz /= sqrt(pow(nx,2)+pow(ny,2)+pow(nz,2));

// Affichage de la face avec les normales associées à chaque sommet
glBegin(GL_POLYGON);
glNormal3f(nx,ny,nz); 
glVertex3f(x1,y1,z1);
glNormal3f(nx,ny,nz); 
glVertex3f(x2,y2,z2);
glNormal3f(nx,ny,nz); 
glVertex3f(x3,y3,z3);
glNormal3f(nx,ny,nz); 
glVertex3f(x4,y4,z4);
glEnd();

}
}
}
Exemple #18
0
//client draw callback
gboolean drawCallback (GLuint texture, GLuint width, GLuint height)
{
    static GLfloat	xrot = 0;
    static GLfloat	yrot = 0;
    static GLfloat	zrot = 0;
    static GTimeVal current_time;
    static glong last_sec = current_time.tv_sec;
    static gint nbFrames = 0;

    g_get_current_time (&current_time);
    nbFrames++ ;

    if ((current_time.tv_sec - last_sec) >= 1)
    {
        std::cout << "GRAPHIC FPS of the scene which contains the custom cube) = " << nbFrames << std::endl;
        nbFrames = 0;
        last_sec = current_time.tv_sec;
    }

    glEnable(GL_DEPTH_TEST);

    glEnable (GL_TEXTURE_RECTANGLE_ARB);
    glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
    glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0f,0.0f,-5.0f);

    glRotatef(xrot,1.0f,0.0f,0.0f);
    glRotatef(yrot,0.0f,1.0f,0.0f);
    glRotatef(zrot,0.0f,0.0f,1.0f);

    glBegin(GL_QUADS);
    // Front Face
    glTexCoord2f((gfloat)width, 0.0f);
    glVertex3f(-1.0f, -1.0f,  1.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f,  1.0f);
    glTexCoord2f(0.0f, (gfloat)height);
    glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f((gfloat)width, (gfloat)height);
    glVertex3f(-1.0f,  1.0f,  1.0f);
    // Back Face
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, (gfloat)height);
    glVertex3f(-1.0f,  1.0f, -1.0f);
    glTexCoord2f((gfloat)width, (gfloat)height);
    glVertex3f( 1.0f,  1.0f, -1.0f);
    glTexCoord2f((gfloat)width, 0.0f);
    glVertex3f( 1.0f, -1.0f, -1.0f);
    // Top Face
    glTexCoord2f((gfloat)width, (gfloat)height);
    glVertex3f(-1.0f,  1.0f, -1.0f);
    glTexCoord2f((gfloat)width, 0.0f);
    glVertex3f(-1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, (gfloat)height);
    glVertex3f( 1.0f,  1.0f, -1.0f);
    // Bottom Face
    glTexCoord2f((gfloat)width, 0.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, (gfloat)height);
    glVertex3f( 1.0f, -1.0f,  1.0f);
    glTexCoord2f((gfloat)width,(gfloat)height);
    glVertex3f(-1.0f, -1.0f,  1.0f);
    // Right face
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, (gfloat)height);
    glVertex3f( 1.0f,  1.0f, -1.0f);
    glTexCoord2f((gfloat)width, (gfloat)height);
    glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f((gfloat)width, 0.0f);
    glVertex3f( 1.0f, -1.0f,  1.0f);
    // Left Face
    glTexCoord2f((gfloat)width, 0.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f,  1.0f);
    glTexCoord2f(0.0f, (gfloat)height);
    glVertex3f(-1.0f,  1.0f,  1.0f);
    glTexCoord2f((gfloat)width, (gfloat)height);
    glVertex3f(-1.0f,  1.0f, -1.0f);
    glEnd();

    xrot+=0.03f;
    yrot+=0.02f;
    zrot+=0.04f;

    //return TRUE causes a postRedisplay
    //so you have to return FALSE to synchronise to have a graphic FPS
    //equals to the input video frame rate

    //Usually, we will not always return TRUE (or FALSE)
    //For example, if you want a fixed graphic FPS equals to 60
    //then you have to use the timeclock to return TRUE or FALSE
    //in order to increase or decrease the FPS in real time
    //to reach the 60.

    return TRUE;
}
Exemple #19
0
static int
draw_block(GLfloat width, GLfloat height, GLfloat thickness)
{
    int polys = 0;
	glFrontFace(GL_CCW);
	glBegin(GL_QUADS);
	glNormal3f(0, 0, 1);
	glTexCoord2f(0, 0);
	glVertex3f(-width, -height, thickness);
	glTexCoord2f(1, 0);
	glVertex3f(width, -height, thickness);
	glTexCoord2f(1, 1);
	glVertex3f(width, height, thickness);
	glTexCoord2f(0, 1);
	glVertex3f(-width, height, thickness);
    polys++;
	glNormal3f(0, 0, -1);
	glTexCoord2f(0, 0);
	glVertex3f(-width, height, -thickness);
	glTexCoord2f(1, 0);
	glVertex3f(width, height, -thickness);
	glTexCoord2f(1, 1);
	glVertex3f(width, -height, -thickness);
	glTexCoord2f(0, 1);
	glVertex3f(-width, -height, -thickness);
    polys++;
	glNormal3f(0, 1, 0);
	glTexCoord2f(0, 0);
	glVertex3f(-width, height, thickness);
	glTexCoord2f(1, 0);
	glVertex3f(width, height, thickness);
	glTexCoord2f(1, 1);
	glVertex3f(width, height, -thickness);
	glTexCoord2f(0, 1);
	glVertex3f(-width, height, -thickness);
    polys++;
	glNormal3f(0, -1, 0);
	glTexCoord2f(0, 0);
	glVertex3f(-width, -height, -thickness);
	glTexCoord2f(1, 0);
	glVertex3f(width, -height, -thickness);
	glTexCoord2f(1, 1);
	glVertex3f(width, -height, thickness);
	glTexCoord2f(0, 1);
	glVertex3f(-width, -height, thickness);
    polys++;
	glNormal3f(1, 0, 0);
	glTexCoord2f(0, 0);
	glVertex3f(width, -height, thickness);
	glTexCoord2f(1, 0);
	glVertex3f(width, -height, -thickness);
	glTexCoord2f(1, 1);
	glVertex3f(width, height, -thickness);
	glTexCoord2f(0, 1);
	glVertex3f(width, height, thickness);
    polys++;
	glNormal3f(-1, 0, 0);
	glTexCoord2f(0, 0);
	glVertex3f(-width, height, thickness);
	glTexCoord2f(1, 0);
	glVertex3f(-width, height, -thickness);
	glTexCoord2f(1, 1);
	glVertex3f(-width, -height, -thickness);
	glTexCoord2f(0, 1);
	glVertex3f(-width, -height, thickness);
    polys++;
	glEnd();
    return polys;
}
Exemple #20
0
static void draw_sim_debug_elements(SimDebugData *debug_data, float imat[4][4])
{
	GHashIterator iter;
	
	/**** dots ****/
	
	glPointSize(3.0f);
	glBegin(GL_POINTS);
	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
		SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
		if (elem->type != SIM_DEBUG_ELEM_DOT)
			continue;
		
		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
		glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
	}
	glEnd();
	
	/**** circles ****/
	
	{
		float circle[16][2] = {
		    {0.000000, 1.000000}, {0.382683, 0.923880}, {0.707107, 0.707107}, {0.923880, 0.382683},
		    {1.000000, -0.000000}, {0.923880, -0.382683}, {0.707107, -0.707107}, {0.382683, -0.923880},
		    {-0.000000, -1.000000}, {-0.382683, -0.923880}, {-0.707107, -0.707107}, {-0.923879, -0.382684},
		    {-1.000000, 0.000000}, {-0.923879, 0.382684}, {-0.707107, 0.707107}, {-0.382683, 0.923880} };
		for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
			SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
			float radius = elem->v2[0];
			float co[3];
			int i;
			
			if (elem->type != SIM_DEBUG_ELEM_CIRCLE)
				continue;
			
			glColor3f(elem->color[0], elem->color[1], elem->color[2]);
			glBegin(GL_LINE_LOOP);
			for (i = 0; i < 16; ++i) {
				co[0] = radius * circle[i][0];
				co[1] = radius * circle[i][1];
				co[2] = 0.0f;
				mul_mat3_m4_v3(imat, co);
				add_v3_v3(co, elem->v1);
				
				glVertex3f(co[0], co[1], co[2]);
			}
			glEnd();
		}
	}
	
	/**** lines ****/
	
	glBegin(GL_LINES);
	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
		SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
		if (elem->type != SIM_DEBUG_ELEM_LINE)
			continue;
		
		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
		glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
		glVertex3f(elem->v2[0], elem->v2[1], elem->v2[2]);
	}
	glEnd();
	
	/**** vectors ****/
	
	glPointSize(2.0f);
	glBegin(GL_POINTS);
	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
		SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
		if (elem->type != SIM_DEBUG_ELEM_VECTOR)
			continue;
		
		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
		glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
	}
	glEnd();
	
	glBegin(GL_LINES);
	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
		SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
		float t[3];
		if (elem->type != SIM_DEBUG_ELEM_VECTOR)
			continue;
		
		glColor3f(elem->color[0], elem->color[1], elem->color[2]);
		glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
		add_v3_v3v3(t, elem->v1, elem->v2);
		glVertex3f(t[0], t[1], t[2]);
	}
	glEnd();
	
	/**** strings ****/
	
	for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
		SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
		if (elem->type != SIM_DEBUG_ELEM_STRING)
			continue;
		
		unsigned char col[4];
		rgb_float_to_uchar(col, elem->color);
		col[3] = 255;
		view3d_cached_text_draw_add(elem->v1, elem->str, strlen(elem->str),
		                            0, V3D_CACHE_TEXT_GLOBALSPACE, col);
	}
}
Exemple #21
0
void GLCanvas::drawAABB(const AABB &box) const
{
    float minX = box.minX();
    float minY = box.minY();
    float minZ = box.minZ();

    float maxX = box.maxX();
    float maxY = box.maxY();
    float maxZ = box.maxZ();

    /* Uncomment if always a real cube shall be displayed
    const float delta = 0.002f;

    if (std::abs(maxX - minX) < 2.0f*delta)
    {
        minX -= delta;
        maxX += delta;
    }
    if (std::abs(maxY - minY) < delta)
    {
        minY -= delta;
        maxY += delta;
    }
    if (std::abs(maxZ - minZ) < delta)
    {
        minZ -= delta;
        maxZ += delta;
    }
    */

    glColor4ubv(white);

    glBegin(GL_LINES);
        glVertex3f(minX, minY, minZ);
        glVertex3f(maxX, minY, minZ);

        glVertex3f(minX, minY, minZ);
        glVertex3f(minX, maxY, minZ);

        glVertex3f(minX, minY, minZ);
        glVertex3f(minX, minY, maxZ);

        glVertex3f(maxX, maxY, maxZ);
        glVertex3f(minX, maxY, maxZ);

        glVertex3f(maxX, maxY, maxZ);
        glVertex3f(maxX, minY, maxZ);

        glVertex3f(maxX, maxY, maxZ);
        glVertex3f(maxX, maxY, minZ);

        glVertex3f(maxX, minY, minZ);
        glVertex3f(maxX, maxY, minZ);

        glVertex3f(maxX, minY, minZ);
        glVertex3f(maxX, minY, maxZ);

        glVertex3f(minX, maxY, minZ);
        glVertex3f(maxX, maxY, minZ);

        glVertex3f(minX, maxY, minZ);
        glVertex3f(minX, maxY, maxZ);

        glVertex3f(minX, minY, maxZ);
        glVertex3f(maxX, minY, maxZ);

        glVertex3f(minX, minY, maxZ);
        glVertex3f(minX, maxY, maxZ);
    glEnd();
}
Exemple #22
0
void GLWidget::drawCoordinateCross(void)
{
    GLint   viewport[4];

    glMatrixMode (GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode (GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glGetIntegerv (GL_VIEWPORT, viewport);

    glTranslatef (-1, -1, 0.0);
    glScalef (40.0 / viewport[2], 40.0 / viewport[3], 1);
    glTranslatef (1.25, 1.25, 0.0);

    glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
    glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
    glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);

    glEnable (GL_COLOR_MATERIAL);
    glDisable (GL_LIGHTING);

    glLineWidth (1.0f);

    glBegin(GL_LINES);
    glColor3f(1,0,0);
    glVertex3f (0.0f, 0.0f, 0.0f);
    glVertex3f (0.9, 0.0f, 0.0f);
    glColor3f(0,1,0);
    glVertex3f (0.0f, 0.0f, 0.0f);
    glVertex3f (0.0f, 0.9, 0.0f);
    glColor3f(0,0,1);
    glVertex3f (0.0f, 0.0f, 0.0f);
    glVertex3f (0.0f, 0.0f, 0.9);
    glEnd ();

    glColor3f(1,0,0);
    glPushMatrix();
    glTranslatef(0.5,0,0);
    glRotatef(90,0,1,0);
    gluCylinder(row,0.1,0,0.4,10,10);
    glPopMatrix();

    glColor3f(0,1,0);
    glPushMatrix();
    glTranslatef(0,0.5,0);
    glRotatef(-90,1,0,0);
    gluCylinder(row,0.1,0,0.4,10,10);
    glPopMatrix();

    glColor3f(0,0,1);
    glPushMatrix();
    glTranslatef(0,0,0.5);
    gluCylinder(row,0.1,0,0.4,10,10);
    glPopMatrix();

    glColor3f(1,0,0);
    draw2DText(1.1, 0.0, 0.0, (char*)"X");

    glColor3f(0,1,0);
    draw2DText(0.1, 1.0, 0.0, (char*)"Y");

    glColor3f(0,0,1);
    draw2DText(0.1, 0.0, 1.0, (char*)"Z");

    glEnable(GL_LIGHTING);
    glDisable (GL_COLOR_MATERIAL);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
}
void drawQuad(void)
{
    glBegin(GL_QUADS);

    /* Front */
    glNormal3f(0.0f, 0.0f, 1.0f);
    glVertex3f(-QUADC, QUADC, QUADH);
    glVertex3f(-QUADC, -QUADC, QUADH);
    glVertex3f(QUADC, -QUADC, QUADH);
    glVertex3f(QUADC, QUADC, QUADH);

    /* Right */
    glNormal3f(1.0f, 0.0f, 0.0f);
    glVertex3f(QUADC, QUADC, QUADH);
    glVertex3f(QUADC, -QUADC, QUADH);
    glVertex3f(QUADC, -QUADC, -QUADH);
    glVertex3f(QUADC, QUADC, -QUADH);

    /* Rear */
/*
    glNormal3f(0.0f, 0.0f, -1.0f);
    glVertex3f(QUADC, QUADC, -QUADH);
    glVertex3f(QUADC, -QUADC, -QUADH);
    glVertex3f(-QUADC, -QUADC, -QUADH);
    glVertex3f(-QUADC, QUADC, -QUADH);
*/

    /* Left */
    glNormal3f(-1.0f, 0.0f, 0.0f);
    glVertex3f(-QUADC, QUADC, -QUADH);
    glVertex3f(-QUADC, -QUADC, -QUADH);
    glVertex3f(-QUADC, -QUADC, QUADH);
    glVertex3f(-QUADC, QUADC, QUADH);

    /* Top */
    glNormal3f(0.0f, 1.0f, 0.0f);
    glVertex3f(-QUADC, QUADC, -QUADH);
    glVertex3f(-QUADC, QUADC, QUADH);
    glVertex3f(QUADC, QUADC, QUADH);
    glVertex3f(QUADC, QUADC, -QUADH);

    /* Bottom */
    glNormal3f(0.0f, -1.0f, 0.0f);
    glVertex3f(QUADC, -QUADC, -QUADH);
    glVertex3f(QUADC, -QUADC, QUADH);
    glVertex3f(-QUADC, -QUADC, QUADH);
    glVertex3f(-QUADC, -QUADC, -QUADH);

    glEnd();
}
void D_PAD::Draw3D(Pcb3D_GLCanvas * glcanvas)
/***********************************************/
/* Dessin 3D des pads avec leur trou de percage
*/
{
int ii, ll, layer, nlmax;
int	ux0,uy0,
	dx,dx0,dy,dy0,
	delta_cx, delta_cy,
	xc, yc;
int angle, delta_angle;
int coord[4][2];
double fcoord[8][2], f_hole_coord[8][2];
float scale;
double zpos;
wxPoint shape_pos;
double x, y, r, w, hole;
double drillx, drilly;
bool Oncu, Oncmp, Both;
int color;

	scale = g_Parm_3D_Visu.m_BoardScale;
	hole = (double)m_Drill * scale / 2;

	/* calcul du centre des formes des pads : */
    shape_pos = ReturnShapePos();
	ux0 = shape_pos.x;
	uy0 = shape_pos.y;
	xc = ux0;
	yc = uy0;

	/* le trace depend de la rotation de l'empreinte */
	dx = dx0 = m_Size.x >> 1 ;
	dy = dy0 = m_Size.y >> 1 ; /* demi dim  dx et dy */

	angle = m_Orient;
	drillx = m_Pos.x  * scale;
	drilly = m_Pos.y * scale;
	/* trace du trou de percage */
	if ( m_Drill )
	{
		SetGLColor(DARKGRAY);
		Draw3D_FilledCylinder(drillx, -drilly, hole, g_Parm_3D_Visu.m_LayerZcoord[CMP_N], 0.0);
	}

 	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	nlmax = g_Parm_3D_Visu.m_Layers-1;
	Oncu = (m_Masque_Layer & CUIVRE_LAYER) ? TRUE : FALSE;
	Oncmp = (m_Masque_Layer & CMP_LAYER) ? TRUE : FALSE;
	Both = Oncu && Oncmp;
	switch (m_PadShape & 0x7F)
		{
		case CIRCLE :
			x = xc * scale;
			y = yc * scale;
			r = (double)dx * scale;
			for ( layer = CUIVRE_N; layer <= CMP_N; layer ++)
			{
				if (layer && (layer == nlmax) ) layer = CMP_N;
				if ( (layer == CMP_N) && ! Oncmp ) continue;
				if ( (layer == CUIVRE_N) && ! Oncu ) continue;
				if ( (layer > CUIVRE_N) && (layer < CMP_N) && !Both) continue;
				color = g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[layer];
				if ( color & ITEM_NOT_SHOW ) continue;
				SetGLColor(color);
				glNormal3f( 0.0, 0.0, (layer == CUIVRE_N) ? -1.0 : 1.0);
				zpos = g_Parm_3D_Visu.m_LayerZcoord[layer];
				Draw3D_FilledCircle(x, -y, r, hole, zpos);
			}
			break;

		case OVALE :
			/* calcul de l'entraxe de l'ellipse */
			if( dx > dy )	/* ellipse horizontale */
				{
				delta_cx = dx - dy; delta_cy = 0;
				w = m_Size.y * scale;
				delta_angle = angle+900;
				}
			else			/* ellipse verticale */
				{
				delta_cx = 0; delta_cy = dy - dx;
				w = m_Size.x * scale;
				delta_angle = angle;
				}
			RotatePoint(&delta_cx, &delta_cy, angle);
			{
			double ox, oy, fx, fy;
			ox = (double)(ux0 + delta_cx) * scale;
			oy = (double)(uy0 + delta_cy) * scale;
			fx = (double)(ux0 - delta_cx) * scale;
			fy = (double)(uy0 - delta_cy) * scale;
			for ( layer = CUIVRE_N; layer <= CMP_N; layer ++)
			{
				if (layer && (layer == nlmax) ) layer = CMP_N;
				if ( (layer == CMP_N) && ! Oncmp ) continue;
				if ( (layer == CUIVRE_N) && ! Oncu ) continue;
				if ( (layer > CUIVRE_N) && (layer < CMP_N) && !Both) continue;
				color = g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[layer];
				glNormal3f( 0.0, 0.0, (layer == CUIVRE_N) ? -1.0 : 1.0);
				if ( color & ITEM_NOT_SHOW ) continue;
				SetGLColor(color);
				zpos = g_Parm_3D_Visu.m_LayerZcoord[layer];
				Draw3D_FilledSegmentWithHole(ox, -oy, fx, -fy, w, drillx, -drilly, hole, zpos);
			}
			}
			break;

		case RECT :
		case SPECIAL_PAD:
		case TRAPEZE:
			{
			int ddx, ddy ;
			ddx = m_DeltaSize.x >> 1 ;
			ddy = m_DeltaSize.y >> 1 ; /* demi dim  dx et dy */

			 coord[0][0] = - dx - ddy;
			 coord[0][1] = + dy + ddx;

			 coord[1][0] = - dx + ddy;
			 coord[1][1] = - dy - ddx;

			 coord[2][0] = + dx - ddy;
			 coord[2][1] = - dy + ddx;

			 coord[3][0] = + dx + ddy;
			 coord[3][1] = + dy - ddx;

			for (ii = 0; ii < 4; ii++)
				{
				RotatePoint(&coord[ii][0],&coord[ii][1], angle);
				coord[ii][0] += ux0;
				coord[ii][1] += uy0;
				ll = ii*2;
				fcoord[ll][0] = coord[ii][0] * scale;
				fcoord[ll][1] = coord[ii][1] * scale;
				}
			for (ii = 0; ii < 7; ii+=2)
				{
				ll = ii+2; if (ll > 7) ll -= 8;
				fcoord[ii+1][0] = (fcoord[ii][0] + fcoord[ll][0])/2;
				fcoord[ii+1][1] = (fcoord[ii][1] + fcoord[ll][1])/2;
				}
			for (ii = 0; ii < 8; ii++)
				{
				f_hole_coord[ii][0] = -hole*0.707;
				f_hole_coord[ii][1] = hole*0.707;
				RotatePoint(&f_hole_coord[ii][0], &f_hole_coord[ii][1],
					angle -(ii * 450) );
				f_hole_coord[ii][0] += drillx;
				f_hole_coord[ii][1] += drilly;
				}

			for ( layer = CUIVRE_N; layer <= CMP_N; layer ++)
			{
				if (layer && (layer == nlmax) ) layer = CMP_N;
				if ( (layer == CMP_N) && ! Oncmp ) continue;
				if ( (layer == CUIVRE_N) && ! Oncu ) continue;
				if ( (layer > CUIVRE_N) && (layer < CMP_N) && !Both) continue;
				color = g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[layer];
				glNormal3f( 0.0, 0.0, (layer == CUIVRE_N) ? -1.0 : 1.0);
				if ( color & ITEM_NOT_SHOW ) continue;
				SetGLColor(color);
				zpos = g_Parm_3D_Visu.m_LayerZcoord[layer];
				glBegin(GL_QUAD_STRIP);
				for ( ii = 0; ii < 8; ii++ )
				{
					glVertex3f( f_hole_coord[ii][0], -f_hole_coord[ii][1] , zpos);
					glVertex3f( fcoord[ii][0], -fcoord[ii][1] , zpos);
				}
				glVertex3f( f_hole_coord[0][0], -f_hole_coord[0][1] , zpos);
				glVertex3f( fcoord[0][0], -fcoord[0][1] , zpos);
				glEnd();
			}
			break;

			default:
				break;
			}
		}

}
Exemple #25
0
void scene::compileSatelite()
{
    glNewList(satelite_id, GL_COMPILE);
    
    GLfloat dore[] = {1.f, 0.7843f, 0.f, 1.f};
    GLfloat bleu[] = {0.1960f, 0.3921f, 0.5490f, 1.f};
    GLfloat gris[] = {0.8f, 0.8f, 0.8f, 1.0f};
    GLfloat white[] = {1.f, 1.f, 1.f, 1.0f};
    GLfloat shininess[] = {50};
    
    glMaterialfv(GL_FRONT, GL_DIFFUSE, dore);
    glMaterialfv(GL_FRONT, GL_SPECULAR, gris);
    glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
    
    createPetitCube();
    
    glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
    
    glNormal3f(0.f, 0.f, -1.f);
    
    glBegin(GL_TRIANGLES);
    glVertex3f(0.1f, 0.f, 0.f);
    glVertex3f(0.15f, 0.1f, 0.f);
    glVertex3f(0.15f,  -0.1f, 0.f);
    glEnd();
    glBegin(GL_TRIANGLES);
    glVertex3f(-0.1f, 0.f, 0.f);
    glVertex3f(-0.15f,  -0.1f, 0.f);
    glVertex3f(-0.15f, 0.1f, 0.f);
    glEnd();
    
    glMaterialfv(GL_FRONT, GL_DIFFUSE, bleu);
    
    glBegin(GL_QUADS);
    glVertex3f(0.36f, 0.11f, 0.f);
    glVertex3f(0.16f, 0.11f, 0.f);
    glVertex3f(0.16f,  0.21f, 0.f);
    glVertex3f(0.36f,  0.21f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.36f, 0.005f, 0.f);
    glVertex3f(0.16f, 0.005f, 0.f);
    glVertex3f(0.16f,  0.10f, 0.f);
    glVertex3f(0.36f,  0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.16f, -0.005f, 0.f);
    glVertex3f(0.36f, -0.005f, 0.f);
    glVertex3f(0.36f,  -0.10f, 0.f);
    glVertex3f(0.16f,  -0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.16f, -0.11f, 0.f);
    glVertex3f(0.36f, -0.11f, 0.f);
    glVertex3f(0.36f, -0.21f, 0.f);
    glVertex3f(0.16f, -0.21f, 0.f);
    glEnd();
    
    glBegin(GL_QUADS);
    glVertex3f(-0.16f, 0.11f, 0.f);
    glVertex3f(-0.36f, 0.11f, 0.f);
    glVertex3f(-0.36f,  0.21f, 0.f);
    glVertex3f(-0.16f,  0.21f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.16f, 0.005f, 0.f);
    glVertex3f(-0.36f, 0.005f, 0.f);
    glVertex3f(-0.36f,  0.10f, 0.f);
    glVertex3f(-0.16f,  0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.36f, -0.005f, 0.f);
    glVertex3f(-0.16f, -0.005f, 0.f);
    glVertex3f(-0.16f,  -0.10f, 0.f);
    glVertex3f(-0.36f,  -0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.36f, -0.11f, 0.f);
    glVertex3f(-0.16f, -0.11f, 0.f);
    glVertex3f(-0.16f, -0.21f, 0.f);
    glVertex3f(-0.36f, -0.21f, 0.f);
    glEnd();
    
    glNormal3f(0.f, 0.f, 1.f);
    
    glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
    
    glBegin(GL_TRIANGLES);
    glVertex3f(0.1f, 0.f, 0.f);
    glVertex3f(0.15f,  -0.1f, 0.f);
    glVertex3f(0.15f, 0.1f, 0.f);
    glEnd();
    glBegin(GL_TRIANGLES);
    glVertex3f(-0.1f, 0.f, 0.f);
    glVertex3f(-0.15f, 0.1f, 0.f);
    glVertex3f(-0.15f,  -0.1f, 0.f);
    glEnd();
    
    glMaterialfv(GL_FRONT, GL_DIFFUSE, bleu);
    
    glBegin(GL_QUADS);
    glVertex3f(0.16f, 0.11f, 0.f);
    glVertex3f(0.36f, 0.11f, 0.f);
    glVertex3f(0.36f,  0.21f, 0.f);
    glVertex3f(0.16f,  0.21f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.16f, 0.005f, 0.f);
    glVertex3f(0.36f, 0.005f, 0.f);
    glVertex3f(0.36f,  0.10f, 0.f);
    glVertex3f(0.16f,  0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.36f, -0.005f, 0.f);
    glVertex3f(0.16f, -0.005f, 0.f);
    glVertex3f(0.16f,  -0.10f, 0.f);
    glVertex3f(0.36f,  -0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(0.36f, -0.11f, 0.f);
    glVertex3f(0.16f, -0.11f, 0.f);
    glVertex3f(0.16f, -0.21f, 0.f);
    glVertex3f(0.36f, -0.21f, 0.f);
    glEnd();
    
    glBegin(GL_QUADS);
    glVertex3f(-0.36f, 0.11f, 0.f);
    glVertex3f(-0.16f, 0.11f, 0.f);
    glVertex3f(-0.16f,  0.21f, 0.f);
    glVertex3f(-0.36f,  0.21f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.36f, 0.005f, 0.f);
    glVertex3f(-0.16f, 0.005f, 0.f);
    glVertex3f(-0.16f,  0.10f, 0.f);
    glVertex3f(-0.36f,  0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.16f, -0.005f, 0.f);
    glVertex3f(-0.36f, -0.005f, 0.f);
    glVertex3f(-0.36f,  -0.10f, 0.f);
    glVertex3f(-0.16f,  -0.10f, 0.f);
    glEnd();
    glBegin(GL_QUADS);
    glVertex3f(-0.16f, -0.11f, 0.f);
    glVertex3f(-0.36f, -0.11f, 0.f);
    glVertex3f(-0.36f, -0.21f, 0.f);
    glVertex3f(-0.16f, -0.21f, 0.f);
    glEnd();
    

    
    glEndList();
}
static void Draw3D_FilledSegmentWithHole(double startx, double starty,
				double endx, double endy,double width,
				double holex, double holey, double holeradius, double zpos)
/*****************************************************************/
/* trace un polygone semblable a un segment a bouts ronds avec trou
*/
{
double x, y, xin, yin;
double firstx=0, firsty=0, firstxin=0, firstyin=0;
int ii, angle, theta;

	/* on va calculer les coordonnées du segment supposé horizontal,
	puis tourner les  cordonnes de l'angle voulu
	Tous des calculs se font avec startx, starty comme origine du tracé */

	endx -= startx; endy -= starty;
	holex -= startx; holey -= starty;
	angle = (int)(( atan2( endy, endx ) / M_PI * 1800)+0.5) ;

	RotatePoint(&endx, &endy, angle);	// apres rotation: endx = longueur du segment
									// endy = 0;
	RotatePoint(&holex, &holey, angle);
	width /= 2;

	glBegin(GL_QUAD_STRIP);
	// tracé de l'arrondi a droite (1er demi polygone a la fin du segment)
	// autour du demi-trou de percage
	for ( ii = 0; ii <= 8; ii++ )
	{
		x = 0.0; y = -width;
		xin = 0.0; yin = - holeradius;
		theta = -ii * 225;
		RotatePoint(&x, &y, theta);
		RotatePoint(&xin, &yin, theta);
		x += endx;
		RotatePoint(&x, &y, -angle);
		xin += holex;
		RotatePoint(&xin, &yin, -angle);
		glVertex3f( startx + xin, starty+yin, zpos);
		glVertex3f( startx + x, starty+y, zpos);
		if ( ii == 0 )	// Memorisation du point de départ du tracé
		{
			firstx = startx + x;
			firsty = starty + y;
			firstxin = startx + xin;
			firstyin = starty + yin;
		}
	}
	// tracé de l'arrondi a gauche (2ieme demi polygone a l'origine du segment)
	for ( ii = 0; ii <= 8; ii++ )
	{
		theta = - ii * 225;
		x = 0.0; y = width;
		RotatePoint(&x, &y, -angle + theta);
		xin = 0.0; yin = holeradius;
		RotatePoint(&xin, &yin, theta);
		xin += holex;
		RotatePoint(&xin, &yin, -angle);
		glVertex3f( startx + xin,starty + yin, zpos);
		glVertex3f( startx + x, starty + y, zpos);
	}

	glVertex3f( firstxin, firstyin, zpos);
	glVertex3f( firstx, firsty, zpos);
	glEnd();
}
Exemple #27
0
/*
** Function called to update rendering
*/
void		DisplayFunc (void)
{
  const float t = glutGet (GLUT_ELAPSED_TIME) / 1000.;
  const float delta = 2. / RESOLUTION;
  const unsigned int length = 2 * (RESOLUTION + 1);
  const float xn = (RESOLUTION + 1) * delta + 1;
  unsigned int i;
  unsigned int j;
  float x;
  float y;
  unsigned int indice;
  unsigned int preindice;

  /* Yes, I know, this is quite ugly... */
  float v1x;
  float v1y;
  float v1z;

  float v2x;
  float v2y;
  float v2z;

  float v3x;
  float v3y;
  float v3z;

  float vax;
  float vay;
  float vaz;

  float vbx;
  float vby;
  float vbz;

  float nx;
  float ny;
  float nz;

  float l;


  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glLoadIdentity ();
  glTranslatef (0, 0, -translate_z);
  glRotatef (rotate_y, 1, 0, 0);
  glRotatef (rotate_x, 0, 1, 0);

  /* Vertices */
  for (j = 0; j < RESOLUTION; j++)
    {
      y = (j + 1) * delta - 1;
      for (i = 0; i <= RESOLUTION; i++)
	{
	  indice = 6 * (i + j * (RESOLUTION + 1));

	  x = i * delta - 1;
	  surface[indice + 3] = x;
	  surface[indice + 4] = z (x, y, t);
	  surface[indice + 5] = y;
	  if (j != 0)
	    {
	      /* Values were computed during the previous loop */
	      preindice = 6 * (i + (j - 1) * (RESOLUTION + 1));
	      surface[indice] = surface[preindice + 3];
	      surface[indice + 1] = surface[preindice + 4];
	      surface[indice + 2] = surface[preindice + 5];
	    }
	  else
	    {
	      surface[indice] = x;
	      surface[indice + 1] = z (x, -1, t);
	      surface[indice + 2] = -1;
	    }
	}
    }

  /* Normals */
  for (j = 0; j < RESOLUTION; j++)
    for (i = 0; i <= RESOLUTION; i++)
      {
	indice = 6 * (i + j * (RESOLUTION + 1));

	v1x = surface[indice + 3];
	v1y = surface[indice + 4];
	v1z = surface[indice + 5];

	v2x = v1x;
	v2y = surface[indice + 1];
	v2z = surface[indice + 2];

	if (i < RESOLUTION)
	  {
	    v3x = surface[indice + 9];
	    v3y = surface[indice + 10];
	    v3z = v1z;
	  }
	else
	  {
	    v3x = xn;
	    v3y = z (xn, v1z, t);
	    v3z = v1z;
	  }

	vax =  v2x - v1x;
	vay =  v2y - v1y;
	vaz =  v2z - v1z;

	vbx = v3x - v1x;
	vby = v3y - v1y;
	vbz = v3z - v1z;

	nx = (vby * vaz) - (vbz * vay);
	ny = (vbz * vax) - (vbx * vaz);
	nz = (vbx * vay) - (vby * vax);

	l = sqrtf (nx * nx + ny * ny + nz * nz);
	if (l != 0)
	  {
	    l = 1 / l;
	    normal[indice + 3] = nx * l;
	    normal[indice + 4] = ny * l;
	    normal[indice + 5] = nz * l;
	  }
	else
	  {
	    normal[indice + 3] = 0;
	    normal[indice + 4] = 1;
	    normal[indice + 5] = 0;
	  }


	if (j != 0)
	  {
	    /* Values were computed during the previous loop */
	    preindice = 6 * (i + (j - 1) * (RESOLUTION + 1));
	    normal[indice] = normal[preindice + 3];
	    normal[indice + 1] = normal[preindice + 4];
	    normal[indice + 2] = normal[preindice + 5];
	  }
	else
	  {
/* 	    v1x = v1x; */
	    v1y = z (v1x, (j - 1) * delta - 1, t);
	    v1z = (j - 1) * delta - 1;

/* 	    v3x = v3x; */
	    v3y = z (v3x, v2z, t);
	    v3z = v2z;

	    vax = v1x - v2x;
	    vay = v1y - v2y;
	    vaz = v1z - v2z;

	    vbx = v3x - v2x;
	    vby = v3y - v2y;
	    vbz = v3z - v2z;

	    nx = (vby * vaz) - (vbz * vay);
	    ny = (vbz * vax) - (vbx * vaz);
	    nz = (vbx * vay) - (vby * vax);

	    l = sqrtf (nx * nx + ny * ny + nz * nz);
	    if (l != 0)
	      {
		l = 1 / l;
		normal[indice] = nx * l;
		normal[indice + 1] = ny * l;
		normal[indice + 2] = nz * l;
	      }
	    else
	      {
		normal[indice] = 0;
		normal[indice + 1] = 1;
		normal[indice + 2] = 0;
	      }
	  }
      }

  /* The ground */
  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  glDisable (GL_TEXTURE_2D);
  glColor3f (1, 0.9, 0.7);
  glBegin (GL_TRIANGLE_FAN);
  glVertex3f (-1, 0, -1);
  glVertex3f (-1, 0,  1);
  glVertex3f ( 1, 0,  1);
  glVertex3f ( 1, 0, -1);
  glEnd ();

  glTranslatef (0, 0.2, 0);

  /* Render wireframe? */
  if (wire_frame != 0)
    glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);

  /* The water */
  glEnable (GL_TEXTURE_2D);
  glColor3f (1, 1, 1);
  glEnableClientState (GL_NORMAL_ARRAY);
  glEnableClientState (GL_VERTEX_ARRAY);
  glNormalPointer (GL_FLOAT, 0, normal);
  glVertexPointer (3, GL_FLOAT, 0, surface);
  for (i = 0; i < RESOLUTION; i++)
    glDrawArrays (GL_TRIANGLE_STRIP, i * length, length);

  /* Draw normals? */
  if (normals != 0)
    {
      glDisable (GL_TEXTURE_2D);
      glColor3f (1, 0, 0);
      glBegin (GL_LINES);
      for (j = 0; j < RESOLUTION; j++)
	for (i = 0; i <= RESOLUTION; i++)
	  {
	    indice = 6 * (i + j * (RESOLUTION + 1));
	    glVertex3fv (&(surface[indice]));
	    glVertex3f (surface[indice] + normal[indice] / 50,
			surface[indice + 1] + normal[indice + 1] / 50,
			surface[indice + 2] + normal[indice + 2] / 50);
	  }

      glEnd ();
    }

  /* End */
  glFlush ();
  glutSwapBuffers ();
  glutPostRedisplay ();
}
GLuint Pcb3D_GLCanvas::CreateDrawGL_List(void)
/**********************************************/
/* Creation de la liste des elements a afficher
*/
{
GLuint gllist = glGenLists( 1 );
WinEDA_BasePcbFrame * pcbframe = m_Parent->m_Parent;
BOARD * pcb = pcbframe->m_Pcb;
TRACK * pt_piste;
int ii;

	wxBusyCursor dummy;

	pcb->ComputeBoundaryBox();
	g_Parm_3D_Visu.m_BoardSettings = pcb->m_BoardSettings;
	g_Parm_3D_Visu.m_BoardSize = pcb->m_BoundaryBox.GetSize();
	g_Parm_3D_Visu.m_BoardPos = pcb->m_BoundaryBox.Centre();
	g_Parm_3D_Visu.m_BoardPos.y = - g_Parm_3D_Visu.m_BoardPos.y;
	g_Parm_3D_Visu.m_Layers = pcb->m_BoardSettings->m_CopperLayerCount;
	g_Parm_3D_Visu.m_BoardScale = 2.0 / MAX(g_Parm_3D_Visu.m_BoardSize.x, g_Parm_3D_Visu.m_BoardSize.y);
	float epoxy_width = 1.6;	// epoxy width in mm
	g_Parm_3D_Visu.m_Epoxy_Width = epoxy_width/2.54 * 1000
				* g_Parm_3D_Visu.m_BoardScale;

	/* calcul de l'altitude de chaque couche */
	for ( ii = 0; ii < 32; ii++ )
	{
		if ( ii < g_Parm_3D_Visu.m_Layers )
			g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width * ii
				/ (g_Parm_3D_Visu.m_Layers-1);
		else g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width;
	}
	GLfloat zpos_cu =  500 * g_Parm_3D_Visu.m_BoardScale;
	GLfloat zpos_cmp = g_Parm_3D_Visu.m_Epoxy_Width + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[ADHESIVE_N_CU] = -zpos_cu*2;
	g_Parm_3D_Visu.m_LayerZcoord[ADHESIVE_N_CMP] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[SILKSCREEN_N_CU] = -zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[SILKSCREEN_N_CMP] = zpos_cmp;
	g_Parm_3D_Visu.m_LayerZcoord[DRAW_N] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[COMMENT_N] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[ECO1_N] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[ECO2_N] = zpos_cmp + zpos_cu;

	glNewList( gllist, GL_COMPILE_AND_EXECUTE );

    glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);

	/* draw axes*/
	glEnable(GL_COLOR_MATERIAL);
	SetGLColor(WHITE);
    glBegin(GL_LINES);
 	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	glVertex3f( 0.0 , 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0);	// X axis
	glVertex3f( 0.0 , 0.0, 0.0); glVertex3f(0.0, -1.0, 0.0);	// y axis
 	glNormal3f( 1.0, 0.0, 0.0);	// Normal is Y axis
	glVertex3f( 0.0 , 0.0, 0.0); glVertex3f(0.0, 0.0, 0.3);	// z axis
    glEnd();

	/* Draw epoxy limits (do not use, works and test in progress)*/
#if 0
glEnable(GL_FOG);
	GLfloat param;
//	param = GL_LINEAR; glFogfv(GL_FOG_MODE,& param);
	param = 0.2; glFogfv(GL_FOG_DENSITY,& param);
	param = g_Parm_3D_Visu.m_LayerZcoord[15]; glFogfv(GL_FOG_END,& param);
	glBegin(GL_QUADS);
	SetGLColor(g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[CMP_N]);
	double sx = DataScale3D * g_Parm_3D_Visu.m_BoardSize.x / 2;
	double sy = DataScale3D * g_Parm_3D_Visu.m_BoardSize.y / 2;
	double zpos = g_Parm_3D_Visu.m_LayerZcoord[15];
	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	sx = sy = 0.5;
	glVertex3f( -sx, -sy , zpos);
	glVertex3f( -sx, sy , zpos);
	glVertex3f( sx, sy , zpos);
	glVertex3f( sx, -sy , zpos);
	glEnd();
	glBegin(GL_QUADS);
	SetGLColor(g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[CUIVRE_N]);
	glNormal3f( 0.0, 0.0, -1.0);	// Normal is -Z axis
	glVertex3f( -sx, -sy , 0);
	glVertex3f( -sx, sy , 0);
	glVertex3f( sx, sy , 0);
	glVertex3f( sx, -sy , 0);
	glEnd();
#endif

	/* Translation du tracé du BOARD pour placer son centre en 0, 0 */
    glTranslatef(-g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BoardScale,
			-g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BoardScale,
			0.0F);

 	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	/* Tracé des pistes : */
	for (pt_piste = pcb->m_Track ; pt_piste != NULL ; pt_piste = (TRACK*) pt_piste->Pnext )
		{
		if ( pt_piste->m_StructType == TYPEVIA )
			Draw3D_Via((SEGVIA*)pt_piste);
		else Draw3D_Track( pt_piste);
		}

	/* Tracé des edges */
EDA_BaseStruct * PtStruct;
	for ( PtStruct = pcb->m_Drawings; PtStruct != NULL; PtStruct = PtStruct->Pnext)
	{
		#define STRUCT ((DRAWSEGMENT *) PtStruct)
		if( PtStruct->m_StructType != TYPEDRAWSEGMENT ) continue;
		Draw3D_DrawSegment(STRUCT);
	}

	/* tracé des modules */
MODULE * Module = (MODULE*) pcb->m_Modules;
	for ( ; Module != NULL; Module = (MODULE *) Module->Pnext )
	{
		Module->Draw3D(this);
	}
    glEndList();

	/* Test for errors */
	GLenum err = glGetError();
	if ( err != GL_NO_ERROR )
		DisplayError(this, wxT("Error in GL commands") );
	return gllist;
}
Exemple #29
0
void
drawEnv(void)
{
    int i;

    glBegin(GL_LINES);
    for (i = - WORLD_SIDE; i < WORLD_SIDE; i++) {
        if (i % 2 == 0)
            glColor3f(1.0f, 1.0f, 1.0f);
        else
            glColor3f(0.5f, 0.5f, 0.5f);
        glVertex3f(i,           0,  WORLD_SIDE);
        glVertex3f(i,           0, -WORLD_SIDE);
        glVertex3f( WORLD_SIDE, 0,           i);
        glVertex3f(-WORLD_SIDE, 0,           i);
    }
    glEnd();

    glBegin(GL_QUADS);
    glColor3f(1.0f, 0.0f, 0.0f);
    glNormal3f(0,0,1);
    glVertex3f(-WORLD_SIDE, WORLD_SIDE, -WORLD_SIDE);
    glVertex3f( WORLD_SIDE, WORLD_SIDE, -WORLD_SIDE);
    glVertex3f( WORLD_SIDE,          0, -WORLD_SIDE);
    glVertex3f(-WORLD_SIDE,          0, -WORLD_SIDE);
    glColor3f(0.3f, 1.0f, 0.3f);
    glNormal3f(1,0,0);
    glVertex3f(-WORLD_SIDE, WORLD_SIDE, -WORLD_SIDE);
    glVertex3f(-WORLD_SIDE, WORLD_SIDE,  WORLD_SIDE);
    glVertex3f(-WORLD_SIDE,          0,  WORLD_SIDE);
    glVertex3f(-WORLD_SIDE,          0, -WORLD_SIDE);
    glColor3f(0.3f, 0.3f, 1.0f);
    glNormal3f(0,0,-1);
    glVertex3f(-WORLD_SIDE, WORLD_SIDE, WORLD_SIDE);
    glVertex3f(-WORLD_SIDE,          0, WORLD_SIDE);
    glVertex3f( WORLD_SIDE,          0, WORLD_SIDE);
    glVertex3f( WORLD_SIDE, WORLD_SIDE, WORLD_SIDE);
    glColor3f(1.0f, 0.3f, 1.0f);
    glNormal3f(-1,0,0);
    glVertex3f(WORLD_SIDE, WORLD_SIDE,  WORLD_SIDE);
    glVertex3f(WORLD_SIDE, WORLD_SIDE, -WORLD_SIDE);
    glVertex3f(WORLD_SIDE,          0, -WORLD_SIDE);
    glVertex3f(WORLD_SIDE,          0,  WORLD_SIDE);
    glEnd();
}
void CZClip::Paint( void ) {
	float	x, y;
	int	xCam = z.width / 4;	// hmmm, a rather unpleasant and obscure global name, but it was already called that so...
	GL_Color( ZCLIP_COLOUR ); //1.0, 0.0, 1.0);
	// draw TOP marker...
	//
	x = 0;
	y = m_iZClipTop;
	if( m_bEnabled ) {
		glBegin( GL_QUADS );
	} else {
		glBegin( GL_LINE_LOOP );
	}
	glVertex3f( x - xCam, y, 0 );
	glVertex3f( x - xCam, y + ZCLIP_BAR_THICKNESS, 0 );
	glVertex3f( x + xCam, y + ZCLIP_BAR_THICKNESS, 0 );
	glVertex3f( x + xCam, y, 0 );
	glEnd();
	GL_Color( ZCLIP_COLOUR_DIM ); //0.8, 0.0, 0.8);
	if( m_bEnabled ) {
		glBegin( GL_TRIANGLES );
	} else {
		glBegin( GL_LINE_LOOP );
	}
	glVertex3f( x, ( y + ZCLIP_BAR_THICKNESS ), 0 );
	glVertex3f( x - xCam, ( y + ZCLIP_BAR_THICKNESS ) + ( ZCLIP_ARROWHEIGHT / 2 ), 0 );
	glVertex3f( x + xCam, ( y + ZCLIP_BAR_THICKNESS ) + ( ZCLIP_ARROWHEIGHT / 2 ), 0 );
	glEnd();
	// draw bottom marker...
	//
	GL_Color( ZCLIP_COLOUR ); //1.0, 0.0, 1.0);
	x = 0;
	y = m_iZClipBottom;
	if( m_bEnabled ) {
		glBegin( GL_QUADS );
	} else {
		glBegin( GL_LINE_LOOP );
	}
	glVertex3f( x - xCam, y, 0 );
	glVertex3f( x - xCam, y - ZCLIP_BAR_THICKNESS, 0 );
	glVertex3f( x + xCam, y - ZCLIP_BAR_THICKNESS, 0 );
	glVertex3f( x + xCam, y, 0 );
	glEnd();
	GL_Color( ZCLIP_COLOUR_DIM ); //0.8, 0.0, 0.8);
	if( m_bEnabled ) {
		glBegin( GL_TRIANGLES );
	} else {
		glBegin( GL_LINE_LOOP );
	}
	glVertex3f( x, ( y - ZCLIP_BAR_THICKNESS ), 0 );
	glVertex3f( x - xCam, ( y - ZCLIP_BAR_THICKNESS ) - ( ZCLIP_ARROWHEIGHT / 2 ), 0 );
	glVertex3f( x + xCam, ( y - ZCLIP_BAR_THICKNESS ) - ( ZCLIP_ARROWHEIGHT / 2 ), 0 );
	glEnd();
}