Menu

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.

Show posts Menu

Messages - Hemlos

#1561
I might be able to help a little with this one..

Try creating a new xmake3d and camera for each obeject you want to render.
You are redunantly moving and rotating 2 times with one camera frame.

Also..
Showscreen automatically blacks out the screen buffer after it is rendered to the screen.
Thus eliminating the last fillrect after the showscreen, in your example will free up some memory loss:
Code (glbasic) Select
Remove:
      X_MAKE2D
   FILLRECT 0,0,320,240,RGB(0,0,200)
Note: If you want to render 2d on top of the 3d, it may help if you call x_make2d only once, before showscreen. Hence, even on a normal pc the differences in performance can be drastic, if there is too much redundant and/or unused lines of code.
#1562
Ok you asked for it, heres an example :)

http://www.glbasic.com/forum/viewtopic.php?id=545
#1563
Ow, delete my program if its spam,
i used it as an example in the snippets for maintaining high frame rates and massive DIm arrays.
#1564
Announcements / IRC chat
2006-Oct-15
Page can not be displayed..

How do i use the link on the website?

Is there a plugin i need?
#1565
link to irc is dead apparently..do i need a plugin for mybrowser or something?

im going to try the code above and see if i can use it

i have europe long distance calling, i can call youif you give me your phone number...
id give you mine but the email server says im a spammer :P

Ok here is your last code modified to use with a joystick..

Code (glbasic) Select
// --------------------------------- //
// Project:
// Start: Friday, October 13, 2006
// IDE Version: 3.283


// Make a rotor
c=RGB(0x40, 0x40, 0xff)
cn=RGB(255,255,255)

// a rotor blade
X_OBJSTART 0
    X_OBJADDVERTEX   0,0,-.1,  0,0, cn
    X_OBJADDVERTEX  10,0, -1, .1,0, c
    X_OBJADDVERTEX  10,0,  1,-.1,0, c
    X_OBJADDVERTEX   0,0, .1,  0,0, cn
    X_OBJADDVERTEX   0,0,-.1,  0,0, cn
    X_OBJADDVERTEX -10,0,  1,  0,0, c
    X_OBJADDVERTEX -10,0, -1, .1,0, c
    X_OBJADDVERTEX   0,0,-.1,-.1,0, cn
X_OBJEND


// a "helicopter"
X_OBJSTART 1
    X_OBJADDVERTEX  0,   0,  0, 0,0,  cn
    X_OBJADDVERTEX -2,  -2,  1, 0,0,  c
    X_OBJADDVERTEX  2,  -1,  1, 0,0,  c
    X_OBJADDVERTEX  0,  -4, .5, 0,0,  c
    X_OBJADDVERTEX  2,  -3,  1, 0,0,  c
    X_OBJADDVERTEX 10,  -2,  0, 0,0,  c
    X_OBJADDVERTEX 10,-2.5,  0, 0,0,  c
    X_OBJNEWGROUP
    X_OBJADDVERTEX  0,   0,  0, 0,0,  cn
    X_OBJADDVERTEX -2,  -2, -1, 0,0,  c
    X_OBJADDVERTEX  2,  -1, -1, 0,0,  c
    X_OBJADDVERTEX  0,  -4,-.5, 0,0,  c
    X_OBJADDVERTEX  2,  -3, -1, 0,0,  c
    X_OBJADDVERTEX 10,  -2,  0, 0,0,  c
    X_OBJADDVERTEX 10,-2.5,  0, 0,0,c
X_OBJEND


WHILE TRUE
    INC inclination, MOUSEAXIS(1)/20
    INC rotation,    MOUSEAXIS(0)
    INC drift,       MOUSEAXIS(2)
    INC spin, GETTIMER()/10

    X_MAKE3D 1,100,45
    X_CAMERA 0,5,-20, 0,0,0

    // the helicopter itself:
    // first incline the thing
    x=x+GETJOYX(0)
    z=z+GETJOYY(0)
    y=y+GETJOYRZ(0)
    X_ROTATION -z, 0,0,1
    // then rotate it
    X_ROTATION -y,    0,1,0
 
    X_PUSHMATRIX
        X_ROTATION -x, 1,0,0
        X_DRAWOBJ 1, 0


        X_PUSHMATRIX // we go relative to the rotated helicopter now
            // add a rotation for the top rotor
            // see: I spin it around the y-axis of the chopper!
            X_ROTATION spin, 0,1,0
            X_DRAWOBJ 0, 0
   
   
            // * the back propeller *
            // I move it to the tail -> that clears the above rotation
            X_MOVEMENT 10,-2.2,0
            X_SCALING .1, .1, .1
            // I rotate it to face the side
            X_ROTATION 90, 1,0,0
   
            X_ROTATION 2*spin, 0,0,1
            X_DRAWOBJ 0, 0
   
        X_POPMATRIX
    X_POPMATRIX
    SHOWSCREEN
