### Author Topic: Dynamic 3-d rendering in QB64  (Read 250 times)

#### Mrwhy

• Hero Member
• Posts: 2890
• My Dad called me Mr Why when I was 5.
##### Dynamic 3-d rendering in QB64
« on: February 18, 2011, 06:48:01 AM »
Now that we can generate SOUND on the fly within QB64, the next step is a movie.

A movie of a complex object gyrating around, or under the viewer's control!
Complex like a chaotic 3-D planetary orbit (dodging 4 suns in tetrahedral array) or 3500 bounces of light within a reflecting egg.

These objects (each still) can be calculated and drawn pretty fast! Or else we could store them on frames (arrays) and play them like a film.
We surely have animated displays already - or are they only for stick figures and wireframe objects?

Might we one day BLEND and edit our home movies in QB64?

Mr Why (why not!)

#### Mrwhy

• Hero Member
• Posts: 2890
• My Dad called me Mr Why when I was 5.
##### Re: Dynamic 3-d rendering in QB64
« Reply #1 on: March 12, 2013, 03:33:37 AM »
Whispering galleries.
Sound or light rays trapped inside a 3-d elliptical wall or mirror

Code: [Select]
`' rays of light trapped within an eliptical mirrorSCREEN 12VIEW (0, 0)-(639, 479)WINDOW (-1, -479 / 639)-(1, 479 / 639)GOSUB drawmirror' ******************* SET NUMBER OF REFLECTIONS IN LINE BELOW **************FOR i = 1 TO 335 'next 35 reflections    ' P0=P1, P1=P2    do reflection    x0 = x1: y0 = y1: z0 = z1    x1 = x2: y1 = y2: z1 = z2    gamma = -x1 * (x1 - x0) / a ^ 2 - y1 * (y1 - y0) / b ^ 2 - z1 * (z1 - z0) / c ^ 2    gamma = gamma / ((x1 / a ^ 2) ^ 2 + (y1 / b ^ 2) ^ 2 + (z1 / c ^ 2) ^ 2)    u1 = 2 * gamma * x1 / a ^ 2 + (x1 - x0)    v1 = 2 * gamma * y1 / b ^ 2 + (y1 - y0)    w1 = 2 * gamma * z1 / c ^ 2 + (z1 - z0)    ' calculation of x2,y2,z2    SECOND RAY strikes mirror at 2 at time t2    t2 = x1 * u1 * (b * c) ^ 2 + y1 * v1 * (c * a) ^ 2 + z1 * w1 * (a * b) ^ 2    t2 = -2 * t2    t2 = t2 / ((b * c * u1) ^ 2 + (a * c * v1) ^ 2 + (a * b * w1) ^ 2)    'PRINT "Value of t2 is"; t2    'PRINT "Values of x2,y2,z2 are:-"    x2 = x1 + t2 * ((x1 - x0) + 2 * gamma * x1 / a ^ 2)    y2 = y1 + t2 * ((y1 - y0) + 2 * gamma * y1 / b ^ 2)    z2 = z1 + t2 * ((z1 - z0) + 2 * gamma * z1 / c ^ 2)    'PRINT x2; y2; z2    t = 0    mo:    x = x1 + t * ((x1 - x0) + 2 * gamma * x1 / a ^ 2)    y = y1 + t * ((y1 - y0) + 2 * gamma * y1 / b ^ 2)    z = z1 + t * ((z1 - z0) + 2 * gamma * z1 / c ^ 2)    PSET (x, y), 8 + 7 * z / c    t = t + .001    IF t < t2 THEN GOTO mo NEXT iLOCATE 23, 1: PRINT "key"PRINT "of z/c"FOR i = 1 TO 15    LINE (-.99, -.68 + i / 75)-(-.91, -.68 + i / 75), iNEXT iLOCATE 25, 5: PRINT "+1"LOCATE 29, 5: PRINT "-1"ENDdrawmirror:a = 1: b = .7: c = .67FOR x = 0 TO 1 STEP 1 / 320    y = b * SQR(1 - (x / a) ^ 2)    PSET (x, y): PSET (x, -y)    PSET (-x, y): PSET (-x, -y)NEXT x'                            START AT FIRST point x0,y0,z0'select a point P          ' FIRST RAY begins at P=x0,y0,z0'************* SET STARTING POINT IN LINE BELOW **********x0 = .9: y0 = 0: z0 = .1CIRCLE (x0, y0), .005'************ SET POINT ON MIRROR FOR FIRST REFLECTION IN LINE BELOW ******y1 = .7: z1 = 0 ' therefore x1 is found:-qq = (y1 / b) ^ 2 + (z1 / c) ^ 2IF qq > 1 THEN PRINT "Not insude miirror": ENDx1 = SQR(1 - (y1 / b) ^ 2 - (z1 / c) ^ 2)PRINT "value of x0,y0,z0 inside the mirror is"; x0; y0; z0PRINT "value of x1,y1 on the mirror is"; x1; y1; z1'draw line from P to mirror            ' FIRST RAY'                from P0 to P1 on mirror is:FOR t = 0 TO 1 STEP .001    x = x0 + t * (x1 - x0)    y = y0 + t * (y1 - y0)    z = z0 + t * (z1 - z0)    PSET (x, y), 8 + 7 * z / cNEXT t'draw line from mirror     ' SECOND RAY = first reflection off mirrorgamma = -x1 * (x1 - x0) / a ^ 2 - y1 * (y1 - y0) / b ^ 2 - z1 * (z1 - z0) / c ^ 2gamma = gamma / ((x1 / a ^ 2) ^ 2 + (y1 / b ^ 2) ^ 2 + (z1 / c ^ 2) ^ 2)u1 = 2 * gamma * x1 / a ^ 2 + (x1 - x0)v1 = 2 * gamma * y1 / b ^ 2 + (y1 - y0)w1 = 2 * gamma * z1 / c ^ 2 + (z1 - z0)' calculation of x2,y2,z2    SECOND RAY strikes mirror at 2 at time t2t2 = x1 * u1 * (b * c) ^ 2 + y1 * v1 * (c * a) ^ 2 + z1 * w1 * (a * b) ^ 2t2 = -2 * t2t2 = t2 / ((b * c * u1) ^ 2 + (a * c * v1) ^ 2 + (a * b * w1) ^ 2)'PRINT "Value of t2 is"; t2'                from P1 is:t = 0mor:x = x1 + t * ((x1 - x0) + 2 * gamma * x1 / a ^ 2)y = y1 + t * ((y1 - y0) + 2 * gamma * y1 / b ^ 2)z = z1 + t * ((z1 - z0) + 2 * gamma * z1 / c ^ 2)PSET (x, y), 15 - 14 * z / ct = t + .0051IF t < t2 THEN GOTO mor'PRINT "Values of x2,y2,z2 are:-"x2 = x1 + t2 * ((x1 - x0) + 2 * gamma * x1 / a ^ 2)y2 = y1 + t2 * ((y1 - y0) + 2 * gamma * y1 / b ^ 2)z2 = z1 + t2 * ((z1 - z0) + 2 * gamma * z1 / c ^ 2)RETURN`