RotationStation...

Started by
6 comments, last by Goodlife 24 years ago
Okay, I''m posting this again because it would blow my mind if none of you directx jocks know the answer. C''mon, TheGoop! You answered a transparency question for me that I had asked about a dozen people about, with no answer! I got a lotta faith in you! I want to rotate a pixel around a point. I have done it manually, but I want to do it with directx so that I get the performance of MMX and PIII processors. I do this: SetCenter(10,10,10); <- The point I rotate AROUND SetAngle(5,10,360); <- The yaw/pitch/roll SetScale(1,1,1); <- How much I wanna scale it Then I call about a dozen rotatepoint commands: POINT pt; pt.x=50; pt.y=50; RotatePoint(&pt) This is all unoptimized, but I wanted to get it working first. Is there some quick, simple way to do this? Can anyone provide me with code? Thanks in advance! -- Goodlife ----------------------------- Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto
Advertisement
since you have yaw,pitch,roll that turns this into a 3d problem, instead of a simple sprite rotate.
i know you''re not gonna like this answer, but...
setup a translation matrix to transform your point (let''s make z = 0) to the CenterPoint.
translate the point with the matrix.
Next setup a rotation matrix about the 3 axes with your yaw,pitch,roll.
rotate the point with the matrix.
now, set up a scale matrix with the scaling desired.
scale the point with the scale matrix.
now, translate the point back with the inverse of the first translation matrix.

then, either throw away the z value, or apply a projection matrix to the whole deal.

if you swap the order of scale and rotate, you''ll get some crazy stuff to happen.

if you are trying to draw a bitmap in this form, it will be deathly slow. if you want hw accel for this, you will have to use direct3d and use your sprite as a texture on a polygon, then just apply these transformations to the corners.

d3dutil.cpp and d3dmath.cpp have functions that will setup and manipulate the matrices for you.
if you just want to rotate in directdraw, i think there is a dwRotationAngle in the DDBLTFX structure, but i don''t think it will give you the desired results.

anyone else, let me know what i forgot.
hope it helps


crazy166
some people think i'm crazy, some people know it
if you want PIII acceleration, on Gamasutra a couple weeks ago they had a matrix library that was optimized for PIII processors.


crazy166
some people think i'm crazy, some people know it
It''s for 3d objects. Actually, I was looking for real code. I can write matrix routines for myself, from scratch, but whenever I try to use them with directx I get odd results or no results.

I actually tried to port this over to directx, but after a day and half I got such bad results that I said screw it. Wasn''t sure what I was doing wrong, so I just hoped someone had written the code before, could say "here, dude, here''s the functions to do it" or at least provide a good chunk of code for me to work with.

-- Goodlife

-----------------------------
Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto
sorry, i can only access this site at work, and i don''t have any "gaming" code here.
i can post some code up, but not until at least saturday night.
at least you might be able to get a different perspective of the problem from looking at my code.


crazy166
some people think i'm crazy, some people know it
I think I know what you mean. I can supply code, but you are going to have to get rid of the whole CPU optimization idea. It is in Visual Basic, but all of you C/C++er''s can say it is pseudo code.

// Get the Horizontal(X) and
// Vertical(Y) Angle and convert to radians
AA = AngleX * PI / 180
AB = AngleY * PI / 180

// Now the Radius is you scale.
// And CenterXYZ is your center point.
// the COS and SIN functions are for the rotations
X = CenterX + Radius * Cos(AA) * Cos(AB)
Y = CenterY + Radius * Sin(AB)
Z = CenterZ + Radius * Sin(AA) * Cos(AB)


What that is above, is a function for a circle, but it works fine for rotations. If this is not your solution then please respond.
uh oh, I forgot my User Name. Anyhoo I forgot to say it is a sphere and not a circle. Also, I got this info from Spellbound.
Hey Nes8Bit, that works for two dimensions... how about three?

Here's what I have in my code-- I have the idea that it can be optimized to do less multiplications:

(xpos,ypos,zpos are the point I am rotating MINUS the center point)

fixx=(rotxcos*xpos)-(rotxsin*ypos);
fixy=(rotxsin*xpos)+(rotxcos*ypos);
fixz=zpos;

xx=fixx;yy=fixy;zz=fixz;
fixx=(rotycos*xx)-(rotysin*zz);
fixy=(rotysin*xx)+(rotycos*zz);

xx=fixx;yy=fixy;zz=fixz;
fixy=(rotzcos*yy)-(rotzsin*zz);
fixz=(rotzsin*yy)+(rotzcos*zz);

Then I add fixx,fixy,fixz to my center point, and I have my new transformed pixel.

However, I know the purpose of a matrix is to minimize the multiplication-- all my angles are determined beforehand, so how can I cut this down?




Edited by - Goodlife on 4/9/00 8:17:40 AM
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto

This topic is closed to new replies.

Advertisement