WEND
Perfect scenario is pull back on the stick and point the helicopter up...now if you twist the joystick(rudder) it twists on the y axis...but the world y axis, not the heli Y axis...
is there a way around this, so the axis of control moves with the object in 3 dimensions??
#1566
Hmm
this is what i need to do to ONE part of the helicopter...rotations stop working properly when the part is rotated upsidedown or sideways!....btw this is just the body of the chopper, its not even the glass or the blades....

   X_MOVEMENT x,y,z
   X_ROTATION rz,-1,0,0
   X_ROTATION ry,0,-1,0
   X_ROTATION rx,0,0,1
   X_DRAWOBJ num, frame

It MUST rotate on 3 axis ..or helicopter wont fly
it twists, it rolls, it dives...all 3 axis can be spun 360 degrees to fly in any direction basically.
when you rotate on all 3, it gets ugly.
cool 3d helicopter btw!

change  this code to your helicopter body rotations and you will see what i mean about the rotations getting messed up...the axis stop controlling the correct axis of the object...
Code (glbasic) Select
  // first incline the thing
    X_ROTATION inclination, 0,0,1
    // then rotate it
    X_ROTATION rotation,    0,1,0
    X_ROTATION spin,    1,0,0  //  <-- JUST ADD THIS LINE
twist it up with the mouse when you run it, youll notice how the tail stops spinning and occasionally the body will instead rotate in a different unwanted direction.
#1567
GLBasic - en / ordered...
2006-Oct-13
Thats awesome!
Curious, ive never used a pocketpc, do you program the code on it, or do you use a home pc to do the dirty work
#1568
Sorry, my mail is not working so i have to post this bug report on the forums...

With each 3d object the heirarchy order of rotations are different.... the code is NOT universal. It doesnt work every object the same way! I added 3 x_popmatrix like you said, after the drawobj, but that doesnt help much... after  too many rotations, and after a while none of the rotations have been pushed correctly at all.

With almost a hundred hours of testing...i found the rotations dont truely stack, not matter how i code it, no matter how i place pushmatrix....in retrospect, x_movement pushes fine.

i suspect the problem is in the pushmatrix/popmatrix/rotation commands because 2 matrices do not "push" the stack the same way.
Theoratically in 3d you should only have to rotate any object a maximum of 3 times, if you push the stack 3 times, right? I ask because i need a 4th rotation for one of my objects, because 3 isnt sufficient.
#1569
GLBasic - en / ordered...
2006-Oct-12
Hey there kanati, welcome aboard.
Ive been reporting bugs to Gernot for years, hes used to it :)
Gernot is a good man, he has turned nothing into something, a magician.
You are using GLBASIC to program pocketpc?
#1570
To learn to program in GLBASIC requires a prerequisit of at LEAST basic algebra, and if you -know calculus, you will have a great time!

A knowledge of simple digital LOGIC is helpful too...for example AND, OR, XOR, XAND, IF, FOR-NEXT,WHILE-NEXT,ARRAY, etc, etc, etc

Secondly, you need to read the manual, and this is how you get to it:
1. Run GLBASIC
2. Start a new project!
3. Look at the top of the program compiler, there is a "?", click it.
4. Now select "Help"
5. A help window opens, and then select the Tab "Index"
You will find the manual there, and a complete listing of all the commands with examples.

Goodluck, Hemlos
ps. Post your errors and code here in the glbasic forums!
#1571
Black transparency is more asthetic than the pink, i dont like those edges.
If you want to make a black font, you can just use rgb(1,1,1)
As far as the pink edge thing with sprites, that becomes a very tedious process in changing the edges of sprites transparency...not to mention it ruins the quality of the original image.
I do like the idea of a black transparency, i think i did suggest that myself, a long time ago in the DiNGs days heh.
Perhaps you can make a command?
Code (glbasic) Select
SPRITE_TRANSPARENT Color#And make it reuseable in case color schemes or sprites change?
-hem
#1572
Here's some source code for simple 3D objects with textures.

