Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - FutureCow

Pages: [1] 2 3 ... 10
1
IDE/Syntax / Error Handling
« on: 2013-Jun-02 »
Can we please have error checking? You should be able to check the return code on commands like LoadSprite for example to gracefully handle if they fail rather than having your program die unexpectedly.

2
Off Topic / Maths help for my game
« on: 2012-Jul-04 »
Any takers on how to apply a sin wave on a vector?

Ie. Normally if your object was travelling down the screen you'd just add the sin value to your X coordinate, but what if you're not travelling horizontally or vertically?
I know I need to add the sin wave to the perpendicular of the vector, but I'm having trouble finding the formula written down without being in complicated maths language or expressed as a matrix.

So far I have
1) To work out coordinates based on an angle : x=cos (angle) and y=sin(angle)
2) Angle of a vector : angle=atan(ydifference,x difference)
  (Where ydifference is your destination coordinate - your current coordinate)

Any takers?

Bonus points if you can explain to me why in code that uses trigonometry you see the code "normalize" the vectors all the time. What does the normalizing do? I think it just maps it to the unit circle (ie. range -1 to +1) - is that right?

3
If I'm running my program (GLBasic v10.283) and it runs to a breakpoint, if I hit Debugger->Stop, or shift-f5, the program starts running again instead of stopping the execution flow. From this point it also ignores any further breakpoints it hits.

4
Bug Reports / IDE breakpoint very minor bugs
« on: 2012-Jun-23 »
They're not major issues, but I noticed some unusual behaviour with breakpoints
* If you're on a line prior to one with a breakpoint and you delete your current line, when the next line (with the breakpoint) moves up one line, the breakpoint disappears.
*If you're on a line with a breakpoint and in the first column and press enter, the breakpoint doesn't move down a line as it should.


5
I'm contributing this here because even though it's really simple, I was surprised there was no command to return it directly.

If you have a number (eg. 63.45) and want to return the ".45" part only it's as simple as
Code: (glbasic) [Select]
FUNCTION FractionOnly : Number
Return (Number - INTEGER(Number))


6
This should be relatively simple but vectors are making my head hurt just now.

I'm looking at implementing steering behaviour (ie. gradually changing a vector to another one). Does anyone have pseudocode or an example they can throw in my direction?

The easiest way to describe it is with a car example :
Lets say I've got a car going North at 10 m/s. I want to change that so that the car is eventually going East at 10 m/s. Every game update the speed will be 10m/s. The player turns a steering wheel a certain amount so that every game update the car is facing a bit more to the east, a bit less to the north, but still doing the same speed.

My code currently has an initial vector and a starting point on a grid. I know when the player hits a particular location I need to start changing the vector so it gradually moves to point at a different location. I'm not sure of the calculation to set the new facing direction as I only know it as an angle from the current facing direction, not as a vector.

Edit - Just found that it looks to be
X=cos(angle) * speed
Y=sin(angle) * speed

7
I'm trying a new approach to texturing a model (a generated 3D landscape) but I'm having some unexpected behaviour I'm hoping someone will be able to pinpoint for me.

Firstly my model is built as follows
  • I load a list of heights of each square tile - the map is 128x128 tiles in size
  • I create the model in triangle strips
  • I load a test image to use for a texture that is 128x128 pixels in size
  • The texture is set to the image that was loaded then the model is drawn

Here's what my model comes out looking like - this is a picture taken from looking straight down at the model. The lines aren't 100% straight as the section of the model shown isn't flat so I'm not worried about that.



Here's the texture. Each quad in my model correllates to exactly 1 pixel in the source texture.


Here's how I create the model
Code: (glbasic) [Select]
FOR Z=0 TO (ModelSizeZ-2)
ZTexValue1=1/(128/(Z+1))                      // Set the first Z offset into the texture image
ZTexValue2=1/(128/(Z+2))                      // Set the second Z offset into the texture image
X_OBJNEWGROUP

