Path: chuka.playstation.co.uk!news From: Craig Graham Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: 2 Questions - Same Game Date: Mon, 19 Oct 1998 14:21:16 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 42 Message-ID: <362B3CCC.6CE99F0@hinge.mistral.co.uk> References: <70f9cd$s3k10@chuka.playstation.co.uk> NNTP-Posting-Host: d1-s42-74-telehouse.mistral.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) John Whitmore wrote: > Hi, > Secondly a maths question, when moving my character around I wish to > store a vector (x,y) of the direction it is facing so a weapon can be fired > using this same vector. how is best to calculate this vector so it can be > used in this situation? > I have tried using the rotational value of the sprite, as this is how I am > changing the visual appearance of the sprite on screen, but with no success. Using just the libs you get from Sony (with no floating point emulation): // Setup a direction vector, length is up to you, I'd keep it quite large though and scale down // the value later if you need to SVECTOR direction_vector={10,0,0},rotated_direction; // Setup a matrix to rotate the vector MATRIX rotation_matrix=GsIDMATRIX; // Rotate around Z axis (2d coordinate is in X/Y axis, so rotate around Z) RotMatrixZ( sprite_rotation_angle,&rotation_matrix); // Apply the rotation ApplyMatrixSV(&rotation_matrix,&direction_vector,&rotated_direction); // Final value is in rotated_direction Or, faster (in the 2D case) is to use a quick lookup table integer version of Sin/Cos (again, no floating point emulation): // These use my own lookup table trig functions - it's easy to do one yourself.... direction_vector_x=XSinN(10,sprite_rotation_angle); // return X*Sin(N) direction_vector_y=XCosN(10,sprite_rotation_angle); // return X*Cos(N) > Thanks in advance, > > John Craig.