func NewObject3D() *Object3D { Object3DIdCount++ object3d := Object3D{ NewEventDispatcher(), Id: Object3DIdCount, Uuid: math.GenerateUUID(), Name: "", Type: "Object3D", Parent: nil, Channels: NewChannels(), Children: make([]Object3D, 0), Up: DefaultUp.Clone(), Position: math.NewEmptyVector3(), Rotation: math.NewEmptyEuler(), Quaternion: math.NewEmptyQuaternion(), Scale: math.NewVector3(1.0, 1.0, 1.0), RotationAutoUpdate: true, Matrix: math.NewMatrix4(), MatrixWorld: math.NewMatrix4(), MatrixAutoUpdate: DefaultMatrixAutoUpdate, MatrixWorldNeedsUpdate: false, Visible: true, CastShadow: false, ReceiveShadow: false, FrustumCulled: true, RenderOrder: 0, UserData: make(map[string]string), ModelViewMatrix: math.NewMatrix4(), NormalMatrix: *math.NewMatrix3(), Geometry: nil, } onRotationChange := func() { object3d.Quaternion.SetFromEuler(object3d.Rotation, false) } onQuaternionChange := func() { object3d.Rotation.SetFromQuaternion(object3d.Quaternion, nil, false) } object3d.Rotation.OnChange(onRotationChange) object3d.Quaternion.OnChange(onQuaternionChange) object3d.GetWorldQuaternion = object3d.buildGetWorldQuaternion() object3d.GetWorldRotation = object3d.buildGetWorldRotation() object3d.GetWorldScale() = object3d.buildGetWorldScale() object3d.GetWorldDirection = object3d.buildGetWorldDirection() object3d.LookAt = object3d.buildLookAt() return &object3d }
func (c *Camera) GetWorldDirection(optionalTarget *math.Vector3) *math.Vector3 { var quaternion = math.NewEmptyQuaternion() var result = optionalTarget if result == nil { result = math.NewEmptyVector3() } c.GetWorldQuaternion(quaternion) return result.Set(0, 0, -1).ApplyQuaternion(quaternion) }
func (o *Object3D) buildGetWorldDirection() func(*math.Vector3) *math.Vector3 { var quaternion = math.NewEmptyQuaternion() return func(optionalTarget *math.Vector3) *math.Vector3 { result := optionalTarget if result == nil { result = math.NewEmptyVector3() } o.GetWorldQuaternion(quaternion) return result.Set(0, 0, 1).ApplyQuaternion(quaternion) } }
func (o *Object3D) buildGetWorldRotation() func(*math.Euler) *math.Euler { quaternion := math.NewEmptyQuaternion() return func(optionalTarget *math.Euler) { result := optionalTarget if result == nil { result = math.NewEmptyEuler() } o.GetWorldQuaternion(quaternion) return result.SetFromQuaternion(quaternion, o.Rotation.Order, false) } }
func (o *Object3D) buildGetWorldScale() func(*math.Vector3) *math.Vector3 { var position = math.NewEmptyVector3() var quaternion = math.NewEmptyQuaternion() return func(optionalTarget *math.Vector3) *math.Vector3 { result := optionalTarget if result == nil { result = math.NewEmptyVector3() } o.UpdateMatrixWorld(true) o.MatrixWorld.Decompose(position, quaternion, result) return result } }
func (o *Object3D) buildGetWorldQuaternion() func(*math.Vector3) *math.Quaternion { position := math.NewEmptyVector3() scale := math.NewEmptyVector3() return func(optionalTarget *math.Vector3) *math.Quaternion { var result = optionalTarget if result == nil { result = math.NewEmptyQuaternion() } o.UpdateMatrixWorld(true) o.MatrixWorld.Decompose(position, result, scale) return result } }