| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package model
- import (
- "math"
- "roserver/serverproto"
- )
- const (
- Eepsilon = 0.0004
- )
- type Direction3D struct {
- //x=roll,y=pitch,z=yaw
- dir serverproto.Vector3
- }
- func (this *Direction3D) roll() float32 {
- return this.dir.X
- }
- func (this *Direction3D) pitch() float32 {
- return this.dir.Y
- }
- func (this *Direction3D) yaw() float32 {
- return this.dir.Z
- }
- func (this *Direction3D) setRoll(val float32) {
- this.dir.X = val
- }
- func (this *Direction3D) setPitch(val float32) {
- this.dir.Y = val
- }
- func (this *Direction3D) setYaw(val float32) {
- this.dir.Z = val
- }
- func almostEqual(f1, f2 float32) bool {
- return math.Abs(float64(f1-f2)) < Eepsilon
- }
- //v1 - v2
- func Vector3Sub(v1, v2 *serverproto.Vector3) *serverproto.Vector3 {
- retVec3 := &serverproto.Vector3{}
- retVec3.X = v1.X - v2.X
- retVec3.Y = v1.Y - v2.Y
- retVec3.Z = v1.Z - v2.Z
- return retVec3
- }
- //v1 + v2
- func Vector3Add(v1, v2 *serverproto.Vector3) *serverproto.Vector3 {
- retVec3 := &serverproto.Vector3{}
- retVec3.X = v1.X + v2.X
- retVec3.Y = v1.Y + v2.Y
- retVec3.Z = v1.Z + v2.Z
- return retVec3
- }
- //vector3 len
- func Vector3Len(v *serverproto.Vector3) float32 {
- return float32(math.Sqrt(float64(v.X*v.X + v.Y*v.Y + v.Z*v.Z)))
- }
|