Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Jiman An · Jun 08, 2016 at 05:44 PM · rotationquaternioneuler angles

I can get Quaternion data(x,y,z,w) from simulation program. But, how to assign it in rotation?

I receive data(xPos, yPos, zPos, xQ, yQ, zQ, wQ) from other simulation program.

xPos, yPos, zPos are Position Data.

xQ, yQ, zQ, wQ are Rotation Data.

and I assign these data in Box Object. I insert position data into box. But, I have some troubles with rotation.

This is my code. Which part I have to modify?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 using System.Text;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
 public class UDPReceive : MonoBehaviour
 {
 
     // receiving Thread
     Thread receiveThread;
 
     // udpclient object
     UdpClient client;
 
     // port
     public int port = 8051; // define > init
 
     // infos
     public string lastReceivedUDPPacket = "";
     float XPos;
     float YPos;
     float ZPos;
     float XRot;
     float YRot;
     float ZRot;
     Quaternion a;
     public Transform box;
     //game object
     //public GameObject tmp;
     //GameObject tmp = GameObject.Find("Cube");
 
     private static void Main()
     {
         UDPReceive receiveObj = new UDPReceive();
         receiveObj.init();
 
         string text = "";
         do
         {
             text = Console.ReadLine();
         }
         while (!text.Equals("exit"));
     }
 
     public void Start()
     {
 
         init();
     }
 
 
     void Update()
     {
         parseDataToBox(lastReceivedUDPPacket);
 
         //GameObject tmp = GameObject.Find("Cube");
         box.transform.position = box.position;
         box.transform.rotation = Quaternion a;
         //box.transform.eulerAngles = box.eulerAngles;
 
     }
 
 
     void OnGUI()
     {
         Rect rectObj = new Rect(40, 10, 200, 400);
         GUIStyle style = new GUIStyle();
         style.alignment = TextAnchor.UpperLeft;
         GUI.Box(rectObj, "\nLast Packet: \n" + lastReceivedUDPPacket, style);
     }
 
 
     private void init()
     {
         // Endpunkt definieren, von dem die Nachrichten gesendet werden.
         print("UDPSend.init()");
 
         // define port
         port = 8051;
 
         // status
         print("Sending to 127.0.0.1 : " + port);
         print("Test-Sending to this Port: nc -u 127.0.0.1  " + port + "");
 
 
         receiveThread = new Thread(
             new ThreadStart(ReceiveData));
         receiveThread.IsBackground = true;
         receiveThread.Start();
 
     }
     // Unity Application Quit Function
     void OnApplicationQuit()
     {
         stopThread();
     }
 
     // Stop reading UDP messages
     private void stopThread()
     {
         if (receiveThread.IsAlive)
         {
             receiveThread.Abort();
         }
         client.Close();
     }
 
 
     // receive thread
     private void ReceiveData()
     {
 
         client = new UdpClient(port);
         while (true)
         {
 
             try
             {
                 // Bytes empfangen.
                 IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
                 byte[] data = client.Receive(ref anyIP);
 
                 // Bytes mit der UTF8-Kodierung in das Textformat kodieren.
                 string text = Encoding.UTF8.GetString(data);
 
                 // Data Received from simulation
                 print("Received Data >> " + text);
 
                 // latest UDPpacket
                 lastReceivedUDPPacket = text;
 
             }
             catch (Exception err)
             {
                 print(err.ToString());
             }
         }
     }
 
 
     private void parseDataToBox(string text)
     {
         try
         {
             string[] AgxData = text.Split(';');
             //float[] floatData = Array.ConvertAll(text.Split(';'), float.Parse);
             float[] UnityData = new float[7];
             //float[] RotData = new float[3];
             UnityData[0] = float.Parse(AgxData[0]); //x Position
             UnityData[1] = float.Parse(AgxData[1]); //y Position
             UnityData[2] = float.Parse(AgxData[2]); //z Position
             UnityData[3] = float.Parse(AgxData[3]); //x Quaternion
             UnityData[4] = float.Parse(AgxData[4]); //y Quaternion
             UnityData[5] = float.Parse(AgxData[5]); //z Quaternion
             UnityData[6] = float.Parse(AgxData[6]); //w Quaternion
 
             box.position = new Vector3(UnityData[0], UnityData[1], UnityData[2]);
             Quaternion quaternion = (UnityData[3], UnityData[4], UnityData[5], UnityData[6]);
             //box.eulerAngles = new Vector3(UnityData[3], UnityData[4], UnityData[5]);
             
 
         }
         catch (Exception err)
         {
             print(err.ToString());
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Jun 08, 2016 at 05:52 PM

Your code looks correct, you just don't set the rotation, such as:

 box.rotation = quaternion;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to clamp rotation, following Unity's quaternion rules 1 Answer

Mirror rotation of object along 2 Euler Axis' 0 Answers

transform.rotation spazes out 0 Answers

Rotation problem 0 Answers

Quaternion.LookRotation on only one axis? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges