Explorar el Código

geometry improvements

danaugrs hace 7 años
padre
commit
7a018760b8
Se han modificado 5 ficheros con 34 adiciones y 6 borrados
  1. 15 1
      geometry/box.go
  2. 3 1
      geometry/circle.go
  3. 2 2
      geometry/geometry.go
  4. 8 0
      geometry/plane.go
  5. 6 2
      geometry/sphere.go

+ 15 - 1
geometry/box.go

@@ -139,8 +139,22 @@ func NewSegmentedBox(width, height, length float32, widthSegments, heightSegment
 	box.AddVBO(gls.NewVBO().AddAttrib("VertexNormal", 3).SetBuffer(normals))
 	box.AddVBO(gls.NewVBO().AddAttrib("VertexTexcoord", 2).SetBuffer(uvs))
 
-	box.boundingBox = math32.Box3{math32.Vector3{-wHalf, -hHalf, -lHalf}, math32.Vector3{wHalf, hHalf, lHalf}}
+	// Update bounding box
+	box.boundingBox.Min = math32.Vector3{-wHalf, -hHalf, -lHalf}
+	box.boundingBox.Max = math32.Vector3{wHalf, hHalf, lHalf}
 	box.boundingBoxValid = true
 
+	// Update bounding sphere
+	box.boundingSphere.Radius = math32.Sqrt(math32.Pow(width/2,2) + math32.Pow(height/2,2) + math32.Pow(length/2,2))
+	box.boundingSphereValid = true
+
+	// Update area
+	box.area = 2*width + 2*height + 2*length
+	box.areaValid = true
+
+	// Update volume
+	box.volume = width * height * length
+	box.volumeValid = true
+
 	return box
 }

+ 3 - 1
geometry/circle.go

@@ -86,7 +86,9 @@ func NewCircleSector(radius float64, segments int, thetaStart, thetaLength float
 	circ.AddVBO(gls.NewVBO().AddAttrib("VertexNormal", 3).SetBuffer(normals))
 	circ.AddVBO(gls.NewVBO().AddAttrib("VertexTexcoord", 2).SetBuffer(uvs))
 
-	//circ.BoundingSphere = math32.NewSphere(math32.NewVector3(0,0,0), float32(radius))
+	// Update volume
+	circ.volume = 0
+	circ.volumeValid = true
 
 	return circ
 }

+ 2 - 2
geometry/geometry.go

@@ -30,14 +30,14 @@ type Geometry struct {
 	// Geometric properties
 	boundingBox         math32.Box3     // Last calculated bounding box
 	boundingSphere      math32.Sphere   // Last calculated bounding sphere
-	volume              float32         // Last calculated volume
 	area                float32         // Last calculated area
+	volume              float32         // Last calculated volume
 
 	// Flags indicating whether geometric properties are valid
 	boundingBoxValid    bool            // Indicates if last calculated bounding box is valid
 	boundingSphereValid bool            // Indicates if last calculated bounding sphere is valid
-	volumeValid         bool            // Indicates if last calculated volume is valid
 	areaValid           bool            // Indicates if last calculated area is valid
+	volumeValid         bool            // Indicates if last calculated volume is valid
 }
 
 // Geometry group object

+ 8 - 0
geometry/plane.go

@@ -75,5 +75,13 @@ func NewPlane(width, height float32, widthSegments, heightSegments int) *Plane {
 	plane.AddVBO(gls.NewVBO().AddAttrib("VertexNormal", 3).SetBuffer(normals))
 	plane.AddVBO(gls.NewVBO().AddAttrib("VertexTexcoord", 2).SetBuffer(uvs))
 
+	// Update area
+	plane.area = width*height
+	plane.areaValid = true
+
+	// Update volume
+	plane.volume = 0
+	plane.volumeValid = true
+
 	return plane
 }

+ 6 - 2
geometry/sphere.go

@@ -87,9 +87,13 @@ func NewSphere(radius float64, widthSegments, heightSegments int, phiStart, phiL
 	s.AddVBO(gls.NewVBO().AddAttrib("VertexNormal", 3).SetBuffer(normals))
 	s.AddVBO(gls.NewVBO().AddAttrib("VertexTexcoord", 2).SetBuffer(uvs))
 
-	r := float32(s.Radius)
-	s.boundingSphere = math32.Sphere{math32.Vector3{0, 0, 0}, r}
+	r := float32(radius)
+
+	// Update bounding sphere
+	s.boundingSphere.Radius = 3
 	s.boundingSphereValid = true
+
+	// Update bounding box
 	s.boundingBox = math32.Box3{math32.Vector3{-r, -r, -r}, math32.Vector3{r, r, r}}
 	s.boundingBoxValid = true