It looks like you're new here. If you want to get involved, click one of these buttons!

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 629 Off topic board
- 217 Mobile & Wireless
- 89 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 151 WEB-Services / SOAP

Hickory
Member Posts: **56**

in 3D Graphics

I dont think this is the correct board but theres no maths board so I'll post to the most related forum. Apologies.

I'm trying to move an object through 3D space relative to its Rotation, Pitch, and Yaw. I dont have a compiler at hand but I'm writting code and need to know if this is right. x and z being the plane, and y being vertical. I'm not exactly and expert and 3D math so I'm kind of half guessing here.

x += (Amount * sinf( Rot ));

z += (Amount * cosf( Rot ));

z += (Amount * sinf( Pitch ));

y += (Amount * cosf( Pitch ));

y += (Amount * sinf( Yaw ));

x += (Amount * cosf( Yaw ));

I'm not sure I even used sin and cos on the correct dimensions. I know Rot is correct, but thats only for rot... If thats not all right, could someone tell me what is?

Thanks a million.

I'm trying to move an object through 3D space relative to its Rotation, Pitch, and Yaw. I dont have a compiler at hand but I'm writting code and need to know if this is right. x and z being the plane, and y being vertical. I'm not exactly and expert and 3D math so I'm kind of half guessing here.

x += (Amount * sinf( Rot ));

z += (Amount * cosf( Rot ));

z += (Amount * sinf( Pitch ));

y += (Amount * cosf( Pitch ));

y += (Amount * sinf( Yaw ));

x += (Amount * cosf( Yaw ));

I'm not sure I even used sin and cos on the correct dimensions. I know Rot is correct, but thats only for rot... If thats not all right, could someone tell me what is?

Thanks a million.

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

25Z will be increased by 2 Amounts (If you want this my comments are useless).

As I understood from your source,

you want to move the object along one direction

(which vector is defined by Rot, Pitch & Yaw).

So in this case it would be better to calculate

direction vector and then add it to the object's position.

You can perform 3 times of rotation on initial vector, say (0;0;1)

(X=0; Y=0; Z=1). So then you'll have direction (the length of vector

must be equal to 1) and that vector multiply by Amount.

Rotation of point is:

X'=X*cos(a)-Y*sin(a)

Y'=X*sin(a)+Y*cos(a)

where is 'a' - angle of rotation.

Usually for the above task first performing rotation of point

around Z axis, then X and finally Y (cinema camera rotation

or human's head).

56: you want to move the object along one direction

: (which vector is defined by Rot, Pitch & Yaw).

: So in this case it would be better to calculate

: direction vector and then add it to the object's position.

: You can perform 3 times of rotation on initial vector, say (0;0;1)

: (X=0; Y=0; Z=1). So then you'll have direction (the length of vector

: must be equal to 1) and that vector multiply by Amount.

:

: Rotation of point is:

: X'=X*cos(a)-Y*sin(a)

: Y'=X*sin(a)+Y*cos(a)

: where is 'a' - angle of rotation.

: Usually for the above task first performing rotation of point

: around Z axis, then X and finally Y (cinema camera rotation

: or human's head).

Thank you for your reply. I hate to bother you further, but I dont have a compiler available and my grasp of the math is poor. I think I understand what you explained, but I'm not 100% sure, and have no way to calculate it. I feel stupid asking someone to get this specific, but I'm in a tight spot.

My function is in a format as follows:

void Move(float x, float y, float z, float Rot, float Pitch, float Yaw, float Amount)

{

}

Would it be rude of me to ask you if you could show me the exact code that would be used for that function? I've never asked for complete code before and I feel a little bad doing so.

Thank you for helping.

25Well, first of all I'd like to say, that for the above task you need only 2 axises

(if you only need move object): X and Y.

Here you are...

void Rotate2D(float *x,float *y,float a) //<- this is from my source, 100% reliability.

{ // it will rotate the point CCW by 'a' radians.

float xx,yy;

xx=*x*cosf(a)-*y*sinf(a);

yy=*x*sinf(a)+*y*cosf(a);

*x=xx;*y=yy;

};

// But this function is better for objects moving, not view's camera (else you are to

// change the order)

// As you need only 1 forward vector to be directed (0;0;1), there will be only 2 rotations

// around X & Y axis.

void Move(float *x, float *y, float *z, float AxisX, float AxisY, float Amount)

{

float nx=0,ny=0,nz=1; // <- normal of init direction

Rotate2D(nz,ny, AxisX); // around X

Rotate2D(nx,nz, AxisY); // around Y

*x+=nx*Amount;

*y+=ny*Amount;

*z+=nz*Amount;

}

==============

suppose if:

x=0;y=0;z=0;

Move(&x,&y,&z, PI/2,0, 10);

will move the point up to 10 (0;10;0)

and then...

Move(&x,&y,&z, 0,0, 10);

will move the point front to 10 (0;10;10)

and more...

Move(&x,&y,&z, 0,PI/2, 10);

will move the point left to -10 (-10;10;10)

==============

But if you need to direct some object while moving along some direction, you

better use matrices (It will work faster and it is better for complex transformations)

That is all.

If you have some queries, do not hesitate to ask questions, anytime.

4The only thing it cannot do is compile executable programs, but you can run your programs in its environment...it offers pixel drawing and line drawing routines which could be used for you to learn what you want...?