# [Code]Entity Translation Transformation & Rotation Transformation

#### Jerry小坏

##### YEA
✔️ HL Verified
/** This is about the Matrix Knowledge, and the code below is based on Matrix Multiplication. **/

/***************************************************************************/

Set Entity Origin Forward:
PHP:
``````	new Float: vAng[3], Float: vec[3];
pev( Client, pev_v_angle, vAng );
angle_vector( vAng, 2, vec );
new Float: vec2[3];

/* Forward */
vec2[0] = vec[0];
vec2[1] = vec[1];
vec2[2] = vec[2] + -1.0;

new Float: vecForward[3];
xs_vec_cross( vec, vec2, vecForward );
xs_vec_normalize(vecForward, vecForward);

new Float: org[3];
pev( Client, pev_origin, org );

/* Distance */
org[0] = ( vecForward[0] * 150.0 ) + org[0];
org[1] = ( vecForward[1] * 150.0 ) + org[1];
org[2] = ( vecForward[2] * 150.0 ) + org[2];

set_pev( Client, pev_origin, org );``````

Set Entity Origin Backward:
PHP:
``````	new Float: vAng[3], Float: vec[3];
pev( Client, pev_v_angle, vAng );
angle_vector( vAng, 2, vec );
new Float: vec2[3];

/* Backward */
vec2[0] = vec[0];
vec2[1] = vec[1];
vec2[2] = vec[2] + 1.0;

new Float: vecBackward[3];
xs_vec_cross( vec, vec2, vecBackward );
xs_vec_normalize(vecBackward, vecBackward);

new Float: org[3];
pev( Client, pev_origin, org );

/* Distance */
org[0] = ( vecBackward[0] * 150.0 ) + org[0];
org[1] = ( vecBackward[1] * 150.0 ) + org[1];
org[2] = ( vecBackward[2] * 150.0 ) + org[2];

set_pev( Client, pev_origin, org );``````

Set Entity Origin Leftward:
PHP:
``````	new Float: vAng[3], Float: vec[3];
pev( Client, pev_v_angle, vAng );

/* Leftward */
vAng[1] -= 90.0

angle_vector( vAng, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0];
vec2[1] = vec[1];
vec2[2] = vec[2] + 1.0;

new Float: vecLeftward[3];
xs_vec_cross( vec, vec2, vecLeftward );
xs_vec_normalize(vecLeftward, vecLeftward);

new Float: org[3];
pev( Client, pev_origin, org );
org[0] = ( vecLeftward[0] * 150.0 ) + org[0];
org[1] = ( vecLeftward[1] * 150.0 ) + org[1];
org[2] = ( vecLeftward[2] * 150.0 ) + org[2];
set_pev( Client, pev_origin, org );``````

Set Entity Origin Rightward:
PHP:
``````	new Float: vAng[3], Float: vec[3];
pev( Client, pev_v_angle, vAng );

/* Rightward */
vAng[1] += 90.0

angle_vector( vAng, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0];
vec2[1] = vec[1];
vec2[2] = vec[2] + 1.0;

new Float: vecRightward[3];
xs_vec_cross( vec, vec2, vecRightward );
xs_vec_normalize(vecRightward, vecRightward);

new Float: org[3];
pev( Client, pev_origin, org );
org[0] = ( vecRightward[0] * 150.0 ) + org[0];
org[1] = ( vecRightward[1] * 150.0 ) + org[1];
org[2] = ( vecRightward[2] * 150.0 ) + org[2];
set_pev( Client, pev_origin, org );``````

Vertical Forward Rotation:

PHP:
``````public server_frame( )
{
if( !is_valid_ent( ent ) ) return;

new Float: ang[3], Float: vec[3];
pev( ent, pev_angles, ang );

/* Vertical Forward */
ang[0] += 1.0;// Speed
ang[2] = 180.0;
set_pev( ent, pev_angles, ang );

angle_vector( ang, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0];
vec2[1] = vec[1] + 1.0;
vec2[2] = vec[2];

new Float: vecForward[3];
xs_vec_cross( vec, vec2, vecForward );
xs_vec_normalize( vecForward, vecForward );

/* The origin of the centre of the circle */
new Float: org[3];
pev( 1, pev_origin, org );
org[0] = ( vecForward[0] * 30.0 ) + org[0];// 30.0 = Radius
org[1] = ( vecForward[1] * 30.0 ) + org[1];
org[2] = ( vecForward[2] * 30.0 ) + org[2];

set_pev( ent, pev_origin, org );
}``````

Vertical Backward Rotation:
PHP:
``````public server_frame( )
{
if( !is_valid_ent( ent ) ) return;

new Float: ang[3], Float: vec[3];
pev( ent, pev_angles, ang );

/* Vertical Backward */
ang[0] -= 1.0;// Speed
ang[2] = 180.0;
set_pev( ent, pev_angles, ang );

angle_vector( ang, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0];
vec2[1] = vec[1] + 1.0;
vec2[2] = vec[2];

new Float: vecBackward[3];
xs_vec_cross( vec, vec2, vecBackward );
xs_vec_normalize( vecBackward, vecBackward );

/* The origin of the centre of the circle */
new Float: org[3];
pev( 1, pev_origin, org );
org[0] = ( vecBackward[0] * 30.0 ) + org[0];// 30.0 = Radius
org[1] = ( vecBackward[1] * 30.0 ) + org[1];
org[2] = ( vecBackward[2] * 30.0 ) + org[2];

set_pev( ent, pev_origin, org );
}``````

Clockwise Plane Rotation:
PHP:
``````public server_frame( )
{
if( !is_valid_ent( ent ) ) return;

new Float: ang[3], Float: vec[3];
pev( ent, pev_angles, ang );

/* Clockwise */
ang[1] -= 1.0;// Speed
set_pev( ent, pev_angles, ang );

angle_vector( ang, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0];
vec2[1] = vec[1];
vec2[2] = vec[2] + 1.0;

new Float: vecRightward[3];
xs_vec_cross( vec, vec2, vecRightward );
xs_vec_normalize( vecRightward, vecRightward );

/* The origin of the centre of the circle */
new Float: org[3];
pev( 1, pev_origin, org );
org[0] = ( vecRightward[0] * 30.0 ) + org[0];// 30.0 = Radius
org[1] = ( vecRightward[1] * 30.0 ) + org[1];
org[2] = ( vecRightward[2] * 30.0 ) + org[2];

set_pev( ent, pev_origin, org );
}``````

Anti-clockwise Plane Rotation:
PHP:
``````public server_frame( )
{
if( !is_valid_ent( ent ) ) return;

new Float: ang[3], Float: vec[3];
pev( ent, pev_angles, ang );

/* Anti-clockwise */
ang[1] += 1.0;// Speed
set_pev( ent, pev_angles, ang );

angle_vector( ang, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0];
vec2[1] = vec[1];
vec2[2] = vec[2] + 1.0;

new Float: vecLeftward[3];
xs_vec_cross( vec, vec2, vecLeftward );
xs_vec_normalize( vecLeftward, vecLeftward );

/* The origin of the centre of the circle */
new Float: org[3];
pev( 1, pev_origin, org );
org[0] = ( vecLeftward[0] * 30.0 ) + org[0];// 30.0 = Radius
org[1] = ( vecLeftward[1] * 30.0 ) + org[1];
org[2] = ( vecLeftward[2] * 30.0 ) + org[2];

set_pev( ent, pev_origin, org );
}``````

Vertical Leftward Rotation:
PHP:
``````public server_frame( )
{
if( !is_valid_ent( ent ) ) return;

new Float: ang[3], Float: vec[3];
pev( ent, pev_angles, ang );

/* Vertical Leftward */
ang[1] = 180.0;// Speed
ang[2] += 1.0;
set_pev( ent, pev_angles, ang );

angle_vector( ang, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0] + 1.0;
vec2[1] = vec[1];
vec2[2] = vec[2];

new Float: vecLeftward[3];
xs_vec_cross( vec, vec2, vecLeftward );
xs_vec_normalize( vecLeftward, vecLeftward );

/* The origin of the centre of the circle */
new Float: org[3];
pev( 1, pev_origin, org );
org[0] = ( vecLeftward[0] * 30.0 ) + org[0];// 30.0 = Radius
org[1] = ( vecLeftward[1] * 30.0 ) + org[1];
org[2] = ( vecLeftward[2] * 30.0 ) + org[2];

set_pev( ent, pev_origin, org );
}``````

Vertical Rightward Rotation:
PHP:
``````public server_frame( )
{
if( !is_valid_ent( ent ) ) return;

new Float: ang[3], Float: vec[3];
pev( ent, pev_angles, ang );

/* Vertical Righttward */
ang[1] = 180.0;// Speed
ang[2] -= 1.0;
set_pev( ent, pev_angles, ang );

angle_vector( ang, 2, vec );
new Float: vec2[3];

vec2[0] = vec[0] + 1.0;
vec2[1] = vec[1];
vec2[2] = vec[2];

new Float: vecRighttward[3];
xs_vec_cross( vec, vec2, vecRighttward );
xs_vec_normalize( vecRighttward, vecRighttward );

/* The origin of the centre of the circle */
new Float: org[3];
pev( 1, pev_origin, org );
org[0] = ( vecRighttward[0] * 30.0 ) + org[0];// 30.0 = Radius
org[1] = ( vecRighttward[1] * 30.0 ) + org[1];
org[2] = ( vecRighttward[2] * 30.0 ) + org[2];

set_pev( ent, pev_origin, org );
}``````