Posting code problem


Tweet
(Posted 6 months ago) Blitzman

Hi guys how do i post code.cut and paste does not like it.

(Posted 6 months ago) RonTek commented:

Hey Blitzman, here's the template for code posting

https://www.blitzcoder.org/forum/topic.php?id=397

Just select and copy all in the code box, paste it and modify the source as intended. Hope this helps.

(Posted 6 months ago) Blitzman commented:
'' Just a snippet BlitzMax Vanilla

Import BRL.GLGraphics
Import BRL.GLMax2D

Global ScreenWidth:Int=800
Global ScreenHeight:Int=600
Global ScreenDepth:Int=0

Global angle:Float = 0.0
Global legAngle:Float[] = [0.0, 0.0]
Global armAngle:Float[] = [0.0, 0.0]

Global arm1=True
Global arm2=False
Global leg1=True
Global leg2=False

GLGraphics (ScreenWidth,ScreenHeight,ScreenDepth,60)

Start_Gl()

'MAIN

Repeat

    Render()

    Flip

Until KeyHit (KEY_ESCAPE) Or AppTerminate()

End 

'END MAIN

Function Start_Gl()
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glClearDepth 1.0
    glDepthFunc(GL_LESS)
    glEnable(GL_DEPTH_TEST)
    glShadeModel(GL_SMOOTH)
    glViewport(0,0,ScreenWidth,ScreenHeight)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45.0,1.3333,1.0,1000.0)
    glMatrixMode(GL_MODELVIEW)
End Function

Function Render()

        'Heres our rendering.
        'clear the Color And depth
        'buffers, And reset our modelview matrix.

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        'Increase rotation angle counter

        angle = angle + 1.0

        'Reset after we have completed a circle

        If angle >= 360.0 Then

                angle = 0.0
        EndIf

        glPushMatrix()

                glLoadIdentity()

                'Move To 0,0,-30 , rotate the robot on
                'its y axis, draw the robot, And dispose
                'of the current matrix.

                glTranslatef(0.0, 0.0, -30.0)
                glRotatef(angle, 0.0, 1.0, 0.0)

                DrawRobot(0.0, 0.0, 0.0)

        glPopMatrix()

        glFlush()

End Function

Function DrawRobot(xPos:Float, yPos:Float, zPos:Float)

    'Variables For state of robots legs. True
    'means the leg is forward, And False means
    'the leg is back. The same applies To the
    'robots arm states.

        glPushMatrix()

                'This will draw our robot at the
                'desired coordinates.

                glTranslatef(xPos, yPos, zPos)

                'These three lines will draw the
                'various components of our robot.

                DrawHead(1.0, 2.0, 0.0)
                DrawTorso(1.5, 0.0, 0.0)
                glPushMatrix()

                'If the arm is moving forward we will increase
                'the angle; otherwise, we will decrease the
                'angle.

                If arm1

                        armAngle[0] = armAngle[0] + 1.0

                Else

                        armAngle[0] = armAngle[0] - 1.0

          EndIf

                'Once the arm has reached its Max angle
                'in one direction, we want it To reverse
                'And change direction.

                If armAngle[0] >= 15.0 Then

                        arm1 = False

                EndIf

                If armAngle[0] <= -15.0 Then

                        arm1 = True

          EndIf                


                'Here we are going To move the arm away
                'from the torso And rotate. This will
                'Create a walking effect.

                glTranslatef(0.0, -0.5, 0.0)
                glRotatef(armAngle[0], 1.0, 0.0, 0.0)

                DrawArm(2.5, 0.0, -0.5)

        glPopMatrix()

        glPushMatrix()


                'If the arm is moving forward we will increase
                'the angle, otherwise we will decrease the
                'angle

                If arm2

                        armAngle[1] = armAngle[1] + 1.0

                Else

                        armAngle[1] = armAngle[1] - 1.0

          EndIf

                'Once the arm has reached its Max angle
                'in one direction, we want it To reverse
                'And change direction.

                If armAngle[1] >= 15.0 Then

                        arm2 = False

                EndIf

                If armAngle[1] <= -15.0 Then

                        arm2 = True

          EndIf      

                'Here we are going To move the arm away
                'from the torso And rotate. This will
                'Create a walking effect.

                glTranslatef(0.0, -0.5, 0.0)
                glRotatef(armAngle[1], 1.0, 0.0, 0.0)

                DrawArm(-1.5, 0.0, -0.5)

        glPopMatrix()

        'Now its time To rotate the legs relative To the
        'robots position in the world, this is the first
        'leg, ie the Right one.

        glPushMatrix()

                'If the leg is moving forward we will increase
                'the angle; otherwise, we will decrease the
                'angle.

                If leg1

                        legAngle[0] = legAngle[0] + 1.0

                Else

                        legAngle[0] = legAngle[0] - 1.0

          EndIf

                'Once the leg has reached its Max angle
                'in one direction, we want it To reverse
                'And change direction.

                If legAngle[0] >= 15.0 Then

                        leg1 = False

                EndIf

                If legAngle[0] <= -15.0 Then

                        leg1 = True

          EndIf

                'Here we are going To move the leg away
                'from the torso And rotate. This will
                'Create a walking effect.

                glTranslatef(0.0, -0.5, 0.0)
                glRotatef(legAngle[0], 1.0, 0.0, 0.0)


                'Time To draw the leg.

                DrawLeg(-0.5, -4.8, -0.5)

        glPopMatrix()

        'Same as above, For the Left leg.

        glPushMatrix()

                'If the leg is moving forward we will increase
                'the angle, otherwise we will decrease the
                'angle

                If leg2

                        legAngle[1] = legAngle[1] + 1.0

                Else

                        legAngle[1] = legAngle[1] - 1.0

          EndIf

                'Once the leg has reached its Max angle
                'in one direction, we want it To reverse
                'And change direction.

                If legAngle[1] >= 15.0 Then 

                        leg2 = False

                EndIf

                If legAngle[1] <= -15.0 Then

                        leg2 = True

          EndIf                

                'Here we are going To move the leg away
                'from the torso And rotate. This will
                'Create a walking effect.

                glTranslatef(0.0, -0.5, 0.0)
                glRotatef(legAngle[1], 1.0, 0.0, 0.0)

               'Time To draw the leg.

                DrawLeg(1.5, -4.8, -0.5)

        glPopMatrix()