A Sphere
Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  SPHERE  #=-
// ------------------------------------------------------------- //
FUNCTION CreateSphere: num, r, n, col
LOCAL i,j, theta1, theta2, theta3, pi
pi = ACOS(0)*2
IF r < 0 THEN r = -r
IF n < 3 THEN n = 3

X_OBJSTART num
FOR j=0 TO n/2-1

theta1 = j * 2*pi / n - pi/2;
theta2 = (j + 1) * 2*pi / n - pi/2;
FOR i=0 TO n
theta3 = i * 2*pi / n;
X_OBJADDVERTEX r*COS(theta2) * COS(theta3), r*SIN(theta2), r*COS(theta2) * SIN(theta3), i/n, 2*(j+1)/n, col
X_OBJADDVERTEX r*COS(theta1) * COS(theta3), r*SIN(theta1), r*COS(theta1) * SIN(theta3), i/n, 2*j/n, col
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION // n

A Cube - each side has the same texture
Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CREATECUBE  #=-
// ------------------------------------------------------------- //
FUNCTION CreateCube: num, sz, col
// Diese Variablen sind als LOCAL definiert:
// num, sz,
sz=sz/2
X_OBJSTART num
// Front Face
X_OBJADDVERTEX  sz, -sz,  sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz,  sz, 0, 0, col
X_OBJADDVERTEX  sz,  sz,  sz, 1, 1, col
X_OBJADDVERTEX -sz,  sz,  sz, 0, 1, col
X_OBJNEWGROUP
// Back Face
X_OBJADDVERTEX -sz,  sz, -sz, 1, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz, -sz, 0, 1, col
X_OBJADDVERTEX  sz, -sz, -sz, 0, 0, col
X_OBJNEWGROUP
// Top Face
X_OBJADDVERTEX -sz,  sz,  sz, 0, 0, col
X_OBJADDVERTEX -sz,  sz, -sz, 0, 1, col
X_OBJADDVERTEX  sz,  sz,  sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz, -sz, 1, 1, col
X_OBJNEWGROUP
// Bottom Face
X_OBJADDVERTEX  sz, -sz, -sz, 0, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 1, col
X_OBJADDVERTEX  sz, -sz,  sz, 0, 0, col
X_OBJADDVERTEX -sz, -sz,  sz, 1, 0, col
X_OBJNEWGROUP
// Right face
X_OBJADDVERTEX  sz,  sz, -sz, 1, 1, col
X_OBJADDVERTEX  sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz,  sz, 0, 1, col
X_OBJADDVERTEX  sz, -sz,  sz, 0, 0, col
X_OBJNEWGROUP
// Left Face
X_OBJADDVERTEX -sz, -sz,  sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz, -sz, 0, 0, col
X_OBJADDVERTEX -sz,  sz,  sz, 1, 1, col
X_OBJADDVERTEX -sz,  sz, -sz, 0, 1, col
X_OBJNEWGROUP
X_OBJEND

ENDFUNCTION // sz

A Clyinder and a Cone
Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CREATECYLINDER - also creates a cone if any radius = 0  #=-
// ------------------------------------------------------------- //
FUNCTION CreateCylinder: num, baseRadius, topRadius, height, slices, stacks, col
LOCAL da, r, dr, dz, x, y, z, i, j
LOCAL x1, y1, x2, y2
da = 360 / slices
dr = (topRadius-baseRadius) / stacks
dz = height / stacks
X_OBJSTART num
FOR i=0 TO slices-1
x1 = COS(i*da)
y1 = SIN(i*da)
x2 = COS((i+1)*da)
y2 = SIN((i+1)*da)
z = 0
r = baseRadius

// Bottom lid
IF baseRadius>0
X_OBJADDVERTEX 0, 0, 0,  .5, .5, col
X_OBJADDVERTEX x1*r, y1*r, 0, x1/2+.5, y1/2+.5, col
X_OBJADDVERTEX x2*r, y2*r, 0, x2/2+.5, y2/2+.5, col
X_OBJNEWGROUP
ENDIF
// side
FOR j=0 TO stacks
X_OBJADDVERTEX x2*r, y2*r, z, (i+1)/slices,  j/stacks, col
X_OBJADDVERTEX x1*r, y1*r, z,  i   /slices,  j/stacks, col
z = z+dz
r = r+dr
NEXT
// Top lid
IF topRadius>0
X_OBJNEWGROUP
X_OBJADDVERTEX x2*r, y2*r, height, x2/2+.5, y2/2+.5, col
X_OBJADDVERTEX x1*r, y1*r, height, x1/2+.5, y1/2+.5, col
X_OBJADDVERTEX 0, 0, height,  .5, .5, col
ENDIF
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION

