RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
QuaternionStruct.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.math.geometry.struct;
6
7import java.nio.ByteBuffer;
8import org.wpilib.math.geometry.Quaternion;
9import org.wpilib.util.struct.Struct;
10
11public final class QuaternionStruct implements Struct<Quaternion> {
12 @Override
13 public Class<Quaternion> getTypeClass() {
14 return Quaternion.class;
15 }
16
17 @Override
18 public String getTypeName() {
19 return "Quaternion";
20 }
21
22 @Override
23 public int getSize() {
24 return DOUBLE_SIZE * 4;
25 }
26
27 @Override
28 public String getSchema() {
29 return "double w;double x;double y;double z";
30 }
31
32 @Override
33 public Quaternion unpack(ByteBuffer bb) {
34 double w = bb.getDouble();
35 double x = bb.getDouble();
36 double y = bb.getDouble();
37 double z = bb.getDouble();
38 return new Quaternion(w, x, y, z);
39 }
40
41 @Override
42 public void pack(ByteBuffer bb, Quaternion value) {
43 bb.putDouble(value.getW());
44 bb.putDouble(value.getX());
45 bb.putDouble(value.getY());
46 bb.putDouble(value.getZ());
47 }
48
49 @Override
50 public boolean isImmutable() {
51 return true;
52 }
53}