FOR X=0 TO (MapSizeX-2) STEP 2
XTexValue1=1/(128/(X+1))                      // Set the first X offset into the texture image
XTexValue2=1/(128/(X+2))                      // Set the second X offset into the texture image

      X_OBJADDVERTEX   X,   HeightsArray[X][Z+1],  Z+1,  0,0, RGB(255,255,255)         // Create quad. Bottom left corner
        X_OBJADDVERTEX   X,   HeightsArray[X][Z],      Z,  0,1, RGB(255,255,255)              // Top left corner
        X_OBJADDVERTEX   X+1, HeightsArray[X+1][Z+1], Z+1, 1,0, RGB(255,255,255)     // Bottom right corner
        X_OBJADDVERTEX   X+1, HeightsArray[X+1][Z],    Z,  1,1, RGB(255,255,255)         // Top right Corner
ENDIF
NEXT
NEXT

My issues
1) Any idea why am I getting the image coming out looking like it's made up of joined up strips? I would've expected everything to blend together nicely, but instead I get the lines in it where two strips of triangles meet.

2) Each tile (ie square of 2 triangles) should be a solid colour. How do I stop each colour from blending into the next one so that each square's doesn't blend into those of the squares next to it? Is this because of the small texture image size? (128x128 pixels)

8
I have a 3D terrain object that is currently made up of lots of joined together squares (ie. it's drawn as one 3D object by my code). Currently I set my texture then draw the land object once per game loop.
Originally all the squares have the same texture, but over time I want to change some of them (eg. make some squares muddy).
Any idea what the best way to accomplish changing part of the texture of a 3D object is?

The only way I've come up with that would work : My terrain is currently 128x128 squares (ie. 32768 triangles) and I'm using x_collisionray to determine which grid location is under the cursor. I could draw each grid square as a separate 3D object and texture them separately but that's a lot of 3D objects draw every frame, and 32768 x_collisionray calls per frame (or even once a second) I'm guessing would make the program really slow.

A bit of googling initially led me to think that a vertex shader is what I'm after but now I'm not so sure - besides which I've got no idea how to write/implement one (assuming that IS what I'm looking for!)

If anyone has any great ideas I'd love to hear them!!!

9
I had posted in that thread, but seeing the post is stickied and old, I thought people would overlook the post so moved it here.

I'm not sure what's going on but I seem to have big issues with this code and GLBasic 10.283. Hopefully someone will have some ideas! (I don't understand the maths too well so I don't know where to start sorry!!!!)

If I use camera_roll,pitch or yaw, every alternate call seems to give me a result 180 degrees out (based on how it shows on the screen) from where it should be. For example, assuming each call to "camera_roll" rotates 1 degree, my first run through the code would be 0 degrees roll, rollowed by 181 degrees, followed by 2 degrees, followed by 183 degrees, followed by 4 degrees etc.

My only change to the original code to show the problem easily is to modify the showscreen section of the main loop to say :
Code: (glbasic) [Select]
SHOWSCREEN
MOUSEWAIT
camera_roll(cam1,2)

but I can change that "2" value to anything I like and still appear to get the same results.

Here's the full combined code from the post about the library (http://www.glbasic.com/forum/index.php?topic=3851.0) with my little change to make it easy for someone to paste straight into a project. Run it, and click the mouse multiple times and you'll see the issue.

Code: (glbasic) [Select]
// --------------------------------- //
// Project: 6DOFCam_lib
// Start: Thursday, November 19, 2009
// IDE Version: 7.177
//

main()

TYPE Tquaternion
    w#
    x#
    y#
    z#
ENDTYPE

TYPE Tcamera
    //position
    x#
    y#
    z#

    //look vector
    lx#
    ly#
    lz#

    //up vector
    ux#
    uy#
    uz#

    //right vector
    rx#
    ry#
    rz#

    FOV#
    aspect#
    nearClip#
    farClip#
ENDTYPE


FUNCTION quaternion_normalize AS Tquaternion: tmpQ AS Tquaternion
LOCAL mag# = SQR(tmpQ.w*tmpQ.w+tmpQ.x*tmpQ.x+tmpQ.y*tmpQ.y+tmpQ.z*tmpQ.z)
LOCAL q AS Tquaternion
q.w = tmpQ.w / mag
q.x = tmpQ.x / mag
q.y = tmpQ.y / mag
q.z = tmpQ.z / mag
RETURN q
ENDFUNCTION


