Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D Terrain
#12
(01-09-2023, 06:53 PM)OldMoses Wrote:
(01-09-2023, 05:26 PM)james246 Wrote: Using vector math would really open up some possibilities.   Definitely over my head but this seems like the way to go for a good 3d physics engine.


You already are, truth be told. The only difference is your code handles the vectors as individual x/y/z components.

The main possibility is less overall typing and more succinct code. It's just a matter of thinking of those individual components as whole objects and writing some subroutines to handle the individual components of those objects.

I notice your SUB processterrain is doing just that. In the DO...LOOP, it's mostly scalar multiplications of, and additions to vectors, which could be SUB'ed out to something that would handle the grunt work. All that would be needed is a vector TYPE, say...

TYPE Vector
    x AS SINGLE
    y AS SINGLE
    z AS SINGLE
END TYPE

A subroutine to do the multiplications
SUB MultVec (v as Vector, m AS SINGLE)
    v.x = v.x * m
    v.y = v.y * m
    v.z = v.z * m
END SUB

Then just DIM AS Vector vec1, vec2, vec3 '  in the SUB

Suddenly:
 x1 = x1 * scale1: y1 = y1 * scale1: 'z1 = z1 * scale1
 x2 = x2 * scale1: y2 = y2 * scale1: 'z2 = z2 * scale1
 x3 = x3 * scale1: y3 = y3 * scale1: 'z3 = z3 * scale1

becomes:
MultiVec vec1, scale1
MultiVec vec2, scale1
MultiVec vec3, scale1

Then you can do the same to the vector additions. Change shx, shy & shz to a single vector type: sh.x, sh.y & sh.z. Write a sub to add two vectors together:

SUB AddVec (v1 as Vector, v2 AS Vector)
    v1.x = v1.x + v2.x
    v1.y = v1.y + v2.y
    v1.z = v1.z + v2.z
END SUB

Now:
x1 = x1 + shx: y1 = y1 + shy: z1 = z1 + shz
x2 = x2 + shx: y2 = y2 + shy: z2 = z2 + shz
x3 = x3 + shx: y3 = y3 + shy: z3 = z3 + shz

becomes:
AddVec vec1, sh
AddVec vec2, sh
AddVec vec3, sh

A little more upfront work for a big payoff in short code, more descriptive variable naming, etc.

Excellent advice.   I didn't realize I was this close to something useful - it was just an experiment to see if I could establish some random uneven terrain and to use a single image for this terrain map.  I'll update the code - Thank you!
Reply


Messages In This Thread
3D Terrain - by james2464 - 01-08-2023, 09:24 PM
RE: 3D Terrain - by mnrvovrfc - 01-09-2023, 08:29 AM
RE: 3D Terrain - by james2464 - 01-09-2023, 05:13 PM
RE: 3D Terrain - by OldMoses - 01-09-2023, 12:12 PM
RE: 3D Terrain - by james2464 - 01-09-2023, 05:26 PM
RE: 3D Terrain - by OldMoses - 01-09-2023, 06:53 PM
RE: 3D Terrain - by james2464 - 01-09-2023, 08:17 PM
RE: 3D Terrain - by MasterGy - 01-09-2023, 03:24 PM
RE: 3D Terrain - by james2464 - 01-09-2023, 05:28 PM
RE: 3D Terrain - by MasterGy - 01-09-2023, 06:31 PM
RE: 3D Terrain - by james2464 - 01-09-2023, 06:40 PM
RE: 3D Terrain - by MasterGy - 01-09-2023, 06:56 PM
RE: 3D Terrain - by james2464 - 01-09-2023, 08:20 PM
RE: 3D Terrain - by james2464 - 01-10-2023, 06:30 PM
RE: 3D Terrain - by james2464 - 01-11-2023, 07:50 PM
RE: 3D Terrain - by bplus - 01-11-2023, 08:07 PM
RE: 3D Terrain - by james2464 - 01-11-2023, 08:46 PM
RE: 3D Terrain - by james2464 - 01-11-2023, 09:53 PM
RE: 3D Terrain - by bplus - 01-11-2023, 10:34 PM
RE: 3D Terrain - by james2464 - 01-11-2023, 11:51 PM
RE: 3D Terrain - by james2464 - 01-12-2023, 04:08 AM
RE: 3D Terrain - by bplus - 01-12-2023, 05:33 AM
RE: 3D Terrain - by james2464 - 01-12-2023, 04:34 PM
RE: 3D Terrain - by MasterGy - 01-12-2023, 04:57 PM
RE: 3D Terrain - by james2464 - 01-12-2023, 05:37 PM
RE: 3D Terrain - by OldMoses - 01-13-2023, 12:11 AM



Users browsing this thread: 1 Guest(s)