Hi Friends,
You'll find a bit of a hack & slash below, written & sourced by myself a few years back. It should hopefully compile (no doubt there's some Matrix1 Utils hiding in my code) on copy & paste, and you'll see a few camera tricks at play in the resulting EXE.
A bit of background on where I'm at. I'd like to move on from DBPro Matrix features, mainly due to the fact they you can't recover them during a media reload operation, which ultimately causes any DBPro application that's using a Matrix to crash upon reload.
Now, my question; can those of you familiar with
any of the 3rd Party terrain plugins for DBpro, create a similar or identical scene, which allows users or objects to select "squares" on mouse over the terrain object, allowing the change in colour of that terrain square? Further to this, it's not just a simple colour change, but rather a texture changing, that red/green is actually a generated image that slots on to each Matrix tile.
If you think or know that this can be achieved, would you care to post an example? Feel free to modify the code below, but note that I don't own any terrain plugins so won't be able to compile your example, so please include an example EXE too in your reply.
Cheers in advance,
BFM
PS: Mind your step in my code dump!
`Terrain Question - Best alternative to Matrix commands
Position window get dbpro window(), 100,100
Gosub Sub_Matrix_Ini
Gosub Sub_Mouse_Ini
Gosub Sub_Camera_Ini
Gosub Sub_Object_Ini
Gosub Sub_Matrix_Prep
Sync on
Sync rate 60
do
Line CA(1).Win_Left,CA(1).Win_Top, CA(1).Win_Right, CA(1).Win_Bottom
Line CA(1).Win_Left,CA(1).Win_Bottom, CA(1).Win_Right,CA(1).Win_Top
Mouse.PosX = MouseX()
Mouse.PosY = MouseY()
Mouse.Cam = D3D_Cursor_In_Camera(0,3)
If Mouse.Cam < 0
Mouse.Cam = 0
ENDIF
`Find the location of the mouse in 3D space on the matrix's level
Set current camera Mouse.Cam
Mouse.Active_Object = Pick Object(Mouse.PosX, Mouse.PosY, 1,2)
If Mouse.Active_Object = 1 or Mouse.Active_Object = 2
`Get those coordinates
tempx1=get pick vector x()+CA(Mouse.Cam).PosX
tempz1=get pick vector z()+CA(Mouse.Cam).PosZ
For testing = 1 to 1
tempx=(tempx1)/MA(testing).Tile_Size_X
tempz=(tempz1)/MA(testing).Tile_Size_Y
if tempx<MA(testing).Tile_Count_X and tempz<MA(testing).Tile_Count_Y and tempx>-1 and tempz>-1
set matrix tile testing,tempx,tempz,2
update matrix testing
endif
next testing
endif
Position Object 4, tempx1,5,tempz1
` Position Object 5, tempx1,5,tempz1
If upkey() = 1
Dec CA(1).Win_Top, 1
Dec CA(1).Win_Bottom, 1
ENDIF
If downkey() = 1
Inc CA(1).Win_Top, 1
Inc CA(1).Win_Bottom, 1
ENDIF
If leftkey() = 1
Dec CA(1).Win_left, 1
Dec CA(1).Win_right, 1
ENDIF
If rightkey() = 1
Inc CA(1).Win_left, 1
Inc CA(1).Win_right, 1
ENDIF
If keystate(44)
dec CA(1).PosX, 2
inc CA(1).PosY, 2
dec CA(1).PosZ, 2
endif
If keystate(45)
inc CA(1).PosX, 2
dec CA(1).PosY, 2
inc CA(1).PosZ, 2
endif
Set Camera View CA(1).ID, CA(1).Win_Left, CA(1).Win_Top, CA(1).Win_Right,CA(1).Win_Bottom
Position Camera CA(1).ID, CA(1).PosX, CA(1).PosY, CA(1).PosZ
Set cursor 0,0
ink rgb(255,255,255),rgb(255,0,255)
Print "Arrow keys, and Z/X darlings."
Sync
Loop
End
Sub_Camera_Ini:
Type TCamera
ID as Integer
PosX as Integer
PosY as Integer
PosZ as Integer
Win_Left as Integer
Win_Top as Integer
Win_Right as Integer
Win_Bottom as Integer
PointX as Integer
PointY as Integer
PointZ as Integer
Aspect as Float
BackDrop_Colour as Integer
Range_Near as Float
Range_Far as Float
Fov as Float
Endtype
REM CA - Camera Array
Dim CA(10) As TCamera
CA(0).ID = 0
CA(1).ID = 1
Rem Camera Position Array
CA(0).PosX = 0
CA(0).PosY = 250
CA(0).PosZ = -50
CA(1).PosX = -1500
CA(1).PosY = 1500
CA(1).PosZ = -1500
Rem Camera View Port Array
CA(0).Win_Left = 0
CA(0).Win_Top = 0
CA(0).Win_Right = 1280
CA(0).Win_Bottom = 900
CA(1).Win_Left = 400
CA(1).Win_Top = 620
CA(1).Win_Right = 800
CA(1).Win_Bottom = 900
Rem Camera Point Array
CA(0).PointX = 0
CA(0).PointY = 0
CA(0).PointZ = 50
CA(1).PointX = 0
CA(1).PointY = 0
CA(1).PointZ = 0
Rem Camera Aspect
CA(0).Aspect = (CA(0).Win_Right-CA(0).Win_Left)/(CA(0).Win_bottom - CA(0).Win_Top)
CA(1).Aspect = (CA(1).Win_Right-CA(1).Win_Left)/(CA(1).Win_bottom - CA(1).Win_Top)
CA(0).FOV = 90
CA(1).FOV = 1
CA(0).Range_Near = 0.0
CA(0).Range_Far = 1000.0
CA(1).Range_Near = 2000
CA(1).Range_Far = 5000.0
Set Display Mode 1200, 900, 32
Autocam off
REM Camera Creation & Setup
For Make_Camera = 1 to 1
Make Camera Make_Camera
Next Make_Camera
For Setup_Camera = 0 to 1
Position Camera CA(Setup_Camera).ID, CA(Setup_Camera).PosX, CA(Setup_Camera).PosY, CA(Setup_Camera).PosZ
Set Camera View CA(Setup_Camera).ID, CA(Setup_Camera).Win_Left ,CA(Setup_Camera).Win_Top ,CA(Setup_Camera).Win_Right ,CA(Setup_Camera).Win_Bottom
Point Camera CA(Setup_Camera).ID, CA(Setup_Camera).PointX, CA(Setup_Camera).PointY, CA(Setup_Camera).PointZ
Backdrop off CA(Setup_Camera).ID
Set Camera Aspect CA(Setup_Camera).ID, CA(Setup_Camera).Aspect
Set Camera Range CA(Setup_Camera).ID, CA(Setup_Camera).Range_Near, CA(Setup_Camera).Range_Far
Set Camera Fov CA(Setup_Camera).ID, CA(Setup_Camera).FOV
Color Backdrop CA(Setup_Camera).ID, CA(Setup_Camera).Backdrop_Colour
Next Setup_Camera
Backdrop on 0
return
end
Sub_Matrix_Ini:
Type TMatrix
ID as integer
Size_X as integer
Size_Y as integer
Tile_Count_X as integer
Tile_Count_Y as integer
Tile_Size_X as integer
Tile_Size_Y as integer
PosX as Integer
PosY as Integer
PosZ as Integer
endtype
DIM MA(10) As TMatrix
MA(1).ID = 1
MA(1).Size_X = 100
MA(1).Size_Y = 100
MA(1).Tile_Count_X = 10
MA(1).Tile_Count_Y = 10
MA(1).Tile_Size_X = MA(1).Size_X/MA(1).Tile_Count_X
MA(1).Tile_Size_Y = MA(1).Size_Y/MA(1).Tile_Count_Y
MA(1).PosX = (MA(1).Size_X / 2) * -1
MA(1).PosY = 0
MA(1).PosZ = (MA(1).Size_Y / 2) * -1
MA(2).ID = 2
MA(2).Size_X = 50
MA(2).Size_Y = 50
MA(2).Tile_Count_X = 5
MA(2).Tile_Count_Y = 5
MA(2).Tile_Size_X = MA(2).Size_X/MA(2).Tile_Count_X
MA(2).Tile_Size_Y = MA(2).Size_Y/MA(2).Tile_Count_Y
MA(2).PosX = 100
MA(2).PosY = 0
MA(2).PosZ = 100
return
end
Sub_Mouse_Ini:
Type TMouse
PosX as Integer
PosY as Integer
Click as Integer
Cam as Integer
Cam_Cache as Integer
Active_Object as Integer
Endtype
Global Mouse as TMouse
return
End
Sub_Object_Ini:
`Plane object (is necessary for pick object to work correctly)
make object plane 1,MA(1).Size_X,MA(1).Size_Y
position object 1,MA(1).Size_X/2,-0.5,MA(1).Size_Y/2
xrotate object 1,90
fix object pivot 1
set object mask 1, %0000
make object plane 2,MA(2).Size_X,MA(2).Size_Y
position object 2,200, -0.05, 200
xrotate object 2,90
fix object pivot 2
set object mask 2, %0000
Make Object Cube 6, 10 : Position object 6, 0,0,0 : Rotate Object 6, 0,0,45
Make Object Sphere 7, 10 : Position Object 7, -50, 0, 50
Make Object Cone 4, 10 : Position Object 4, 0,0,0 : XRotate Object 4, 180
`Make Object Plane 5, 50, 50 : Position Object 5, 0,0,0 : XRotate Object 5, 90 : Set Alpha Mapping on 5, 50; set object mask 5, %0001
return
Sub_Matrix_Prep:
ink rgb(0,255,0),0
box 1,1,10,10
ink rgb(255,0,0),0
box 11,1,20,10
get image 1,0,0,20,10,1
Make Matrix MA(1).ID,MA(1).Size_X,MA(1).Size_Y,MA(1).Tile_Count_X,MA(1).Tile_Count_Y
Prepare Matrix Texture MA(1).ID, 1, 2,1
Fill Matrix MA(1).ID, 0, 1
Update Matrix MA(1).ID
`Make Matrix MA(2).ID,MA(2).Size_X,MA(2).Size_Y,MA(2).Tile_Count_X,MA(2).Tile_Count_Y
`Prepare Matrix Texture MA(2).ID, 1, 2,1
`Position Matrix MA(2).ID, 200,0,200
`Fill Matrix MA(2).ID, 0, 1
`Update Matrix MA(2).ID
return
end