github.com/metaworking/channeld@v0.7.3/pkg/unreal/handover.go (about)

     1  package unreal
     2  
     3  import (
     4  	"github.com/metaworking/channeld/pkg/common"
     5  	"github.com/metaworking/channeld/pkg/unrealpb"
     6  )
     7  
     8  func CheckEntityHandover(netId uint32, newLoc, oldLoc *unrealpb.FVector) (bool, *common.SpatialInfo, *common.SpatialInfo) { //, spatialNotifier common.SpatialInfoChangedNotifier) {
     9  	var newX, newY, newZ float32
    10  
    11  	if newLoc.X != nil {
    12  		newX = *newLoc.X
    13  	} else {
    14  		// Use GetX/Y() to avoid violation memory access!
    15  		newX = oldLoc.GetX()
    16  	}
    17  
    18  	if newLoc.Y != nil {
    19  		newY = *newLoc.Y
    20  	} else {
    21  		newY = oldLoc.GetY()
    22  	}
    23  
    24  	if newLoc.Z != nil {
    25  		newZ = *newLoc.Z
    26  	} else {
    27  		newZ = oldLoc.GetZ()
    28  	}
    29  
    30  	if newX != oldLoc.GetX() || newY != oldLoc.GetY() || newZ != oldLoc.GetZ() {
    31  		// Swap the Y and Z as UE uses the Z-Up rule but channeld uses the Y-up rule.
    32  		oldInfo := &common.SpatialInfo{
    33  			X: float64(oldLoc.GetX()),
    34  			Y: float64(oldLoc.GetZ()),
    35  			Z: float64(oldLoc.GetY()),
    36  		}
    37  		newInfo := &common.SpatialInfo{
    38  			X: float64(newX),
    39  			Y: float64(newZ),
    40  			Z: float64(newY),
    41  		}
    42  
    43  		return true, oldInfo, newInfo
    44  	}
    45  
    46  	return false, nil, nil
    47  }