forked from Pakz001/Monkey2-3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample - Sprites with new image.monkey2
102 lines (76 loc) · 2.33 KB
/
Example - Sprites with new image.monkey2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#Import "<std>"
#Import "<mojo>"
#Import "<mojo3d>"
Using std..
Using mojo..
Using mojo3d.. 'The new mojo 3d module.
Class MyWindow Extends Window
' What are we going to use.
Field myscene:Scene
Field mycamera:Camera
Field mylight:Light
Field mybox:Model
Field sprites:=New Stack<Sprite>
Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
Super.New( title,width,height,flags )
' Get the current scene
myscene=Scene.GetCurrent()
'create camera
'
mycamera = New Camera
mycamera.Near = 1 '??
mycamera.Far = 256 'how far should we render
mycamera.Move(0,0,0) 'move the camera to position x,y,z
'create light
'
mylight = New Light
mylight.RotateX(Pi/2) 'aim directional light 'down' - Pi/2=90 degrees.
'
' Create cube
'
' This is the mesh with which we create the model.
Local mymesh := Mesh.CreateBox( New Boxf( -2,-2,-2,2,2,2 ),1,1,1 )
' Here we create the material that we put on the box.
Local material:=New PbrMaterial( New Color( 1,0,0) )
mybox = New Model( mymesh,material )
mybox.Move(0,0,20)
Local sm:= New SpriteMaterial()
Local ri:Image=New Image( 32, 32 )
Local rc:Canvas=New Canvas(ri)
rc.Clear(Color.Blue)
rc.Flush()
sm.ColorTexture = ri.Texture
For Local i:=0 Until 100
Local sprite:=New Sprite(sm)
Local x:Int=Rnd(-50,50)
Local y:Int=Rnd(-50,50)
Local z:Int=Rnd(-50,50)
sprite.Move(x,y,z)
sprite.Scale=New Vec3f( Rnd(4,5),Rnd(5,6),1 )
sprite.Handle=New Vec2f( .5,0 )
sprite.Mode=SpriteMode.Billboard
'sprite.Mode=SpriteMode.Upright
sprites.Push( sprite )
Next
End Method
' This method is the main loop.
Method OnRender( canvas:Canvas ) Override
RequestRender()
' Primitive Mouse Movement
If Mouse.X < 250 Then mycamera.RotateY(1.4)
If Mouse.X > Width - 250 Then mycamera.RotateY(-1.4)
If Mouse.Y > Height/2 Then mycamera.RotateX(1.4)
If Mouse.Y < Height/2 Then mycamera.RotateX(-1.4)
mybox.Rotate(.5,.5,.5) 'rotate the box (x,y,z)
myscene.Update()
myscene.Render( canvas) 'render the 3d scene
canvas.Color = Color.Black
canvas.DrawText("Move mouse to edges to turn.",0,0)
If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()
End Method
End Class
Function Main()
New AppInstance
New MyWindow
App.Run()
End Function