FUNCTION quaternion_conj AS Tquaternion: tmpQ AS Tquaternion
LOCAL q AS Tquaternion
q.w = -tmpQ.w
q.x = -tmpQ.x
q.y = -tmpQ.y
q.z = -tmpQ.z
    RETURN q
ENDFUNCTION


FUNCTION quaternion_mult AS Tquaternion: lhs AS Tquaternion, rhs AS Tquaternion
LOCAL q AS Tquaternion
    q.w = lhs.w * rhs.w - lhs.x * rhs.x - lhs.y * rhs.y - lhs.z * rhs.z
    q.x = lhs.w * rhs.x + lhs.x * rhs.w + lhs.y * rhs.z - lhs.z * rhs.y
    q.y = lhs.w * rhs.y - lhs.x * rhs.z + lhs.y * rhs.w + lhs.z * rhs.x
    q.z = lhs.w * rhs.z + lhs.x * rhs.y - lhs.y * rhs.x + lhs.z * rhs.w
RETURN q
ENDFUNCTION


FUNCTION camera_advance: cam AS Tcamera, d#
        LOCAL xt#, yt#, zt#
        xt = (cam.lx - cam.x) * d
        yt = (cam.ly - cam.y) * d
        zt = (cam.lz - cam.z) * d
        cam.x = cam.x + xt
        cam.y = cam.y + yt
        cam.z = cam.z + zt
        cam.ux =cam.ux + xt
        cam.uy =cam.uy + yt
        cam.uz =cam.uz + zt
        cam.rx =cam.rx + xt
        cam.ry =cam.ry + yt
        cam.rz =cam.rz + zt
        cam.lx =cam.lx + xt
        cam.ly =cam.ly + yt
        cam.lz =cam.lz + zt
ENDFUNCTION


FUNCTION camera_strafe: cam AS Tcamera, d#
        LOCAL xt#, yt#, zt#
        xt = (cam.rx - cam.x) * d
        yt = (cam.ry - cam.y) * d
        zt = (cam.rz - cam.z) * d
        cam.x = cam.x + xt
        cam.y = cam.y + yt
        cam.z = cam.z + zt
        cam.ux = cam.ux + xt
        cam.uy = cam.uy + yt
        cam.uz = cam.uz + zt
        cam.rx = cam.rx + xt
        cam.ry = cam.ry + yt
        cam.rz = cam.rz + zt
        cam.lx = cam.lx + xt
        cam.ly = cam.ly + yt
        cam.lz = cam.lz + zt
ENDFUNCTION


FUNCTION camera_rise: cam AS Tcamera, d#
        LOCAL xt#, yt#, zt#
        xt = (cam.ux - cam.x) * d
        yt = (cam.uy - cam.y) * d
        zt = (cam.uz - cam.z) * d
        cam.x = cam.x + xt
        cam.y = cam.y + yt
        cam.z = cam.z + zt
        cam.ux = cam.ux + xt
        cam.uy = cam.uy + yt
        cam.uz = cam.uz + zt
        cam.rx = cam.rx + xt
        cam.ry = cam.ry + yt
        cam.rz = cam.rz + zt
        cam.lx = cam.lx + xt
        cam.ly = cam.ly + yt
        cam.lz = cam.lz + zt
ENDFUNCTION


FUNCTION camera_roll: cam AS Tcamera, a#
        LOCAL qUp AS Tquaternion
        qUp.w = 0
        qUp.x = cam.ux - cam.x
        qUp.y = cam.uy - cam.y
        qUp.z = cam.uz - cam.z

        LOCAL qRight AS Tquaternion
        qRight.w = 0
        qRight.x = cam.rx - cam.x
        qRight.y = cam.ry - cam.y
        qRight.z = cam.rz - cam.z

        LOCAL qRot AS Tquaternion
        qRot.w = COS(a * rad/2)
        qRot.x = (cam.lx - cam.x) * SIN(a * rad/2)
        qRot.y = (cam.ly - cam.y) * SIN(a * rad/2)
        qRot.z = (cam.lz - cam.z) * SIN(a * rad/2)

        LOCAL W AS Tquaternion,W1 AS Tquaternion,W2 AS Tquaternion
        W1 = quaternion_mult(qRot,qUp)
        W2 = quaternion_conj(qRot)
        W = quaternion_mult(W2,W1)
        W = quaternion_normalize(W)
            cam.ux = W.x + cam.x
            cam.uy = W.y + cam.y
            cam.uz = W.z + cam.z