'        glPopMatrix()

End Function

Function DrawCube(xPos:Float, yPos:Float, zPos:Float)

        glPushMatrix()

        glBegin(GL_POLYGON)

                'This is the top face
                glVertex3f(0.0, 0.0, 0.0)
                glVertex3f(0.0, 0.0, -1.0)
                glVertex3f(-1.0, 0.0, -1.0)
                glVertex3f(-1.0, 0.0, 0.0)

                'This is the front face
                glVertex3f(0.0, 0.0, 0.0)
                glVertex3f(-1.0, 0.0, 0.0)
                glVertex3f(-1.0, -1.0, 0.0)
                glVertex3f(0.0, -1.0, 0.0)

                'This is the Right face
                glVertex3f(0.0, 0.0, 0.0)
                glVertex3f(0.0, -1.0, 0.0)
                glVertex3f(0.0, -1.0, -1.0)
                glVertex3f(0.0, 0.0, -1.0)

                'This is the Left face
                glVertex3f(-1.0, 0.0, 0.0)
                glVertex3f(-1.0, 0.0, -1.0)
                glVertex3f(-1.0, -1.0, -1.0)
                glVertex3f(-1.0, -1.0, 0.0)

                'This is the bottom face
                glVertex3f(0.0, 0.0, 0.0)
                glVertex3f(0.0, -1.0, -1.0)
                glVertex3f(-1.0, -1.0, -1.0)
                glVertex3f(-1.0, -1.0, 0.0)

                'This is the back face
                glVertex3f(0.0, 0.0, 0.0)
                glVertex3f(-1.0, 0.0, -1.0)
                glVertex3f(-1.0, -1.0, -1.0)
                glVertex3f(0.0, -1.0, -1.0)

        glEnd()

        glPopMatrix()

End Function

Function DrawArm(xPos:Float, yPos:Float, zPos:Float)

        glPushMatrix()

                'Sets Color To red
                glColor3f(1.0, 0.0, 0.0)
                glTranslatef(xPos, yPos, zPos)

                'Creates 1 x 4 x 1 cube
                glScalef(1.0, 4.0, 1.0)

                DrawCube(0.0, 0.0, 0.0)

        glPopMatrix()

End Function

Function DrawHead(xPos:Float, yPos:Float, zPos:Float)

        glPushMatrix()

                'Sets Color To white
                glColor3f(1.0, 1.0, 1.0)
                glTranslatef(xPos, yPos, zPos)

                'Creates 2 x 2 x 2 cube
                glScalef(2.0, 2.0, 2.0)

                DrawCube(0.0, 0.0, 0.0)

        glPopMatrix()

End Function

Function DrawTorso(xPos:Float, yPos:Float, zPos:Float)

        glPushMatrix()

                'Sets Color To green
                glColor3f(0.0, 1.0, 0.0)
                glTranslatef(xPos, yPos, zPos)

                'Creates 3 x 5 x 1 cube
                glScalef(3.0, 5.0, 1.0)

                DrawCube(0.0, 0.0, 0.0)

        glPopMatrix()

End Function

Function DrawLeg(xPos:Float, yPos:Float, zPos:Float)

        glPushMatrix()

                'Sets Color To blue
                glColor3f(0.0, 0.0, 1.0)
                glTranslatef(xPos, yPos, zPos)

                'Creates 1 x 5 x 1 cube
                glScalef(1.0, 5.0, 1.0)

                DrawCube(0.0, 0.0, 0.0)

        glPopMatrix()

End Function
(Posted 6 months ago) RonTek commented:

There you go! and nice snippet you got there. You can also post it in either code archives (use code-archive tag) or in gallery (Blitz Showcase subforum with screenshot)

Reply To Topic (minimum 10 characters)

Please log in to reply