• Create Account

# Super Llama

Member Since 13 Dec 2007
Offline Last Active Feb 26 2014 07:59 AM

### Can't get Quaternion Time Derivative to work?

23 February 2014 - 10:04 PM

Okay I'm sure this is a stupid question and I'm either completely misusing this formula or I'm missing something obvious, but I can't for the life of me figure out how I'm supposed to apply an angular velocity vector to an orientation quaternion, despite finding the Quaternion Time Derivative formula on multiple websites.

From what I've read, you can take an angular velocity vector like (0, 0, 3.14) for a 180 degree turn around the Z axis each second, then use these values in a non-normalized quaternion with zero w (0 0 3.14 0) -- I'm using xyzw representation for my quaternions -- and then you can multiply it by a delta time and an orientation quaternion and divide it by two, then add it to the orientation quaternion, and that should properly rotate the orientation quaternion according to the velocity. The formula looks like this: Q' = Q + 0.5t(W x Q).

Anyway, when I went to try it with a delta time of one second, it didn't seem to work. I take a unit quaternion with no rotation:

(0 0 0 1)

then multiply it by the angular velocity quaternion (with the original on the right, as per the formula)

(0 0 3.14 0) x (0 0 0 1) = (0 0 3.14 0)

then divide that by two

(0 0 1.57 0)

then add it to the original quaternion

(0 0 1.57 1)

but when I apply this rotation, it's 0, 0, -115 in euler angles, not 0, 0, 180.

So yeah... does anyone know what the problem is? I'd rather avoid having to build a quaternion from axis-angles each frame if I can, since that would require sin and cos which are more costly than just arithmetic, and everyone seems to say this formula works just as well, but I'm not seeing it.

### [d3d9/win7] can't seem to create a shared texture resource?

02 November 2013 - 02:46 PM

I'm trying to create a shared texture from a Direct3D 9 device using the pSharedHandle parameter that supposedly works starting with windows vista-- but no matter what I put in the parameters it always just returns an invalid call. I'm intending to share it with another device in another thread, but I can't even get the initial creation of the shared resource to work.

`ddev->CreateTexture(width, height, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &tex, &handle);`

I've tried changing pretty much all the parameters but if I pass it a &handle it always fails. The handle is pointing to a NULL value. I've been unable to find a lot of information about the texture sharing API, but everything I find says this should work. I'm compiling with the headers/libraries both from the Windows 7 SDK and the June 2010 DX SDK, and I'm able to see and instantiate D3D9Ex classes, so it's definitely a new enough version. The device is perfectly able to create the texture if I don't specify a handle, so I'm guessing I must not be fulfilling one of the restrictions for shared textures that microsoft barely told anyone about. MSDN is not helping very much, all it says is that I have to use D3DPOOL_DEFAULT, which I am.

Any ideas? I'll keep messing with the parameters while I wait for an answer.

EDIT: Well, I got it to create the handle by changing all the DirectX9 objects to DirectX9Ex objects, but this is not ideal and if there's still a way to do it with ordinary D3D9 interfaces, that would be preferable.

### Poly/Ellipsoid Collision Response for Players and NPCs

03 November 2012 - 12:07 PM

I've recently written a collision detection system for detecting collisions between ellipsoids (i.e. players, NPCs) and triangle lists. The detector works flawlessly using a ton of vector operations all baked into a few lines of scalar math, but I'm having trouble with the collision response. For a single triangle, this is easy, all I have to do is work out the closest point ON the triangle to the center of the sphere (I smash the coordinates into ellipsoid-scaled space so at this point it's just a sphere), and push it away from that point until the distance is greater than or equal to the radius.

Working with multiple triangles, I tried several approaches. First, I tried allowing any triangle the player collides with to push you away in turn, all on the same frame. This worked for 90 degree angles, but caused trouble with sharp angles and high-poly collisions since the player could end up on the edge of one of the small polys and be pushed directly into another one. Next, I tried finding the average of all "closest points" and using that as the hit position and moving away from there. While it worked far better than the previous method, the average point would sometimes be inside a sharp external corner, or not far enough out from a sharp internal corner. I have no idea how to calculate how far to push the ellipsoid from this hit position, and the only solution I can think of to stop the player from getting stuck is allowing movement away from the hit normal but not towards it, so they can leave simply by moving away from the point they're stuck in. The trouble with that is that you'll still phase slightly through a sharp spike or steep crevice. Though that might not be too big of a problem, it would make it easier to phase past a mesh and into the void if the penetration is deep enough.

One last problem arises with this method-- if the player is standing on the edge of a cliff or stair step, gravity will slowly pull him off due to the "push away from edge" concept. I suppose I could treat the bottom of the ellipsoid as flat, but I'd have to think of a new collision response for that too. Maybe I could use traces to check for footholds... I guess that's up to me how I want to handle it but any tips would be appreciated.

I wish I could just use binary space partitioning, but I don't want to have to write an editor/compiler for that and I'd prefer to just use 3dsmax to export single texture UV-mapped chunks of level geometry, which can then be arranged to make up a whole level. I guess I could also try forcing convex collision meshes though, but I'd still have the crevice problem between two convex bodies.

### [DX9] Multi-textured meshes, sampler index trouble

19 October 2012 - 01:53 PM

I'm trying to make a level rendering system using a single mesh for the map geometry. I'd planned on using vertices' W coordinate as a texture ID and then passing multiple textures to the shader using device->SetTexture. I got this far before I realized that you can't index a sampler array using a variable, which I'm very upset about as it invalidates my entire plan unless I want to make a massive mess of elseifs... is there some better way to do this? A 3D texture would work on the shader side of things, but it'd be harder to set up in my C++ backend. I just want a way to put multiple textures on one mesh, determining which texture to draw using data from the vertices. Because they're tiled, I can't just bake them all into one texture either. I wish there was a way to convert an array of sampler2D's into one sampler3D, but I'm sure there isn't... any other ideas?

I'm using C++ with DX9. No FX, just shaders and SetShaderConstantF and such.

### Denormalized Angle Operations in Maxscript

26 July 2012 - 04:00 PM

Hi everyone, I'm writing an exporter for my animation format in Maxscript, and I ran into a problem with angles. Basically, the angles start out as denormalized euler angles, but I have to do some transformation operations on them to get them in the proper format. Since you can't just do operations on euler angles in maxscript, I have to convert them to quaternions first-- the problem is, this automatically normalizes them, which causes its own host of problems. Basically my question is (yes, I've googled it), is there any way at all to convert back and forth from euler angles and quaternions without normalizing them? Or is there some way to un-normalize them given the starting angle? All I need to do is subtract the new position from the starting one, but even basic subtraction wreaks havok if you try it on a euler angle. If all else fails, is there some way of subtracting denormalized euler angles? The only remaining courses of action if I don't find a way to do this is to completely change my format so it uses quaternions, and that'd take a lot of editing.

PARTNERS