//        W = quaternion_mult(quaternion_mult(qRot,qRight), quaternion_conj(qRot)) <<< This does not work?!?!
        W1 = quaternion_mult(qRot,qRight)
        W2 = quaternion_conj(qRot)
        W = quaternion_mult(W2,W1)
        W = quaternion_normalize(W)
            cam.rx = W.x + cam.x
            cam.ry = W.y + cam.y
            cam.rz = W.z + cam.z
ENDFUNCTION

FUNCTION camera_pitch: cam AS Tcamera, a#
        LOCAL qUp AS Tquaternion
        qUp.w = 0
        qUp.x = cam.ux - cam.x
        qUp.y = cam.uy - cam.y
        qUp.z = cam.uz - cam.z

        LOCAL qLook AS Tquaternion
        qLook.w = 0
        qLook.x = cam.lx - cam.x
        qLook.y = cam.ly - cam.y
        qLook.z = cam.lz - cam.z

        LOCAL qRot AS Tquaternion
        qRot.w = COS(a * rad/2)
        qRot.x = (cam.rx - cam.x) * SIN(a * rad/2)
        qRot.y = (cam.ry - cam.y) * SIN(a * rad/2)
        qRot.z = (cam.rz - cam.z) * SIN(a * rad/2)

        LOCAL W AS Tquaternion,W1 AS Tquaternion,W2 AS Tquaternion
        W1 = quaternion_mult(qRot,qUp)
        W2 = quaternion_conj(qRot)
        W = quaternion_mult(W2,W1)
        W = quaternion_normalize(W)
            cam.ux = W.x + cam.x
            cam.uy = W.y + cam.y
            cam.uz = W.z + cam.z
        W1 = quaternion_mult(qRot,qLook)
        W2 = quaternion_conj(qRot)
        W = quaternion_mult(W2,W1)
        W = quaternion_normalize(W)
            cam.lx = W.x + cam.x
            cam.ly = W.y + cam.y
            cam.lz = W.z + cam.z
ENDFUNCTION


FUNCTION camera_yaw: cam AS Tcamera, a#
        LOCAL qRight AS Tquaternion
        qRight.w = 0
        qRight.x = cam.rx - cam.x
        qRight.y = cam.ry - cam.y
        qRight.z = cam.rz - cam.z

        LOCAL qLook AS Tquaternion
        qLook.w = 0
        qLook.x = cam.lx - cam.x
        qLook.y = cam.ly - cam.y
        qLook.z = cam.lz - cam.z

        LOCAL qRot AS Tquaternion
        qRot.w = COS(a * rad/2)
        qRot.x = (cam.ux - cam.x) * SIN(a * rad/2)
        qRot.y = (cam.uy - cam.y) * SIN(a * rad/2)
        qRot.z = (cam.uz - cam.z) * SIN(a * rad/2)

        LOCAL W AS Tquaternion,W1 AS Tquaternion,W2 AS Tquaternion
        W1 = quaternion_mult(qRot,qRight)
        W2 = quaternion_conj(qRot)
        W = quaternion_mult(W2,W1)
        W = quaternion_normalize(W)
            cam.rx = W.x + cam.x
            cam.ry = W.y + cam.y
            cam.rz = W.z + cam.z
        W1 = quaternion_mult(qRot,qLook)
        W2 = quaternion_conj(qRot)
        W = quaternion_mult(W2,W1)
        W = quaternion_normalize(W)
            cam.lx = W.x + cam.x
            cam.ly = W.y + cam.y
            cam.lz = W.z + cam.z
ENDFUNCTION


FUNCTION X_6DOFCAMERA: cam AS Tcamera
X_MAKE3D cam.nearClip, cam.farClip, cam.FOV
X_CAMERAUP cam.x - cam.ux, cam.y - cam.uy, cam.z - cam.uz
DEBUG cam.x+","+cam.ux+","+cam.y+","+cam.uy+","+cam.z+","+cam.uz+"\n"
X_CAMERA cam.x, cam.y, cam.z, cam.lx, cam.ly, cam.lz
ENDFUNCTION



