Author Topic: Revolving 3D Vector using GLBasic  (Read 1540 times)

Offline Eric.Erpelding

  • Mc. Print
  • *
  • Posts: 32
    • View Profile
Revolving 3D Vector using GLBasic
« 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
« Last Edit: 2016-Aug-22 by Eric.Erpelding »

Offline nabz32

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 307
    • View Profile
Re: Revolving 3D Vector using GLBasic
« Reply #1 on: 2016-Aug-22 »
Glbasic wants an angle for sin and Cos functions dont know if it Works with Radians too

Offline Eric.Erpelding

  • Mc. Print
  • *
  • Posts: 32
    • View Profile
Re: Revolving 3D Vector using GLBasic
« Reply #2 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.
« Last Edit: 2016-Aug-26 by Eric.Erpelding »