CUDA - Rotating particles - cuda

I'm new to CUDA and experimenting with the samples of the NVidia GPU SDK.
The goal is to rotate the spheres in the Particles example. So while the sphere is falling, it's also rotating, any pointers please?

In the particles sample the particles are just points with a radius. They have no angular momentum in the simulation, because they are assumed to be point masses, not sphere masses (i.e. all of their mass is assumed to be exactly at their centers.)
If you want to do this physically, you would have to use a simplified rigid body dynamics rather than just point masses.
If you just want to visually rotate the particles (non-physically), you can do that by just applying a rotation matrix to the GL matrix stack before you draw the object that you display for each particle (you mentioned a torus). This could be done in OpenGL, independently of the CUDA simulation code.

Related

A 3D face moves differently from a 2D photo. Are there any motion-analysis algorithms to detect this difference?

Are there any motion-analysis algorithms to detect the difference between 2d face motion and 3d face motion?
I assume you are talking about a video.
You can extract 3d landmarks for each one of the frames in the video and then analyze the change in those 3d landmarks to get motion analysis of the face.
A simple way to extract the 3d landmarks is to use
https://github.com/1adrianb/face-alignment
So lets say your video as 1..i..N frames and you extracted 3d landmark LMK_i for each frame.
To analyze the motion between the frames you can find the 3d rigib body transformation between LMK_i and LMK_i+1. (example: python implementation of 3D rigid body translation and rotation
After you have the transformation you can extract from the matrix the rotation translation and scale.
Note the motion analysis assumes the camera is stationary and not moving. If the camera is also moving you need to add take into consideration this movement when you calculate the motion analysis

Logic of reflecting light for 3D specular reflections

I'm trying to add specular reflections to a Stage3D game and it is ALMOST working, but I don't think I have a good enough grasp of the maths happening at the actual reflection stage.
I have an incoming light vector and I have the face normal; I know what to do with the resulting reflected vector (normalize and then dot product with the normalized vector pointing to the player 'camera') but what are the AGAL opcodes to reflect the original light vector off the face? I can't get my head around that. Any help appreciated...
Unlike GLSL with its reflect(), AGAL does not have any kind of helper for doing this. But you can still calculate reflection vector yourself - even GLSL reference page for reflect() mentions the formula used for calculation:
For a given incident vector I and surface normal N reflect returns the reflection direction calculated as I - 2.0 * dot(N, I) * N.

Calculate 3D coordinates from 2D Image plane accounting for perspective without direct access to view/projection matrix

First time asking a question on the stack exchange, hopefully this is the right place.
I can't seem to develop a close enough approximation algorithm for my situation as I'm not exactly the best in terms of 3D math.
I have a 3d environment in which I can access the position and rotation of any object, including my camera, as well as run trace lines from any two points to get distances between a point and a point of collision. I also have my camera's field of view. I do not have any form of access to the world/view/projection matrices however.
I also have a collection of 2d images that are basically a set of screenshots of the 3d environment from the camera, each collection is from the same point and angle and the average set is taken at about an average of a 60 degree angle down from the horizon.
I have been able to get to the point of using "registration point entities" that can be placed in the 3d world that represent the corners of the 2d image, and then when a point is picked on the 2d image it is read as a coordinate with range 0-1, which is then interpolated between the 3d positions of the registration points. This seems to work well, but only if the image is a perfect top down angle. When the camera is tilted and another dimension of perspective is introduced, the results become more grossly inaccurate as there no compensation for this perspective.
I don't need to be able to calculate the height of a point, say a window on a sky scraper, but at least the coordinate at the base of the image plane, or which if I extend a line out from my image from a specified image space point I need at least the point that the line will intersect with the ground if there was nothing in the way.
All of the material I found about this says to just deproject the point using the world/view/projection matrices, which I find straightforward in itself except I don't have access to these matrices, just data I can collect at screenshot time and other algorithms use complex maths I simply don't grasp yet.
One end goal of this would be able to place markers in the 3d environment where a user clicks in the image, while not being able to run a simple deprojection from the user's view.
Any help would be appreciated, thanks.
Edit: Herp derp, while my implementation for doing so is a bit odd due to the limitations of my situation, the solution essentially boiled down to ananthonline's answer about simply recalculating the view/projection matrices.
Between position, rotation and FOV of the camera, could you not calculate the View/Projection matrices of the camera (songho.ca/opengl/gl_projectionmatrix.html) - thus allowing you to unproject known 3D points?

Vectors for Game Programming

Im not sure how to use vectors correctly in game programming. I have been reading advanced game design with flash which shows you how to create a vector with a start point and endpoint and how to use that for games, for example the start point would be used for a characters position in a game and the x and y length would be used for velocity. But since I have started looking online I have found that vectors are usually just x and y with no start point or end point and a character would be moved by having a position vector and a velocity vector and acceleration vector. I have started creating my own vector class. And wondered what the reasons for and against each method are. Or is it completely not important?
Initially a vector means direction. Classical vector is used in physics to present a velocity so that the vector direction stands for the heading and the vector length is a speed.But in graphics vectors are used also to present position. So if you have some point, let's say, in 2d space noted by x ,y it remains point if you don't want to know in what direction it set relating to the origin which is usually a center of the coordinate system. In 2d graphics we deal with Cartesian coordinate system which has an origin in top left corner of the screen. But you can also have a direction of some vector relative to any other point in the space.That is why you have also vector operations like addition, subtracting ,dot product, cross product. All those help you to measure distances and angles between vectors. I would suggest you to buy a book on graphics programming. Most of them introduce an easy to grasp primer to vector math.And you don't need to write a vector class in AS 3.0 You have a generic one - Vector3d

AS3: Simulating RotationX with Matrix

I have to use Flash CS3, so I can't use the properties rotationX, roationY and rotationZ.
I have a movieclip, that looks like this. It is now flat, no 3D rotation or shearing
But what I want is that this movieclip has a rotationX, or that it is a bit in perspective like this:
As I said, I can't use rotationX, so I have been playing around with Matrix.
But I can not get it right.
Here is how I try to do it
myMC.transform.matrix = new
Matrix(1,0.15,0.35, 1, 0, 0);
And this is the result
Can you help me to get the matrix right, or is there another way?
Thank you,
Vincent
Make your life easier and just download a 3D engine for flash 9:
http://away3d.com/downloads
Either that or you can modify your CS3 installation to produce SWF files that target flash 10+
Sorry, rotationX and rotationY are not affine transforms (they obviously do not preserve parallelism between lines), so they cannot be represented by matrix multiplication in 2D space. It is, however, affine in 3D space (where the non-preservation of parallel lines is an apparent effect of the 2D projection, not of the rotation)
i believe what you are trying to do is to get a correct affine transformation matrix.
FYR (Transformation Matrix) http://en.wikipedia.org/wiki/Transformation_matrix
Edits
For more information about 3D transforms and their matrices,
Here, see if this applies.
http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/2d_3d_xforms/
Edits 2
A blog post about 3D transform in CS3 and CS4.
3d Rotation the easy way: Buy Flash
CS4 uggh! I’m still using CS3 and only
for my Flash software. My illustrator,
photoshop, premiere, and aftereffects
are still at the lowly level of CS2
and for economic reasons, I’m stuck w/
my outdated software configuration for
awhile. But if you’re not in my boat
or on the same sea as my boat,
consider buying the latest, greatest
CS4 Flash to make 3D manipulation
inherent in flash display objects.
Yep, inherent, built in, easy.
In Flash CS3 and below, a display
object (i.e. sprite or movieclip) only
recognizes one rotation property
(rotation: Indicates the rotation of
the DisplayObject instance, in
degrees, from its original
orientation, which is usually the
upper left, corner or 0,0). This
property only rotates objects in the
2D flat space of the Flash stage. To
make 3D work in this flash, one must
“fake” it with math. Lots of math,
Points, lines, fills, trig, arrays,
and sometimes Matrices. Yippee kayae!
In Flash CS4 and above (as of writing
there is no above), a display object
(i.e. sprite or movieclip) recognizes
four (4) rotation properties. Holy
Cow! Yeah, four rotation properties:
rotation: Same as in CS3. 2D rotation.
rotationX: spin that shit around the X
axis of the stage, i.e. vertical
flipping. rotationY: spin it around
the Y axis of the stage, i.e.
horizontal flipping. rotationZ: spin,
baby spin o’er the Z axis of the
stage. As far as I’m concerned, a spin
around the Z axis is the same as
rotation (unless, for some reason, the
Z axis does not cross through the
orientation point of the object).
[http://actionscription.wordpress.com/2009/03/12/3d-rotation/]