FUNCTION main:


// --------------------------------- //
// Project: 6DOFCam_test
// Start: Thursday, November 19, 2009
// IDE Version: 7.177

LOCAL cam1 AS Tcamera

LOCAL speed# = .01
LOCAL xv#, yv#, zv#, p#=0, r#=0, y#=0
LOCAL mx%, my%, mw%, mba%, mbb%
CONSTANT rad = 3.1415926535/180

cam1.x# = 0
cam1.y = 0
cam1.z = 0

cam1.lx = 0
cam1.ly = 0
cam1.lz = -1

cam1.ux# = 0
cam1.uy# = 1
cam1.uz# = 0

cam1.rx = 1
cam1.ry = 0
cam1.rz = 0

cam1.FOV = 45
cam1.aspect = 1024/768
cam1.nearClip = .01
cam1.farClip = 5000

WHILE TRUE


MOUSESTATE mx, my, mba, mbb
mx = MOUSEAXIS(0)/10
my = -MOUSEAXIS(1)/10

X_6DOFCAMERA(cam1)

    //Linear Velocity Dampening (SPACE)
    IF KEY(57)
        xv = xv * .95
        yv = yv * .95
        zv = zv * .95
    ENDIF

    //Angular Velocity Dampening (CTRL)
    IF KEY(29)
        r = r * .95
        p = p * .95
        y = y * .95
    ENDIF

    //Accelerate Forward (W)
    IF KEY(17)
        xv = xv + (cam1.lx - cam1.x) * speed
        yv = yv + (cam1.ly - cam1.y) * speed
        zv = zv + (cam1.lz - cam1.z) * speed
    ENDIF
    //Accelerate Backward (S)
    IF KEY(31)
        xv = xv - (cam1.lx - cam1.x) * speed
        yv = yv - (cam1.ly - cam1.y) * speed
        zv = zv - (cam1.lz - cam1.z) * speed
    ENDIF
    //Accelerate Left (A)
    IF KEY(30)
        xv = xv + (cam1.rx - cam1.x) * speed
        yv = yv + (cam1.ry - cam1.y) * speed
        zv = zv + (cam1.rz - cam1.z) * speed
    ENDIF
    //Accelerate Right (D)
    IF KEY(32)
        xv = xv - (cam1.rx - cam1.x) * speed
        yv = yv - (cam1.ry - cam1.y) * speed
        zv = zv - (cam1.rz - cam1.z) * speed
    ENDIF
    //Accelerate Down (F)
    IF KEY(33)
        xv = xv + (cam1.ux - cam1.x) * speed
        yv = yv + (cam1.uy - cam1.y) * speed
        zv = zv + (cam1.uz - cam1.z) * speed
    ENDIF
    //Accelerate Up (R)
    IF KEY(19)
        xv = xv - (cam1.ux - cam1.x) * speed
        yv = yv - (cam1.uy - cam1.y) * speed
        zv = zv - (cam1.uz - cam1.z) * speed
    ENDIF

    // change IF the left mouse button is pressed
    IF mba = 1
        //Pitch mouse up AND
        p = p + my
        //Yaw
        y = y + mx
    ELSEIF mbb = 1
        //Roll with right mouse button
        r = r + mx
    ENDIF

    cam1.x = cam1.x + xv
    cam1.y = cam1.y + yv
    cam1.z = cam1.z + zv
    cam1.lx = cam1.lx + xv
    cam1.ly = cam1.ly + yv
    cam1.lz = cam1.lz + zv
    cam1.rx = cam1.rx + xv
    cam1.ry = cam1.ry + yv
    cam1.rz = cam1.rz + zv
    cam1.ux = cam1.ux + xv
    cam1.uy = cam1.uy + yv
    cam1.uz = cam1.uz + zv

    debug_view(0,0,0,100,RGB(255,255,0),RGB(255,0,255),RGB(0,255,255))

  camera_roll(cam1,r)
  camera_pitch(cam1,p)
  camera_yaw(cam1,y)

