Мастер
Регистрация: 13.06.2011
Сообщений: 1,103
Написано 481 полезных сообщений (для 1,836 пользователей)
|
Ответ: Имитация водной поверхности.
Неа.
Может косяк только у меня происходит?

Include "xors3d.bb"
Global pivot,camera,mxs#,mys#,light
Global vectorx#,vectory#,vectorz#
xGraphics3D(640,480, 32,0, 0)
pivot=xCreatePivot()
camera = xCreateCamera(pivot)
light=xCreateLight()
xPositionEntity light,200,200,200
While(Not (xKeyHit(KEY_ESCAPE) Or xWinMessage("WM_CLOSE")))
xRenderWorld()
DrawSample()
Control(1.1,1)
xFlip()
Wend
End
Function Cross(x1#,y1#,z1#,x2#,y2#,z2#)
vectorx=y1*z2-y2*z1
vectory=z1*x2-z2*x1
vectorz=x1*y2-x2*y1
End Function
Function VecX()
Return vectorx#
End Function
Function VecY()
Return vectory#
End Function
Function VecZ()
Return vectorz#
End Function
Function RollVector(angle#,x1#,y1#,z1#,x2#,y2#,z2#)
; поворачивает вектор 1 в плоскости 1 и 2 векторов.
length#=Sqr#(x1#*x1#+y1#*y1#+z1#*z1#)
If Not (angle# Mod 90)=0 Then
d#=length#*Sin#(angle#)/Cos(angle)
; normal to 1 and 2
x0#=y1#*z2#-y2#*z1#
y0#=z1#*x2#-z2#*x1#
z0#=x1#*y2#-x2#*y1#
;normal to 1 and 0
x3#=y1#*z0#-y0#*z1#
y3#=z1#*x0#-z0#*x1#
z3#=x1#*y0#-x0#*y1#
lengthof3#=Sqr#(x3#^2+y3#^2+z3#^2)
x3#=x3#/lengthof3#
y3#=y3#/lengthof3#
z3#=z3#/lengthof3#
vectorx#=(x1#+x3#*d#)/Sqr#(1+Sin#(angle#)^2/Cos(angle)^2)
vectory#=(y1#+y3#*d#)/Sqr#(1+Tan#(angle#)^2)
vectorz#=(z1#+z3#*d#)/Sqr#(1+Tan#(angle#)^2)
Else
RuntimeError "RollVector(angle#,x1#,y1#,z1#,x2#,y2#,z2#) is too stupid for rolling vector on 90 degree, try something else."
EndIf
End Function
Function DrawSample()
;base point
x0#=Sin(MilliSecs()/40)*7
y0#=6*Sin(MilliSecs()/40)
z0#=Cos(MilliSecs()/40)*8+50
;first vector
x1#=Sin(MilliSecs()/20)*10
y1#=0
z1#=Cos(MilliSecs()/20)*10
x2#=y1-z1
y2#=-x1
z2#=x1
Cross(x1,y1,z1,x2,y2,z2)
xTFormNormal VecX(),VecY(),VecZ(),0,0
x3#=xTFormedX()*10
y3#=xTFormedY()*10
z3#=xTFormedZ()*10
RollVector(32.33,x3,y3,z3,x2,y2,z2)
x4#=VecX()
y4#=VecY()
z4#=VecZ()
xText 100,100,x4
xText 100,110,y4
xText 100,120,z4
;drawing
xCameraProject camera,x0,y0,z0
lx0#=xProjectedX()
ly0#=xProjectedY()
xCameraProject camera,x0+x1,y0+y1,z0+z1
lx1#=xProjectedX()
ly1#=xProjectedY()
xColor 255,0,0
xLine lx0,ly0,lx1,ly1
xText lx1,ly1,"First Vector"
xCameraProject camera,x0+x2,y0+y2,z0+z2
lx2#=xProjectedX()
ly2#=xProjectedY()
xColor 0,255,0
xLine lx0,ly0,lx2,ly2
xText lx2,ly2,"Second Vector"
xCameraProject camera,x0+x3,y0+y3,z0+z3
lx3#=xProjectedX()
ly3#=xProjectedY()
xColor 0,0,255
xLine lx0,ly0,lx3,ly3
xText lx3,ly3,"Third Vector"
xCameraProject camera,x0+x4,y0+y4,z0+z4
lx4#=xProjectedX()
ly4#=xProjectedY()
xColor 255,0,255
xLine lx0,ly0,lx4,ly4
xText lx4,ly4,"Forth Vector it's turned to 3 vector for 32.33 degree in plane of 3 and 2 vectors"
xColor 255,255,255
End Function
Function control(speed#,mousesensitivity#)
If xKeyDown(key_1) Then xWireframe(True) Else xWireframe(False)
xText(10, 10, "FPS: " + xGetFPS())
xText(10,30,"Trisinview: "+xTrisRendered ())
mxs#=mxs#+(xMouseXSpeed()/5.0)
mys#=mys#+(xMouseYSpeed()/5.0)
speed#=speed*xGetFPS()/1000
xRotateEntity (camera,mousesensitivity#*mys#,-mousesensitivity#*mxs#,0)
xMoveMouse xGraphicsWidth()/2,xGraphicsHeight()/2
If xKeyDown(17) Or xKeyDown(200) xMoveEntity camera,0,0,speed#
If xKeyDown(31) Or xKeyDown(208) xMoveEntity camera,0,0,-speed#
If xKeyDown(30) Or xKeyDown(203) xMoveEntity camera,-speed#,0,0
If xKeyDown(32) Or xKeyDown(205) xMoveEntity camera,speed#,0,0
xPositionEntity pivot,xEntityX#(camera,1),xEntityY#(camera,1),xEntityZ#(camera,1)
xPositionEntity camera,0,0,0
End Function
|