GLBasic forum

Main forum => GLBasic - en => Topic started by: Eric.Erpelding on 2016-Aug-22

Title: Revolving 3D Vector using GLBasic
Post by: Eric.Erpelding on 2016-Aug-22
This is my first attempt at making a 3D representation of a revolving vector using GLBasic.
Actually, it is my first attempt at writing any kind of 3D graphics program.
The code is very simple and will be the basis for further development.
Specific parameter values have been hard coded into this version just to get something working.
Any comments will be appreciated.

Code: GLBasic [Select]
// --------------------------------- //
// Project: Revolving Arrow Vector
// Start: Sunday, August 21, 2016
// IDE Version: 14.001

GLOBAL cone, cylinder
GLOBAL phi

GLOBAL ArrowHeadColor, ArrowShaftColor

ArrowHeadColor=RGB(255,0,0)
ArrowShaftColor = RGB(255, 153,51)

// object numbers
cone = 0
cylinder=1

// CreateCone: num, r, h, n, col
CreateCone(cone,6,10,20, ArrowHeadColor)

// CreateCylinder: num, r, h, n, col
CreateCylinder(cylinder,3,50, 20, ArrowShaftColor)


WHILE TRUE
    INC phi, 1.
    X_MAKE3D 1,1000,45

    X_CAMERA 100,75,100, 0,25,0
   
    X_MOVEMENT 0,0,0
   
    // Draw co-ordinate axis
    X_LINE 0,0,0,100,0,0,5,RGB(0,0,255)
    X_LINE 0,0,0,0,100,0,5,RGB(0,0,255)
    X_LINE 0,0,0,0,0,100,5,RGB(0,0,255)
   
    // Draw rotated arrow vector
    X_ROTATION 45, COS(phi),0,-SIN(phi)
    X_DRAWOBJ cylinder,0
    X_MOVEMENT 50*COS(45)*SIN(phi),50*SIN(45),50*COS(45)*COS(phi)
    X_ROTATION 45, COS(phi),0,-SIN(phi)
    X_DRAWOBJ cone,0

    SHOWSCREEN
WEND

// ------------------------------------------------------------- //
// -=#  CONE  #=-
// ------------------------------------------------------------- //
FUNCTION CreateCone: num, r, h, n, col
LOCAL i,j,theta,pi
        pi = ACOS(0)*2
        IF r < 0 THEN r = -r
        IF n < 4 THEN n = 4

        X_AUTONORMALS 2
        X_OBJSTART num
        FOR i=0 TO n
                theta = i * 2*pi / n;
                X_OBJADDVERTEX   0, h, 0, 0, 0, col
        X_OBJADDVERTEX  r*COS(theta),0,r*SIN(theta),0,0,col
        theta = (i+1)*2*pi/n
        X_OBJADDVERTEX  r*COS(theta),0,r*SIN(theta),0,0,RGB(255,255,255)
        X_OBJADDVERTEX 0,0,0,0,0,col
        X_OBJNEWGROUP

        NEXT
        X_OBJEND
ENDFUNCTION

// ------------------------------------------------------------- //
// -=#  CYLINDER  #=-
// ------------------------------------------------------------- //
FUNCTION CreateCylinder: num, r, h, n, col
LOCAL i,j,theta,pi
        pi = ACOS(0)*2
        IF r < 0 THEN r = -r
        IF n < 4 THEN n = 4

        X_AUTONORMALS 2
        X_OBJSTART num
        FOR i=0 TO n
                theta = i * 2*pi / n;
                X_OBJADDVERTEX   r*COS(theta),0,r*SIN(theta),0,0,col
        X_OBJADDVERTEX  r*COS(theta),h,r*SIN(theta),0,0,col
        theta = (i+1)*2*pi/n
        X_OBJADDVERTEX  r*COS(theta),0,r*SIN(theta),0,0,col
        X_OBJADDVERTEX  r*COS(theta),h,r*SIN(theta),0,0,col
        X_OBJNEWGROUP

        NEXT
        X_OBJEND
ENDFUNCTION
Title: Re: Revolving 3D Vector using GLBasic
Post by: nabz32 on 2016-Aug-22
Glbasic wants an angle for sin and Cos functions dont know if it Works with Radians too
Title: Re: Revolving 3D Vector using GLBasic
Post by: Eric.Erpelding on 2016-Aug-22
Quote
Glbasic wants an angle for sin and Cos functions dont know if it Works with Radians too
Yes, I discovered that when writing the program. I think DEG is the only angle mode in GLBasic.