A Torus (Donut)
Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CREATETORUS  #=-
//
// By Samuel R. Buss
// http://math.ucsd.edu/~sbuss/MathCG
// ------------------------------------------------------------- //
FUNCTION CreateTorus: num, MinorRadius, MajorRadius, NumWraps, NumPerWrap, TextureWrapVert, TextureWrapHoriz
// Diese Variablen sind als LOCAL definiert:
// x, y,
// Draw the torus
LOCAL i, di, j, wrapFrac, wrapFracTex, phi, thetaFrac, thetaFracTex, theta
LOCAL x, y, z, r
X_OBJSTART num
FOR di=0 TO NumWraps-1
FOR j=0 TO NumPerWrap
FOR i=di+1 TO di STEP -1
wrapFrac = MOD(j, NumPerWrap)/NumPerWrap
wrapFracTex = j/NumPerWrap
phi = 360*wrapFrac
thetaFrac = (MOD(i, NumWraps)+wrapFracTex)/NumWraps
thetaFracTex = (i+wrapFracTex)/NumWraps
theta = 360*thetaFrac
r = MajorRadius + MinorRadius*COS(phi)
x = SIN(theta)*r
z = COS(theta)*r
y = MinorRadius*SIN(phi)
X_OBJADDVERTEX x,y,z,  thetaFracTex*TextureWrapVert, wrapFracTex*TextureWrapHoriz, RGB(255, 255, 255)
NEXT
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION


#1573
Some simple helix variants:

Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CREATEHELIX  #=-
// Creates a helix aka. spiral object
// R1    : Raduis of Helix
// R2    : Radius of Helix Intersection
// Nu    : Number of elemtents along helix
// Nv    : Number of elements around intersection
// cycles: Number or spiral repetitions
// height: Complete length of the helix
// col   : Color of Helix-Material
// ------------------------------------------------------------- //
FUNCTION CreateHelix: num, R1, R2, Nu, Nv, cycles, height, col
LOCAL du, dv, u, v, x, y, z, tx, ty, q, nu, nv
du = cycles * 360 / Nu
dv = 360 / Nv

X_OBJSTART num
FOR i=0 TO Nu-1
u = i * du
FOR j=0 TO Nv-1
v = j * dv
FOR q = 0 TO 3
nu=0; nv=0 // Use next u/next v

IF q=0 OR q=3 THEN nu=1
IF q>1 THEN nv=1
nu = MOD(q, 2)
nv=INTEGER(q / 2)
qu = u+nu*du
qv = v+nv*dv

x = R1 * COS(qu) * (1 + COS(qv) * R2/R1)
z = R1 * SIN(qu) * (1 + COS(qv) * R2/R1)
y = SIN(qv)*R2 + qu*height/(360 * cycles)
tx = (i+nu)/Nu * cycles
ty = (j+nv)/Nv
X_OBJADDVERTEX x, y, z, tx, ty, col
NEXT
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION
Helicoid
Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CREATEHELICOID  #=-
// Creates a helicoid - minimal surface of a helix
// R1    : Raduis of Helix
// Nu    : Number of elemtents along helix
// Nv    : Number of elements around intersection
// cycles: Number or spiral repetitions
// height: Complete length of the helix
// col   : Color of Helix-Material
// ------------------------------------------------------------- //
FUNCTION CreateHelicoid: num, R1, Nu, Nv, cycles, height, col
LOCAL du, dv, u, v, x, y, z, tx, ty, q, nu, nv
du = cycles*360 / Nu
dv = R1 / Nv

X_OBJSTART num
FOR i=0 TO Nu-1
u = i * du
FOR j=0 TO Nv-1
v = j * dv
FOR q = 0 TO 3
nu=0; nv=0 // Use next u/next v

IF q=0 OR q=3 THEN nu=1
IF q>1 THEN nv=1
nu = MOD(q, 2)
nv=INTEGER(q / 2)
qu = u+nu*du
qv = v+nv*dv

x = qv * COS(qu)
z = qv * SIN(qu)
y = qu/(cycles*360) * height
tx = (i+nu)/Nu * cycles
ty = (j+nv)/Nv
X_OBJADDVERTEX x, y, z, tx, ty, col
NEXT
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION
QuoteORIGINAL POST BY GERNOT, I moved it from another thread. -Hemlos
#1574
What would be the point of a transparent font?!
#1575
Please update this topic Gernot, i wasnt sure if i should delete it or not because of the marketing promotion.