@Try, referring to that problem, I had to find out how to feed an object's position, rotation and scale to a shader.
It has to be in certain order and very tricky thing.
Well, the code below worked for me. I hope that you, Evolved or anyone find it useful:
Rem Project: calculos matrix4
Rem Created: 21/09/2005 21:23:51
Rem ***** Main Source File *****
remstart
THIS EXAMPLE TRIES TO SHOW HOW TO FEED A SHADER WITH THE SCALE, POSITION AND ROTATION
OF AN OBJECT.
ASSUMPTIONS:
- THE SHADER EXIST, AND RECEIVES 2 MATRIX4 AND 1 VECTOR3:
"matWorldView" that is the WorldView matrix4
"matWorldViewProj" that is the WorldViewProjection matrix4
"lightPos" that is the light vector3, MUST BE USED AS A FEEDED VARIABLE IN THE SHADER
- THE SHADER IS NOT AUTOMATICALLY FEEDED FROM THE SYSTEM WITH SHADER NAMED CONSTANTS
- THE OBJECT WITH SHADER APPLIED IS "i" AND IT'S COORDINATES ARE
object_X#(i), object_Y#(i), object_Z#(i)
- THE CAMERA IS ALWAYS AT 0,0,0
- SORRY, JUST CODE, NO SHADER WITH THIS EXAMPLE
remend
rem just some constants
Effect_number = 1
#constant WORLDVIEWPROJ_M = 1
#constant WORLD_M = 2
#constant PROJ_M = 3
#constant VIEW_M = 4
rem make auxiliar vector
#constant vector3aux=500
null=make vector3(vector3aux)
rem more constants for shaders
#constant CTEMP 999
#constant CXROTATE 998
#constant CYROTATE 997
#constant CZROTATE 996
#constant CROTATION 995
#constant CDEGTORAD ( 3.14159 / 180.0 )
rem matrix for rotations
null=make matrix4(CXROTATE)
null=make matrix4(CYROTATE)
null=make matrix4(CZROTATE)
null=make matrix4(CROTATION)
null=make matrix4(CTEMP)
rem make matrix for view matrix4
null = make matrix4(VIEW_M)
rem matrix for shader feed
null = make matrix4(WORLDVIEWPROJ_M) :rem World * View * Projection matrix
null = make matrix4(WORLD_M)
null = make matrix4(PROJ_M)
REM FROM HERE IN EVERY LOOP:
view matrix4 VIEW_M
WORLD MATRIX4 WORLD_M
projection matrix4 PROJ_M
rem ROTATION HERE ***********************
set vector3 vector3aux , 1,0,0
BUILD ROTATION AXIS MATRIX4 CXROTATE, vector3aux, object angle x(i) * CDEGTORAD
set vector3 vector3aux , 0,1,0
BUILD ROTATION AXIS MATRIX4 CYROTATE, vector3aux, object angle y(i) * CDEGTORAD
set vector3 vector3aux , 0,0,1
BUILD ROTATION AXIS MATRIX4 CZROTATE, vector3aux, object angle z(i) * CDEGTORAD
rem multiply all 3 rotation matrices together
multiply matrix4 CROTATION, CXROTATE, CYROTATE
multiply matrix4 CROTATION, CROTATION, CZROTATE
rem SCALE HERE ***********************
scale matrix4 WORLD_M, object size x(i), object size y(i), object size z(i)
rem APPLY ROTATION AFTER SCALING
multiply matrix4 WORLD_M, WORLD_M, CROTATION
rem POSITION HERE ***********************
translate matrix4 CTEMP, object_X#(i), object_Y#(i), object_Z#(i)
multiply matrix4 WORLD_M, WORLD_M, CTEMP
rem apply view matrix
MULTIPLY MATRIX4 WORLDVIEWPROJ_M, WORLD_M, VIEW_M
rem FEED SHADER's MATRIX HERE
set effect constant Matrix Effect_number, "matWorldView", WORLDVIEWPROJ_M
MULTIPLY MATRIX4 WORLDVIEWPROJ_M, WORLDVIEWPROJ_M, PROJ_M
set effect constant Matrix Effect_number, "matWorldViewProj", WORLDVIEWPROJ_M
rem FEED LIGHT POSITION TO SHADER
set vector3 vector3aux, lightx#, lighty#, lightz#
set effect constant vector Effect_number, "lightPos", vector3aux
rem that's all
It comes with no shader, just the DBPro code for manipulating and creating the world, projection and view matrix according to an object position, rotation and scale.
Also note that camera is considered to be always at 0,0,0 (that's what I use all the time)