[bb] Jellyfish Animation by Mr Snidesmin [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Jellyfish Animation
Author : Mr Snidesmin
Posted : 1+ years ago

Description : My first ever 3d animation. . .  (just about sort of)

I would like to be able to display at least 20 of these at a time in a game with loads of other stuff going on, but I've no idea how to store the animation, replay etc quickly.

Someone help me please! :O)


Code :
Code (blitzbasic) Select
Global JellyParam#
Global WaveParam1#
Global WaveParam2#
Global WaveParam3#


Local fps%
Local fpscount%
Local millistop%
Local millis%


Graphics3D 800, 600

;create world:
Global GlobalLight% = CreateLight()
RotateEntity GlobalLight, 70, 45, 45
Global GlobalCamera% = CreateCamera()
LightColor GlobalLight, 255,255,255
AmbientLight 100,120,255
PositionEntity GlobalCamera, 4, 0, 0
CameraClsColor GlobalCamera, 0,50,90

;create jellyfish (mshJellyBase is just used to store original vert positions)
Global mshJellyBase% = CreateMesh() ;LoadMesh("jelly.3ds")
For n# = 0 To 1 Step 0.2
mshtmp = CreateSphere(8)
ScaleMesh mshtmp, 1/(1+10*n), 0.35, 1/(1+10*n)
PositionMesh mshtmp, 0, -n, 0
AddMesh mshtmp, mshJellyBase
FreeEntity mshtmp
Next
For a# = 0 To 350 Step 10
off# = -Rnd(0.3)
For n# = 0 To 0.5 Step 0.05
mshtmp = CreateCylinder(2, False)
ScaleMesh mshtmp, 0.003, 0.05, 0.003
PositionMesh mshtmp, 0.8 * Cos(a), off-n, 0.8 * Sin(a)
AddMesh mshtmp, mshJellyBase
FreeEntity mshtmp
Next
Next
Global mshJelly% = CopyMesh(mshJellyBase)
HideEntity mshJellyBase
EntityAlpha mshJelly, 0.3

;Begin main loop
PointEntity GlobalCamera, mshJelly
While Not KeyHit(1)
UpdateJelly
Navigate_World_With_MouseAndKeys(0.5, .1)

UpdateWorld()

SetBuffer BackBuffer()
RenderWorld()
Color 255, 0, 0
Text 1, 1, "FPS=" + fps
Text 1, 12, "TrisRendered=" + TrisRendered()
Flip

fpscount = fpscount + 1
millis% = MilliSecs()
If millistop < millis - 1000 Then
millistop = millis
fps = fpscount
fpscount = 0
End If
Wend
End


;deforms mesh:
Function UpdateJelly()
spd# = 1.5 + 0.5 * Sin(JellyParam)
JellyParam = JellyParam + spd Mod 360
WaveParam1= WaveParam1+ 1.4 Mod 360
WaveParam2= WaveParam2+ 2.16 Mod 360
WaveParam3= WaveParam3+ 0.79 Mod 360

s0% = GetSurface(mshJellyBase, 1)
s1% = GetSurface(mshJelly, 1)

For iv% = 0 To CountVertices(s0)-1
h1# = 590*(VertexY(s0, iv)+VertexX(s0, iv))
h2# = 190*(VertexY(s0, iv)+VertexZ(s0, iv))

wz# = 0.08 * Cos(WaveParam1+h1) * Cos(WaveParam2+h1) * Cos(WaveParam3+h1) *VertexY(s0, iv)
wx# = 0.08 * Sin(WaveParam1+h2) * Cos(WaveParam2+h2) * Cos(WaveParam3+h2) *VertexY(s0, iv)


s# = Sqr(VertexX(s0, iv)^2 + VertexY(s0, iv)^2)

n# = 0.5 * Cos(JellyParam) / (Abs(VertexY(s0, iv))+0.3) + s

If VertexY(s0, iv) < 0 Then
c# = 0.1 * Abs(VertexY(s0, iv)) ^ 2
Else
c = 0
End If

n2# = 0.3 * (2.5+Sin(-JellyParam+140*VertexY(s0, iv))) / (Abs(VertexY(s0, iv))+1.3)
VertexCoords s1, iv, VertexX(s0, iv) * (n2+c) + wx, VertexY(s0, iv) * (n+1.4)*0.4, VertexZ(s0, iv)* (n2+c) + wz
Next
UpdateNormals mshJelly
End Function






Function Navigate_World_With_MouseAndKeys(turnSpeed#=1, moveSpeed#=1)
Local dY# = EntityPitch(GlobalCamera)+MouseYSpeed()/2*turnSpeed
If dY > 89 Then dY = 89
If dY < -89 Then dY = -89

Local dz# = (KeyDown(200)-KeyDown(208)) * moveSpeed
Local dx# = (KeyDown(205)-KeyDown(203)) * moveSpeed
If dz <> 0 And dx <> 0 Then
dx=dx * 0.707
dz=dz * 0.707
End If
RotateEntity GlobalCamera, dY, EntityYaw(GlobalCamera)-(MouseXSpeed()/2)*turnSpeed, 0
MoveEntity GlobalCamera, dx, 0, dz
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2

If KeyHit(4) Then
CameraZoom GlobalCamera, 4.0
End If
If KeyHit(5) Then
CameraZoom GlobalCamera, 1.0
End If
End Function


Comments :


wizzlefish(Posted 1+ years ago)

 I get "illegal number of segments" error.


Gabriel(Posted 1+ years ago)

 So do I. It's this line
mshtmp = CreateCylinder(2, False)A cylinder can't possibly have 2 segments. 3 is the bare minimum.


BlitzSupport(Posted 1+ years ago)

 Once you correct that line (and move the mouse), it looks really good.


Mr Snidesmin(Posted 1+ years ago)

 That illegal number of segments error only appears in debug.With debug off, the error is not checked and you just get a flat 2 faced square, i.e. a 2 sided cylinder :O)I don't know why debug doesn't allow this cos there's nothing wrong with it. . .


Gabriel(Posted 1+ years ago)

 <div class="quote"> I don't know why debug doesn't allow this cos there's nothing wrong with it. . .  </div>Well there is. A cylinder is :<div class="quote"> The surface generated by a straight line intersecting and moving along a closed plane curve, the directrix, while remaining parallel to a fixed straight line that is not on or parallel to the plane of the directrix. </div>You have no closed plane curve, because your cylinder exists in only 2 dimensions. A cylinder is a 3 dimensional shape.But yeah, nice effect.As for your plea for help. Best thing I can suggest is to write ( or find ) an MD2 exporter. Export it from Blitz in code and then you can use quite a few of them without too much of a speed hit. Anything else is going to be slow because all B3D vertex operations are really slow.


wizzlefish(Posted 1+ years ago)

 I like the effect.


Blitzplotter(Posted 1+ years ago)

 Tried it, modified the cylinder and was quite impressed....


Mr. Bean(Posted 1+ years ago)

 I like the effect, too.


sonokong(Posted 1+ years ago)

 Huh...the jellyfish is quite fun. [/i]