Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Jun 2010
Offline Last Active Dec 21 2015 08:53 PM

Topics I've Started

Unity Network - Rigidbody synchronize problem (ownership)

03 June 2013 - 02:22 AM

Hi, I’m new to the Unity network API. I’m trying to develop a game similar to Air Soccer Fever (https://play.google.com/store/apps/details?id=com.danglingconcepts.airsoccerfever&hl=es).

I’m currently synchronizing the balls by using a NetworkView per Ball, each one with the owner has the machine that run the team. The balls are rigidbodies and a synchronize only the position making a Lerp so it is more or less smooth (I don’t know if this is the usual way when working with RigidBodies in Unity).


My problem comes when ball from say team A hits a balls from team B, because the balls from team B have as owner his player and the writer of the position is that client then even when the ball from team A moves the ball from team B it will automatically reposition because the client that “writes” the position is the client from team B. I don’t know if it is clear but that is the problem.

The solution that I think would be the easiest (if possible implementing) will be changing the ownership of the NetworkView so that when it is the turn of team A his client controls (owns) all the balls, and in the turn of team B then its own all the balls. I don’t even know if this solution would be possible or if another think should be do.

Any advice in this?

Unity 3D and Kinect wrapper (newer official SDK)

23 January 2013 - 09:53 AM

I'm working in a wrapper to the current version of the Kinect official SDK (http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx) from C# inside Unity. The wrapper works making called through interop to the C API of the SDK. It is working in getting the skeletal information, but I’m having problems in retrieving the depth information of the camera. The problems is because I use the C API and there is no problem in making calls to a C function but to get the depth information I need to Lock a DirectX like Texture and because it is a class in this case I don’t know how to called the member function of Texture. The idea of the code I use is (not the actual code but the basic flow of calls) :


NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | 
NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesDepth | 

NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref 

int hr = NativeMethods.NuiImageStreamGetNextFrame(justDepthStreamHandle, 100, 
ref imageFramePtr);
if (hr == 0)
NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, 

// Here must be a LOCKRECT to imageFrame.pFrameTexture

NuiImageBuffer imageBuf = 

DepthBuffer db = 
hr = NativeMethods.NuiImageStreamReleaseFrame(depthStreamHandle, 



If I do the code showed before the depth image I get is not the data instead it is just junk. My guess is that it is because the texture is not locked before accessing it but the problem is that LockRect is a member function (http://msdn.microsoft.com/en-us/library/jj663804.aspx).


The layout for the variable NuiImageBuffer imageBuf that I'm using is:




public struct NuiImageFrame
public Int64 liTimeStamp;
public uint dwFrameNumber;
public NuiImageType eImageType;
public NuiImageResolution eResolution;
public IntPtr pFrameTexture;
public uint dwFrameFlags_NotUsed;
public NuiImageViewArea ViewArea_NotUsed;




Note: the code is based in a wrapper of OpenNI for Unity. There is a Kinect wrapper also based in that OpenNI wrapper but it is from an older version of the Kinect SDK. This wrappers makes the code I show without Locking but it doesn’t work for me sad.png .


The wrapper is http://wiki.etc.cmu.edu/unity3d/index.php/Microsoft_Kinect_-_Microsoft_SDK



How would you make something like this?

07 November 2012 - 03:06 PM

Recently I saw an Indi game named "Sui Generis" (here is a video of it http://kotaku.com/5958364/we-might-be-looking-at-the-next-generation-ofindie-rpgs), it seems very interesting. There are two things that are particularly interesting: the physic interactions, the animation of the characters.

My question is related to the characters animation. I want to ask how you can make something like this, I mean the movements seems very "physic driven" to call it some way. I know that Euphoria (http://www.naturalmotion.com/products/euphoria/) is a very good dynamic motion synthesizer, surely with that you can make something similar but this studio doesn’t seem to be very big so they most probably don’t have access to that kind of technology. May be the animations are simple made with Maya, 3D Studio, etc and they have a ragdoll and nothing else... but the result is very good.

What do you thing guys?

Quaternion coordinate axis change

14 October 2012 - 01:38 AM

Hi guys, I’m having problems with an animation that uses quaternions. The problem is that the bones are given to me in the form of quaternions such that:
1) The system is right handed.
2) In particular the example of bone I want to resolve is this:
Posted ImagePosted Image

In my game the corresponding bone frame of reference is left handed. In particular it is:
Posted ImagePosted Image

So the map would be:

from = +Y along arm, +X right, +Z forward
to = -X along arm, -Z right, -Y forward

In resume my problems are:
* The quaternion of the rotation is in a left hand system
* My system is right handed and with different axis

Watching an example I found that the change in the quaternion seems to be:
Where originalRotation is the rotation in the right hand system
myRotation is the rotation in my axis

Quaternion myRotation = new Quaternion(-originalRotation.y, originalRotation.z, originalRotation.x, originalRotation.w);

This seems to work... but I don’t know how to get there.... it is a change of frame of reference with quaternion with a handness change...
Thanks in avance

SSE optimizations not so optimized

14 September 2011 - 02:08 AM

Hi guys, im having great problems with a few operations i implemented using SSE intrinsics(im using Visual Studio 2008/2010 by the way). The thing is that the performance gain i get depends to much in the operations i make. Im using single floating point presition, so i make 4 floats operations with 1 SSE instruction. When i make a SSE division(_mm_div_ps) the operation only takes 20% of what the fpu would take. With the squareroot i get even better results, something like 15% of what the sqrt(CRT) without SSE takes. But that is the only nice things. With the addition, subtraction and multiplication i get almost the same times with SSE that i get with the fpu. I dont understand how the division and squareroot could be so performing and the rest of the operations only a joke. I dont know if this kind of results should be expected or im doing something really bad?

I perform a few tests. Each test consist of 5000000 operations of its kind(for example only divisions). And a result is the analisis of 20 tests(60 in the case of the addition because it had higer standard deviation Gods knows why). Every test is run in release with speed optimizations, and Enable Enhaced Instruction Set to Not Set (the only diference that it makes is that makes my code that runs in the fpu slower).The blue bar is the average time(in seconds) of a test, and the red bar is the standard deviation. Here are the results ive got:
(NOTE: "Con SIMD" means test made with SIMD and "Sin SIMD" means test made without SIMD, ie fpu)

Posted Image

Posted Image

Posted Image

Posted Image

The code for example to make an addition is:

---------- Vector4.h -------------- 


	class Vector4

		__declspec(align(16)) union
			__m128 m_xyzw;
				float m_x, m_y, m_z, m_w;
		//This union is not probably a good idea... What do you think?
		//Anyway i never get m_x, m_y, m_z, m_w in this test


	inline Vector4 operator+(const Vector4 &B) const
		return Vector4( _mm_add_ps(m_xyzw, B.m_xyzw) );



	class Vector4

		float m_x, m_y, m_z, m_w;

	inline Vector4 operator+(const Vector4 &B) const
		return Vector4( m_x+B.m_x, m_y+B.m_y, m_z+B.m_z, m_w+B.m_w );



A simplified example of a call of a addition operation inside the test would be:

Vector4* data = (Vector4*)_aligned_malloc(iterations*sizeof(Vector4), __alignof(Vector4));//if not properly aligned everything is going to hell
srand(static_cast<unsigned int>(time(NULL)));

for(unsigned int i=0; i < iterations ;++i)
	data[i]   = Vector4(static_cast<float>(rand()%100), static_cast<float>(rand()%100), static_cast<float>(rand()%100), static_cast<float>(rand()%100));

...... later inside a test

data[i]   = data[i]  +data[i+1];

.... other operations of addition

Here is my code. There are projects for Visual Studio 2008 and 2010.

The examples i have seen in the web that show times always use division or squareroot... i dont know if intentionaly or what. For example: