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.


Messages - Mithra

Pages: [1]
1
Programs / Re: Easy to use 3D Engine/Scene Manager using Map Triangle
« on: September 12, 2020, 10:52:03 pm »
Mithra -

Beautiful work. A project after my own heart! We have maybe a half-dozen (non-silent at least) members who dabble in proper 3D projections - this work is definitely a good asset for us. In fact, it may be worth opening a new sub-section on the forums that has to do with 3D without explicit _GL calls (i.e. MapTriangle only).

hey I'm glad it will help and contribute to the 3d community. I was able to dig up other models with textures to create a better example scene, the texture mapping seems to be working really well.

 
screenshot3.png

2
Programs / Easy to use 3D Engine/Scene Manager using Map Triangle
« on: September 12, 2020, 04:00:27 pm »
This is a 3d scene manager to easily display and move multiple 3d objects with texture mapping (supports wavefront obj files which you can create with most 3d programs like blender). It uses MAPTRIANGLE so theres no need to use OpenGL commands. It's great for games! Enjoy!

Description
A simple to use 3d library for qb64. Uses map triangle to display polygons. Simple shading on models. Load multiple 3d objects into the scene and move the camera. Supports loading of wavefront obj files and texture mapping

Download: https://github.com/creamcast/3D-Library-for-QB64

Functions and Subs:
* loadObj (filename AS STRING) load a WAVEFRONT obj file, returns the ID of the object as an integer to be used for the 3d commands
* createTexture (filename AS STRING, image_array() AS LONG) loads and creatures the texture for 3d objects. Provide an 1D array where the textures will be generated and stored
* DISPOBJ (objid AS INTEGER, texture() AS LONG) display the 3d object, provide an object id and texture array that was created using createTexture()
* SETOBJHIDDEN (objid AS INTEGER, n AS INTEGER) Set to 0 for object to be hidden, set to 1 to be rendered
* SETOBJX (objid AS INTEGER, x AS FLOAT) set object x coord on the 3d plane
* SETOBJY (objid AS INTEGER, y AS FLOAT) set object y coord on the 3d plane
* SETOBJZ (objid AS INTEGER, z AS FLOAT) set object z coord on the 3d plane
* SETOBJPOS (objid AS INTEGER, x AS FLOAT, y AS FLOAT, z AS FLOAT) set object x y z coord on the 3d plane
* SETOBJROT (objid AS INTEGER, xr AS FLOAT, yr AS FLOAT, zr AS FLOAT) set object x, y, z rotation
* ROTATEOBJX (objid AS INTEGER, deg AS FLOAT) rotate the object on its x axis by degrees
* ROTATEOBJY (objid AS INTEGER, deg AS FLOAT) rotate the object on its y axis by degrees
* ROTATEOBJZ (objid AS INTEGER, deg AS FLOAT) rotate the object on its z axis by degrees
* MOVEOBJX (objid AS INTEGER, n AS FLOAT) move object x position by n
* MOVEOBJY (objid AS INTEGER, n AS FLOAT) move object y position by n
* MOVEOBJZ (objid AS INTEGER, n AS FLOAT) move object z position by n
* SETOBJSCALE (objid AS INTEGER, x AS FLOAT, y AS FLOAT, z AS FLOAT) set object xyz scale. set all to 1 for original size.
* ROTATECAMX (deg AS FLOAT) rotate the camera x by degrees
* ROTATECAMY (deg AS FLOAT) rotate the camera y by degrees
* ROTATECAMZ (deg AS FLOAT) rotate the camera z by degrees
* MOVECAMX (n AS FLOAT) move cam x position
* MOVECAMY (n AS FLOAT) move cam y position
* MOVECAMZ (n AS FLOAT) move cam z position

You can also modify the object through the global variable g_objects:
TYPE OBJECT
    id AS INTEGER
    polygon_index_start AS INTEGER
    polygon_index_end AS INTEGER
    x AS FLOAT
    y AS FLOAT
    z AS FLOAT
    rotx AS FLOAT
    roty AS FLOAT
    rotz AS FLOAT
    scalex AS FLOAT
    scaley AS FLOAT
    scalez AS FLOAT
    billboard AS INTEGER
    hidden AS INTEGER
END TYPE


Sample Code:
Code: QB64: [Select]
  1. '$INCLUDE: '3d.bi'
  2.  
  3. DIM SHARED G_MAINSCREEN
  4. G_MAINSCREEN = NEWIMAGE(1024, 768, 32)
  5. SCREEN G_MAINSCREEN
  6.  
  7. DIM obj, obj2
  8. DIM tex(0) AS LONG
  9.  
  10. 'load and create texture and store in tex()
  11. createTexture "dice.png", tex()
  12.  
  13. 'load dice 3d model
  14. obj = loadObj("dice.obj")
  15.  
  16. 'load 3d model of an arm
  17. obj2 = loadObj("arm.obj")
  18.  
  19. 'place camera at -1000,0,1000 on 3d plane
  20. g_cam.x = -1000
  21. g_cam.z = 1000
  22. g_cam.y = 0
  23.  
  24. 'rotate camera on y axis by -45 degrees
  25. g_cam.roty = -45
  26.  
  27. 'move arm object to the left
  28. g_objects(2).x = -250
  29.  
  30.     CLS , RGB(0, 0, 0)
  31.    
  32.     'rotate objects every frame
  33.     ROTATEOBJX 1, -1
  34.     ROTATEOBJY 2, -2
  35.  
  36.     'fly into the objects at 45 degree angle
  37.     g_cam.x = g_cam.x + SIN(Deg2Rad(45)) * 3
  38.     g_cam.z = g_cam.z - COS(Deg2Rad(45)) * 3
  39.  
  40.     'display objects
  41.     DISPOBJ 1, tex()
  42.     DISPOBJ 2, tex()
  43.  
  44.     LIMIT 60
  45.     DISPLAY
  46.  
  47. '$INCLUDE: '3d.bm'
  48.  
  49.  

Screenshots:
 
screenshot1.png

 
screenshot2.png


Pages: [1]