X_MAKE2D
PRINT "Cam Pitch = "+p,10,10
PRINT "Cam Yaw = "+y,10,20
PRINT "Cam Roll = "+r,10,30
SETPIXEL mx,my,RGB(255,255,255)
SHOWSCREEN
MOUSEWAIT
camera_roll(cam1,0.1)
WEND
ENDFUNCTION


FUNCTION debug_view: x, y, z, crad, rgb1, rgb2, rgb3
LOCAL rad, x1, y1, j, x2, y2
y1=SIN(0)*crad
x1=COS(0)*crad
FOR j=4 TO 360 STEP 4
    y2=SIN(j)*crad
    x2=COS(j)*crad
    X_LINE x+x1,y+y1,z  , x+x2,y+y2,z,0.1,rgb1
    X_LINE x+x1,y+0,y1+z, x+x2,y+0,y2+z,1,rgb2
    X_LINE x+0,y+x1,y1+z, x+0,y+x2,y2+z,1,rgb3
    x1=x2
    y1=y2
NEXT
X_DOT x,y,z,10,rgb1
X_DRAWAXES x+crad,y,z
    X_DRAWAXES x-crad,y,z
    X_DRAWAXES x,y+crad,z
    X_DRAWAXES x,y-crad,z
    X_DRAWAXES x,y,crad+z
    X_DRAWAXES x,y,-crad+z
    X_PRINT "RIGHT X+",x+crad,y,z,0
    X_PRINT "LEFT X-",x-crad,y,z,0
    X_PRINT "UP Y+",x,y+crad,z,0
    X_PRINT "DOWN Y-",x,y-crad,z,0
    X_PRINT "OUT Z+",x,y,crad+z,0
    X_PRINT "IN Z-",x,y,-crad+z,0
    X_SETTEXTURE -1, -1
ENDFUNCTION

I know the entity system is an alternative, but I found it a bit clunky and buggy when I used it in the past so at this point I'd rather stick with the camera library. Also, I might not understand the maths in the camera library, but at least I wouldn't have to rewrite my project if someone can identify how to fix it.

Any help is appreciated!

10
Bug Reports / X_COLLISIONRAY crash
« on: 2012-May-27 »
My program will crash when it hits the X_COLLISIONRAY line in the following section of code - but only when debug is disabled

Code: (glbasic) [Select]

LOCAL x,y,z, x2,y2,z2
X_SCREEN2WORLD MouseX, MouseY,  0, x, y, z
X_SCREEN2WORLD MouseX, MouseY, -1, x2,y2,z2
// DEBUG M_Hill+","+x+","+y+","+z+","+x2+","+y2+","+z2
// END
IF X_COLLISIONRAY(M_Hill, 0, x, y, z, x2-x, y2-y, z2-z)<>0
MouseCollisionFace=X_GETCOLLISIONFACE() // div by 3 for x_getcollisionface bug, then divide by 2 to get the right triangle
X_GETFACE M_Hill, 0, MouseCollisionFace, Face[]
DEBUG "Collision = "+MouseCollisionFace+",X="+Face[0][0]+",Y="+Face[0][1]+",Z="+Face[0][2]+",nx="+Face[0][6]+",ny="+Face[0][7]+",nz="+Face[0][8]+"\n"
ELSE
MouseCollisionFace=-1
ENDIF

If I turn debug on, there's no crash. By uncommenting the two commented lines I can see I have valid variables to pass to the command :
Code: (glbasic) [Select]
Injection started

7,-6.900289536,1.999999642,3.900290012,-6.900289536,1.999999642,3.900290012
By putting "END" commands straight after the "IF" and "ELSE" lines, I can prove it's the X_COLLISIONRAY on the first execution of the code that crashes the program.

My setup is Windows XP, GLBasic 10.283

