Esempio n. 1
0
func (s Sprite) getGLVertexInfo() Opengl.OpenGLVertexInfo {
	// vertexInfo := Opengl.OpenGLVertexInfo{}
	w, h := s.GetImageSection().GetDimensions()

	vertexInfo := Opengl.OpenGLVertexInfo{
		Translations: []float32{float32(s.x), float32(s.y), 0, float32(s.x), float32(s.y), 0, float32(s.x), float32(s.y), 0, float32(s.x), float32(s.y), 0},
		Rotations:    []float32{0, 0, 1, s.rot, 0, 0, 1, s.rot, 0, 0, 1, s.rot, 0, 0, 1, s.rot},
		Scales:       []float32{s.xS, s.yS, 0, s.xS, s.yS, 0, s.xS, s.yS, 0, s.xS, s.yS, 0},
		Colors:       []float32{s.r, s.g, s.b, s.a, s.r, s.g, s.b, s.a, s.r, s.g, s.b, s.a, s.r, s.g, s.b, s.a},
	}

	// for i := 0; i < 4; i = i + 1 {
	// 	vertexInfo.Translations = append(vertexInfo.Translations, float32(s.x), float32(s.y), 0)
	// 	vertexInfo.Rotations = append(vertexInfo.Rotations, 0, 0, 1, s.rot)
	// 	vertexInfo.Scales = append(vertexInfo.Scales, s.xS, s.yS, 0)
	// 	vertexInfo.Colors = append(vertexInfo.Colors, s.r, s.g, s.b, s.a)

	// }

	vertexInfo.Vertices = []float32{-0.5 * w, 0.5 * h, 1.0, 0.5 * w, 0.5 * h, 1.0, 0.5 * w, -0.5 * h, 1.0, -0.5 * w, -0.5 * h, 1.0}

	vertexInfo.Elements = []uint32{uint32(0), uint32(1), uint32(2), uint32(0), uint32(2), uint32(3)}

	return vertexInfo
}
Esempio n. 2
0
func (this *Image) VertexData() *Opengl.OpenGLVertexInfo {
	v := Opengl.OpenGLVertexInfo{}

	w := float32(this.Bounds().Dx())
	h := float32(this.Bounds().Dy())

	// first tri
	idx := v.NewVertex(-0.5*w, -0.5*h, 1.0)
	v.SetUV(idx, this.uvs[0], this.uvs[1])
	v.SetAggregateId(idx, this.aggrId)

	idx = v.NewVertex(0.5*w, -0.5*h, 1.0)
	v.SetUV(idx, this.uvs[2], this.uvs[3])
	v.SetAggregateId(idx, this.aggrId)

	idx = v.NewVertex(-0.5*w, 0.5*h, 1.0)
	v.SetUV(idx, this.uvs[6], this.uvs[7])
	v.SetAggregateId(idx, this.aggrId)

	// second tri
	idx = v.NewVertex(-0.5*w, 0.5*h, 1.0)
	v.SetUV(idx, this.uvs[6], this.uvs[7])
	v.SetAggregateId(idx, this.aggrId)

	idx = v.NewVertex(0.5*w, -0.5*h, 1.0)
	v.SetUV(idx, this.uvs[2], this.uvs[3])
	v.SetAggregateId(idx, this.aggrId)

	idx = v.NewVertex(0.5*w, 0.5*h, 1.0)
	v.SetUV(idx, this.uvs[4], this.uvs[5])
	v.SetAggregateId(idx, this.aggrId)

	return &v
}
Esempio n. 3
0
func (this *Mesh) VertexData() *Opengl.OpenGLVertexInfo {
	vertexData := Opengl.OpenGLVertexInfo{}

	for _, face := range this.Faces {
		for idx, vIdx := range face.V {
			c := this.Materials[face.Material].Diffuse
			v := this.Vs[vIdx]
			vdID := vertexData.NewVertex(v.X, v.Y, v.Z)
			vertexData.SetColor(vdID, c.R, c.G, c.B, 1)

			tex := this.Materials[face.Material].DiffuseTex

			if len(face.UV) == 0 || tex == "" {
				vertexData.SetMode(vdID, Opengl.NO_TEXTURE)
			} else {

				imgSec := Image.GetImageSection(GT.AssetsImages + tex)

				if imgSec == nil {
					Logging.Info("Cannot open: ", GT.AssetsImages+tex, " For Mat: ", face.Material)

				}

				// uvs
				u := this.VTs[face.UV[idx]].U
				v := this.VTs[face.UV[idx]].V

				//normals

				// x starts from left to right
				locX := int(float32(imgSec.Bounds().Dx()) * u)
				// y starts bottom to top so we need to convert.
				locY := int(float32(imgSec.Bounds().Max.Y) - float32(imgSec.Bounds().Dy())*v)

				locX += imgSec.Section.Min.X
				locY += imgSec.Section.Min.Y

				newU, newV := Image.GetUVFromPosition(image.Point{locX, locY})

				vertexData.SetUV(vdID, newU, newV)

				vertexData.SetMode(vdID, Opengl.TEXTURED)

				// set normals
				nX := this.VNs[face.VN[idx]].X
				nY := this.VNs[face.VN[idx]].Y
				nZ := this.VNs[face.VN[idx]].Z

				vertexData.SetMNormal(vdID, nX, nY, nZ)
				vertexData.SetWNormal(vdID, nX, nY, nZ)

			}
		}
	}
	return &vertexData
}