Skip to content

Commit

Permalink
add object loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr committed Nov 12, 2018
1 parent 712cc51 commit d73bc4c
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 71 deletions.
13 changes: 12 additions & 1 deletion entities/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,16 @@ func CreateCamera(x, y, z float32) Camera {
}

func (c *Camera) lockOnPlayer(player Player) {
// m := mgl32.Ident4()
c.Height = 1.8
c.FollowDistance = -5
m := mgl32.Ident4()
rotY := mgl32.Rotate3DY(player.Entity.Rotation.Y())
cameraShift := mgl32.Vec3{0, 0, c.FollowDistance}
movement := rotY.Mul3x1(cameraShift)
c.Position = mgl32.Vec3{
player.Entity.X() + movement.X(),
player.Entity.Y() + c.Height,
player.Entity.Z() + movement.Z(),
}
c.Entity.Rotation.Elem(c.Entity.Rotation.X(), -player.Entity.Rotation.Y(), c.Entity.Rotation.Z())
}
142 changes: 72 additions & 70 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,92 +29,92 @@ func main() {
// 1,1,
// 1,0,
//}
var vertices = []float32{
-0.5,0.5,-0.5,
-0.5,-0.5,-0.5,
0.5,-0.5,-0.5,
0.5,0.5,-0.5,
//var vertices = []float32{
// -0.5,0.5,-0.5,
// -0.5,-0.5,-0.5,
// 0.5,-0.5,-0.5,
// 0.5,0.5,-0.5,

-0.5,0.5,0.5,
-0.5,-0.5,0.5,
0.5,-0.5,0.5,
0.5,0.5,0.5,
// -0.5,0.5,0.5,
// -0.5,-0.5,0.5,
// 0.5,-0.5,0.5,
// 0.5,0.5,0.5,

0.5,0.5,-0.5,
0.5,-0.5,-0.5,
0.5,-0.5,0.5,
0.5,0.5,0.5,
// 0.5,0.5,-0.5,
// 0.5,-0.5,-0.5,
// 0.5,-0.5,0.5,
// 0.5,0.5,0.5,

-0.5,0.5,-0.5,
-0.5,-0.5,-0.5,
-0.5,-0.5,0.5,
-0.5,0.5,0.5,
// -0.5,0.5,-0.5,
// -0.5,-0.5,-0.5,
// -0.5,-0.5,0.5,
// -0.5,0.5,0.5,

-0.5,0.5,0.5,
-0.5,0.5,-0.5,
0.5,0.5,-0.5,
0.5,0.5,0.5,
// -0.5,0.5,0.5,
// -0.5,0.5,-0.5,
// 0.5,0.5,-0.5,
// 0.5,0.5,0.5,

-0.5,-0.5,0.5,
-0.5,-0.5,-0.5,
0.5,-0.5,-0.5,
0.5,-0.5,0.5,
}
var indices = []uint32{
0,1,3,
3,1,2,
4,5,7,
7,5,6,
8,9,11,
11,9,10,
12,13,15,
15,13,14,
16,17,19,
19,17,18,
20,21,23,
23,21,22,
}
var textureCoord = []float32{
0,0,
0,1,
1,1,
1,0,
0,0,
0,1,
1,1,
1,0,
0,0,
0,1,
1,1,
1,0,
0,0,
0,1,
1,1,
1,0,
0,0,
0,1,
1,1,
1,0,
0,0,
0,1,
1,1,
1,0,
}
// -0.5,-0.5,0.5,
// -0.5,-0.5,-0.5,
// 0.5,-0.5,-0.5,
// 0.5,-0.5,0.5,
//}
//var indices = []uint32{
// 0,1,3,
// 3,1,2,
// 4,5,7,
// 7,5,6,
// 8,9,11,
// 11,9,10,
// 12,13,15,
// 15,13,14,
// 16,17,19,
// 19,17,18,
// 20,21,23,
// 23,21,22,
//}
//var textureCoord = []float32{
// 0,0,
// 0,1,
// 1,1,
// 1,0,
// 0,0,
// 0,1,
// 1,1,
// 1,0,
// 0,0,
// 0,1,
// 1,1,
// 1,0,
// 0,0,
// 0,1,
// 1,1,
// 1,0,
// 0,0,
// 0,1,
// 1,1,
// 1,0,
// 0,0,
// 0,1,
// 1,1,
// 1,0,
//}

d := renderEngine.DisplayManager{WindowWidth:windowWidth, WindowHeight:windowHeight}
defer d.CloseDisplay()
d.CreateDisplay()

model := renderEngine.LoadToVAO(vertices, textureCoord, indices)
model := renderEngine.LoadObjModel("objects/steve.obj") //renderEngine.LoadToVAO(vertices, textureCoord, indices)
s := shaders.CreateStaticShader()
textureID, err := renderEngine.LoadTexture("res/pic.png")
textureID, err := renderEngine.LoadTexture("textures/skin.png")
if err != nil {
panic(err)
}
t := textures.ModelTexture{Id:textureID}
texturedModel := models.TexturedModel{ModelTexture:t, RawModel:model}
entity := entities.Entity{
Position: mgl32.Vec3{0, 0, -5},
Position: mgl32.Vec3{0, -1.5, -5},
Rotation: mgl32.Vec3{0, 0, 0},
}
player := entities.Player{
Expand All @@ -123,13 +123,15 @@ func main() {
}
camera := entities.CreateCamera(0, 0, 1)

camera.LockOnPlayer(player)

for !d.Window.ShouldClose() {
renderEngine.Prepare()
s.Program.Start()
renderEngine.Render(player, camera, s)
s.Program.Stop()
d.UpdateDisplay()
player.Entity.IncreaseRotation(0.01, 0.01, 0.01)
player.Entity.IncreaseRotation(0.0, 0.01, 0.0)
}
s.Program.CleanUp()
renderEngine.CleanUp()
Expand Down
Binary file added objects/steve.blend
Binary file not shown.
Loading

0 comments on commit d73bc4c

Please sign in to comment.