11
Hi All,
There was an old thread that I was testing the code from (http://www.glbasic.com/forum/index.php?topic=673.0) as I was having issues with my code. The old example does something very similar to my program and it shows the same problem in in GLBasic 10 (I'm running 10.283). I don't understand why it doesn't work correctly.

The problem is that some colours on textures are showing up see-through and I'm not sure why.

I've modified the original code very slightly. Firstly, it shows you the sample texture on the screen and waits for an "enter" keypress to continue. This way you can see what the texture should look like.
Secondly, I've replaced FillRect with DrawRect (the current equivalent), and lowered the camera angle to make it easy to see that the texture is see-through - everything else is identical to the original code.

If someone could run this code and tell me why some coloured textures are invisible and others aren't, that would be awesome!

Code: (glbasic) [Select]
LOCAL world[]
DIM world[15][10]

// Dummy Data
FOR x=0 TO 14
FOR y=0 TO 9
world[x][y]=RND(15)/10
NEXT
NEXT

// Create World Object
X_OBJSTART 0
X_AUTONORMALS 2
FOR x=0 TO 14
FOR y=0 TO 9
MakeTile(world[], x,y, -15/2, -10/2)
NEXT
NEXT
X_OBJEND

LOCAL a=0
WHILE a=0
// some dummy texture:
DRAWRECT 0,0,128,128, RGB(0,0,255)
DRAWRECT 4,4,124,124, RGB(255,255,255)
DRAWRECT 5,62,123,66, RGB(0,255,0)
DRAWRECT 62,5,66,123, RGB(0,255,0)
DRAWRECT 62,62,66,66, RGB(255,0,0)
PRINT "GLBasic", 8,8

GRABSPRITE 0, 0,0,128,128
SHOWSCREEN
IF KEY(28)=1 THEN a=1
WEND
BLACKSCREEN


WHILE TRUE
X_MAKE3D 1,100, 45
X_CAMERA 1,6,10, 0,0,0
X_SETTEXTURE 0,-1
X_ROTATION GETTIMERALL()/100, 0,1,0
X_DRAWOBJ 0,0
SHOWSCREEN
WEND



FUNCTION MakeTile: heights[], x,y, offsetx, offsety
// Triangle Strip is:
// 0--2--4-.
// | /| /| .
// |/ |/ |/
// 1--3--5-.

// We need:
// 0-1-2
// |\|/|
// 3-4-5
// |/|\|
// 6-7-8
LOCAL pts[]
LOCAL i, px, py, mx, my
DIM pts[9][3] // 9 points[x,y,z]
pts[0][0]=-1; pts[0][1]=-1
pts[1][0]=.0; pts[1][1]=-1
pts[2][0]= 1; pts[2][1]=-1
pts[3][0]=-1; pts[3][1]=.0
pts[4][0]=.0; pts[4][1]=.0
pts[5][0]= 1; pts[5][1]=.0
pts[6][0]=-1; pts[6][1]= 1
pts[7][0]=.0; pts[7][1]= 1
pts[8][0]= 1; pts[8][1]= 1

// now calculate Z for each point
mx = BOUNDS(heights[], 0)-1
my = BOUNDS(heights[], 1)-1

FOR i=0 TO 8
// Get neighbour point
// but stop at array border
px = MIN(mx, MAX(0, x+pts[i][0]))
py = MIN(my, MAX(0, y+pts[i][1]))
pts[i][2] = ( heights[px][py]+ _
heights[ x][ y]+ _
heights[px][ y]+ _
heights[ x][py])/4
NEXT

// Next a function to create 2 triangles:
INC x, offsetx
INC y, offsety
AddQuad(pts[], x,y,1,0,4,3)
AddQuad(pts[], x,y,1,4,2,5)
AddQuad(pts[], x,y,3,6,4,7)
AddQuad(pts[], x,y,5,4,8,7)

ENDFUNCTION


FUNCTION AddQuad: pts[], x,y,a,b,c,d

// here we build a triangle stipped quad
// for the points a,b,c,d
// we divide coordinates by 2, so we get a
// rectangle of size 1x1 (-0.5 -> 0.5)
// for the texture we divide by 2 and add 0.5
// (0.0 -> 1.0)
// last: we swap y and z, since y is vertical in GLBasic
LOCAL cl
cl =RGB(255,255,255)
X_OBJADDVERTEX x+pts[a][0]/2,pts[a][2],y+pts[a][1]/2, pts[a][0]/2+.5, pts[a][1]/2+.5,cl
X_OBJADDVERTEX x+pts[b][0]/2,pts[b][2],y+pts[b][1]/2, pts[b][0]/2+.5, pts[b][1]/2+.5,cl
X_OBJADDVERTEX x+pts[c][0]/2,pts[c][2],y+pts[c][1]/2, pts[c][0]/2+.5, pts[c][1]/2+.5,cl
X_OBJADDVERTEX x+pts[d][0]/2,pts[d][2],y+pts[d][1]/2, pts[d][0]/2+.5, pts[d][1]/2+.5,cl
X_OBJNEWGROUP
ENDFUNCTION

In the code above, the white part of the texture becomes see through. It's even more apparent if you replace the following section of code (the bit that draws the texture) :
Code: (glbasic) [Select]
// some dummy texture:
DRAWRECT 0,0,128,128, RGB(0,0,255)
DRAWRECT 4,4,124,124, RGB(255,255,255)
DRAWRECT 5,62,123,66, RGB(0,255,0)
DRAWRECT 62,5,66,123, RGB(0,255,0)
DRAWRECT 62,62,66,66, RGB(255,0,0)
PRINT "GLBasic", 8,8

with
Code: (glbasic) [Select]
DRAWRECT 0,0,128,128, RGB(0,100,0)
DRAWRECT 4,4,124,124, RGB(0,200,0)

Any takers????

12
Just listing this wierd bug in case anyone else comes across it.

With my new project, pressing F1 at any point to bring up help would cause the IDE to crash about 2 seconds after leaving help. The problem was persistant across reboots.

Creating a new project and moving my source files across fixed it. No idea what was broken, but that was the fix in case it helps anyone else.

13
Bug Reports / v10.057 mouse bug?
« on: 2011-Aug-07 »
I've just upgraded to v10 from v8 and I'm sure mouse function has either changed or has a bug (I'm going with the latter). The mouse now seems to be able to move past the edges of the screen/window without mousestate reflecting that.

It's a bit hard to explain clearly, but if you run the following code (on a windows XP box, not sure about other platforms), and move the mouse from coordinate 0,0 for example, 1000 pixels up, mousestate shows always my=0
But to move to coordinate 0,1 you now need to move 1001 pixels down, whereas before I'm sure you'd only have to move 1 pixel down.
The same goes for all the borders.

Example code :
Code: (glbasic) [Select]
GLOBAL mx,my,mb1,mb2

WHILE TRUE
MOUSESTATE mx,my,mb1,mb2
PRINT mx,0,0
PRINT my,50,0
DRAWRECT mx,my,2,2,RGB(255,255,255)
SHOWSCREEN
WEND

14
I'm not sure whether this is a bug or just the way it has to work due to the compiling/linking process.

If you modify your main program source file but don't modify any other source files, Incredibuild does a full rebuild of your project (or at least, it doesn't mention that it's skipping any files and takes a bit longer to complete the build/link step)

15
Createscreen seems to be broken. The following code creates a screen 10x30 and fills it with yellow. Afterwards it draws 100 of them on the screen.
If you change the "X=10" to make the rectangle smaller, it works for "X=9", but when X=8, all the rectangles disappear.

This has been causing me a lot of problems over the past day as the Kerned Font routine I'm writing is using CREATESCREEN to create a sprite 1 pixel wide and by the looks of it, this is the cause.

Can people please test if this breaks on their computers? (Confirm it works as written, then change "X=10" to "X=8" and see if the yellow boxes no longer appear) - ESC to quit.
I'm running WinXP SP3, GLBasic IDE, Version: 7.322

Code: (glbasic) [Select]
LOCAL ScreenImage
ScreenImage=GENSPRITE()

LOCAL X
X=10


CREATESCREEN 1, ScreenImage, X, 30 // First pass, we create our sprite to do collision checks against as a single pixel
USESCREEN 1
DRAWRECT 0, 0, X, 30, RGB (255,255,0)
USESCREEN -1

CLEARSCREEN RGB(255,0,0)
LOCAL Loop
LOCAL Done = 0
WHILE Done = 0
FOR Loop = 1 TO 100
DRAWSPRITE ScreenImage,Loop,Loop
NEXT

IF KEY(1) THEN Done = 1
SHOWSCREEN
WEND
END


Pages: [1] 2 3 ... 10