I decide to make some screen savers to practice a few skills, but I've encountered to a really confusing thing!!!
I had no problems writing them until I decided to view the working screen saver on that little monitor in the Display Properties! (with /p argument)
I read a few articles and did a quick search on these forums and found some good points in them specialy a demo that was written by Nicholas and Jess (I think)
There was a function that could force DBPro programs to become CHILD! so I decided to translate it to DGSDK in C++, here is that function:
`function to create the preview window
Function _ScreenSaver_preview(parent As DWord)
Local user32 As Integer
Local Hwnd As DWord
Local temp As DWord
Local x As Integer
Local y As Integer
Local memnum As Integer
Set Window On
Set Window Layout 0,0,0
user32 = 1
memnum = 1
Load DLL "user32.dll",1
Hwnd = Call DLL(1,"GetActiveWindow")
temp = Call DLL(1,"SetParent",Hwnd,parent)
Make Memblock memnum,20
Call Dll user32,"GetWindowRect",parent,Get Memblock Ptr(memnum)
x = MemBlock DWord(memnum,0)
y = MemBlock DWord(memnum,4)
print x
print y
wait key
Set Display Mode 153,113,32
Call DLL user32,"MoveWindow",x,y,153,113,1
EndFunction
and here is the full code (Nice one):
`constants for "arena" size and line movement speed
#constant ARENA_SIZE 10.0
#constant LINE_SPEED 10.0
CURVE_COUNT = 6
CURVE_SEGMENTS = 16
dim Curves(CURVE_COUNT) as CurveData
`Set up for getting Saver info
command As String
parent As String
command = CL$()
print command
wait key
parent = Right$(command,Len(command) - 3)
command = Lower$(Left$(command,2))
`print command
`print CL$()
`print parent
`print val(parent)
`wait key
`If command = "/c" then ...
If command = "/s" or command = "" then _normal()
If command = "/p" then _ScreenSaver_preview(Val(parent))
`setup common display stuff
autocam off
sync off : sync rate 0
backdrop on
color backdrop 0
randomize timer()
position camera 0, 0, ARENA_SIZE * 2.0
point camera 0,0,0
`create curves
gosub START
`Main loop setup
frameTime# = 1.0
startTime = timer()
looping = 1
`main loop
while looping
`if in not in preview mode, then check the mouse and keyboard
if command <> "/p" then if (MouseMoveX() <> 0) Or (MouseMoveY() <> 0) Or (MouseMoveZ() <> 0) Or (ScanCode() <> 0) then looping = 0
`update frametime info used for timer based movement
frameTime# = (frameTime# * 0.8) + ((timer() - startTime) * 0.2)
startTime = timer()
`call routine to animate curves
gosub ANIMATE_CURVES
endwhile
hide window
end
`Curve movement
ANIMATE_CURVES:
for i = 1 to CURVE_COUNT
ft# = frameTime# * 0.001
inc Curves(i).A.Pos.X#, Curves(i).A.Vel.X# * ft#
inc Curves(i).A.Pos.Y#, Curves(i).A.Vel.Y# * ft#
inc Curves(i).A.Pos.Z#, Curves(i).A.Vel.Z# * ft#
inc Curves(i).B.Pos.X#, Curves(i).B.Vel.X# * ft#
inc Curves(i).B.Pos.Y#, Curves(i).B.Vel.Y# * ft#
inc Curves(i).B.Pos.Z#, Curves(i).B.Vel.Z# * ft#
inc Curves(i).C.Pos.X#, Curves(i).C.Vel.X# * ft#
inc Curves(i).C.Pos.Y#, Curves(i).C.Vel.Y# * ft#
inc Curves(i).C.Pos.Z#, Curves(i).C.Vel.Z# * ft#
inc Curves(i).D.Pos.X#, Curves(i).D.Vel.X# * ft#
inc Curves(i).D.Pos.Y#, Curves(i).D.Vel.Y# * ft#
inc Curves(i).D.Pos.Z#, Curves(i).D.Vel.Z# * ft#
if (Curves(i).A.Pos.X# > ARENA_SIZE AND Curves(i).A.Vel.X# > 0) OR (Curves(i).A.Pos.X# < -ARENA_SIZE AND Curves(i).A.Vel.X# < 0) then Curves(i).A.Vel.X# = -Curves(i).A.Vel.X#
if (Curves(i).A.Pos.Y# > ARENA_SIZE AND Curves(i).A.Vel.Y# > 0) OR (Curves(i).A.Pos.Y# < -ARENA_SIZE AND Curves(i).A.Vel.Y# < 0) then Curves(i).A.Vel.Y# = -Curves(i).A.Vel.Y#
if (Curves(i).A.Pos.Z# > ARENA_SIZE AND Curves(i).A.Vel.Z# > 0) OR (Curves(i).A.Pos.Z# < -ARENA_SIZE AND Curves(i).A.Vel.Z# < 0) then Curves(i).A.Vel.Z# = -Curves(i).A.Vel.Z#
if (Curves(i).B.Pos.X# > ARENA_SIZE AND Curves(i).B.Vel.X# > 0) OR (Curves(i).B.Pos.X# < -ARENA_SIZE AND Curves(i).B.Vel.X# < 0) then Curves(i).B.Vel.X# = -Curves(i).B.Vel.X#
if (Curves(i).B.Pos.Y# > ARENA_SIZE AND Curves(i).B.Vel.Y# > 0) OR (Curves(i).B.Pos.Y# < -ARENA_SIZE AND Curves(i).B.Vel.Y# < 0) then Curves(i).B.Vel.Y# = -Curves(i).B.Vel.Y#
if (Curves(i).B.Pos.Z# > ARENA_SIZE AND Curves(i).B.Vel.Z# > 0) OR (Curves(i).B.Pos.Z# < -ARENA_SIZE AND Curves(i).B.Vel.Z# < 0) then Curves(i).B.Vel.Z# = -Curves(i).B.Vel.Z#
if (Curves(i).C.Pos.X# > ARENA_SIZE AND Curves(i).C.Vel.X# > 0) OR (Curves(i).C.Pos.X# < -ARENA_SIZE AND Curves(i).C.Vel.X# < 0) then Curves(i).C.Vel.X# = -Curves(i).C.Vel.X#
if (Curves(i).C.Pos.Y# > ARENA_SIZE AND Curves(i).C.Vel.Y# > 0) OR (Curves(i).C.Pos.Y# < -ARENA_SIZE AND Curves(i).C.Vel.Y# < 0) then Curves(i).C.Vel.Y# = -Curves(i).C.Vel.Y#
if (Curves(i).C.Pos.Z# > ARENA_SIZE AND Curves(i).C.Vel.Z# > 0) OR (Curves(i).C.Pos.Z# < -ARENA_SIZE AND Curves(i).C.Vel.Z# < 0) then Curves(i).C.Vel.Z# = -Curves(i).C.Vel.Z#
if (Curves(i).D.Pos.X# > ARENA_SIZE AND Curves(i).D.Vel.X# > 0) OR (Curves(i).D.Pos.X# < -ARENA_SIZE AND Curves(i).D.Vel.X# < 0) then Curves(i).D.Vel.X# = -Curves(i).D.Vel.X#
if (Curves(i).D.Pos.Y# > ARENA_SIZE AND Curves(i).D.Vel.Y# > 0) OR (Curves(i).D.Pos.Y# < -ARENA_SIZE AND Curves(i).D.Vel.Y# < 0) then Curves(i).D.Vel.Y# = -Curves(i).D.Vel.Y#
if (Curves(i).D.Pos.Z# > ARENA_SIZE AND Curves(i).D.Vel.Z# > 0) OR (Curves(i).D.Pos.Z# < -ARENA_SIZE AND Curves(i).D.Vel.Z# < 0) then Curves(i).D.Vel.Z# = -Curves(i).D.Vel.Z#
curveOffset = i * 100
for j = 0 to CURVE_SEGMENTS-1
t# = j * 1.0 / CURVE_SEGMENTS
x1# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y1# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z1# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
t# = (j+1.0) * 1.0 / CURVE_SEGMENTS
x2# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y2# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z2# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
obj = j + curveOffset
set vector3 1, x1# - x2#, y1# - y2#, z1# - z2#
position object obj, x1#, y1#, z1#
point object obj, x2#, y2#, z2#
scale object obj, 100.0, 100.0, 100.0 * length vector3(1)
next j
next i
return
`Initialisation sequence
START:
temp = make vector3(1)
for i = 1 to CURVE_COUNT + 1
curveOffset = i * 100
if i <= CURVE_COUNT
`SET RANDOM START POINT
Curves(i).A.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).A.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).A.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).B.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).B.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).B.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).C.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).C.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).C.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).D.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).D.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).D.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
`SET RANDOM VELOCITY
Curves(i).A.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).A.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).A.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).B.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).B.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).B.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).C.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).C.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).C.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).D.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).D.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).D.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).col = rgb(rnd(255),rnd(255),rnd(255))
for j = 0 to CURVE_SEGMENTS
obj = j + curveOffset
if j < CURVE_SEGMENTS
t# = j * 1.0 / CURVE_SEGMENTS
x1# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y1# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z1# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
t# = (j+1.0) * 1.0 / CURVE_SEGMENTS
x2# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y2# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z2# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
if object exist(obj) then delete object obj
set vector3 1, x1# - x2#, y1# - y2#, z1# - z2#
make object triangle obj, 0,0,0, 0,0,0, 0, 0, 1.0
scale object obj, 100.0, 100.0, 100.0 * length vector3(1)
position object obj, x1#, y1#, z1#
point object obj, x2#, y2#, z2#
set object wireframe obj,1
set object emissive obj, Curves(i).col
`color object obj, Curves(i).col
else
if object exist(obj) then delete object obj
endif
next j
else
for j = 0 to CURVE_SEGMENTS-1
obj =j + curveOffset
if object exist(obj) then delete object obj
next j
endif
next i
return
`function to create a "normal" window
Function _normal()
`=== Set Resolution =======================================
If Check Display Mode(1024,768,32) = 1 Then Set Display Mode 1024,768,32
EndFunction
`function to create the preview window
Function _ScreenSaver_preview(parent As DWord)
Local user32 As Integer
Local Hwnd As DWord
Local temp As DWord
Local x As Integer
Local y As Integer
Local memnum As Integer
Set Window On
Set Window Layout 0,0,0
user32 = 1
memnum = 1
Load DLL "user32.dll",1
Hwnd = Call DLL(1,"GetActiveWindow")
temp = Call DLL(1,"SetParent",Hwnd,parent)
Make Memblock memnum,20
Call Dll user32,"GetWindowRect",parent,Get Memblock Ptr(memnum)
x = MemBlock DWord(memnum,0)
y = MemBlock DWord(memnum,4)
print x
print y
wait key
Set Display Mode 153,113,32
Call DLL user32,"MoveWindow",x,y,153,113,1
EndFunction
`bezier function for curves
function CubicBezier(A#, B#, C#, D#, T#)
invT# = 1.0 - T#
result# = (A# * invT# * invT# * invT#) + (3.0 * B# * invT# * invT# * T#) + (3.0 * C# * invT# * T# * T#) + (D# * T# * T# * T#)
endfunction result#
`coordinate type
type Coord
X#
Y#
Z#
endtype
`type for storing a point on the bezier curve's info
type PointData
Pos as Coord
Vel as Coord
endtype
`type for storing whole curve info
type CurveData
A as PointData
B as PointData
C as PointData
D as PointData
col as DWORD
endtype
I tried to convert that function to DGSDK but my trial and errors couldn't do anything really...
here is the code so far:
EDITED... The code was very crappy... because I didn't sleep enough
as you can see I've tried a few variable Type, functions, etc. some of the functions (DGSDK's) didn't work properly, so I've used their C++ equal.
I think there is something wrong with the "parent" variable that I can't figure out?
Can someone help me out please?
Thanks!
[EDIT]The code was very crappy, so I removed it for now[/EDIT]