// ----------------------------------------------------------------------------
// Blitz-Irrlicht 1.8.3 Wrapper by Ed Musolino 2015
// Based off of Frank Dodd's Irrlicht 1.7 Freebasic Wrapper (2006-2010)
// ----------------------------------------------------------------------------

//  This software is provided 'as-is', without any express Or implied
//  warranty.  In no event will the authors be held liable For any damages
//  arising from the use of this software.

//  Permission is granted To anyone To use this software For any purpose,
//  including commercial applications, And To alter it And redistribute it
//  freely, subject To the following restrictions:

//  1. The Origin of this software must Not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgement in the product documentation would be
//     appreciated but is Not required.
//  2. Altered source versions must be clearly marked as such, And must Not be
//     misrepresented as being the original software.
//  3. This notice may Not be removed Or altered from any source distribution.
//
// /////////////////////////////////////////////////////////////////////////////

#include "bIrrlicht.h"


extern IrrlichtDevice*		device;
extern IVideoDriver*		driver;
extern ISceneManager*		smgr;
extern IGUIEnvironment*		guienv;


extern "C"
{

/*
ScaleEntity entity,x_scale#,y_scale#,z_scalel#,[,global]
Parameters
entity - name of the entity to be scaled 
x_scale# - x size of entity 
y_scale# - y size of entity 
z_scale# - z size of entity 
global (optional) -  

Description
Scales an entity so that it is of an absolute size. 

Scale values of 1,1,1 are the default size when creating/loading entities. 

Scale values of 2,2,2 will double the size of an entity. 

Scale values of 0,0,0 will make an entity disappear. 

Scale values of less than 0,0,0 will invert an entity and make it bigger.  
*/
/* ----------------------------------------------------------------------------
scale a node
*/
DLL_EXPORT void BBCALL iScaleNode ( IAnimatedMeshSceneNode* node, float fX, float fY, float fZ )
{
    // reposition the model
//	if(smgr->getSceneNodeFromId((s32)node))
		node->setScale(vector3df(fX,fY,fZ));
}


/*
PositionEntity entity,x#,y#,z#,[,global]
Parameters
entity - name of entity to be positioned 
x# - x co-ordinate that entity will be positioned at 
y# - y co-ordinate that entity will be positioned at 
z# - z co-ordinate that entity will be positioned at 
global (optional) - true if the position should be relative to 0,0,0 rather than a parent entity's position. False by default.  

Description
Positions an entity at an absolute position in 3D space. 

Entities are positioned using an x,y,z coordinate system. x, y and z each have their own axis, and each axis has its own set of values. By specifying a value for each axis, you can position an entity anywhere in 3D space. 0,0,0 is the centre of 3D space, and if the camera is pointing in the default positive z direction, then positioning an entity with a z value of above 0 will make it appear in front of the camera, whereas a negative z value would see it disappear behind the camera. Changing the x value would see it moving sideways, and changing the y value would see it moving up/down. 

Of course, the direction in which entities appear to move is relative to the position and orientation of the camera. 
*/
/* ----------------------------------------------------------------------------
reposition a node
*/
DLL_EXPORT void BBCALL iPositionNode ( IAnimatedMeshSceneNode* node, float X, float Y,  float Z )
{
    // reposition the model
//	if(smgr->getSceneNodeFromId((s32)node))
		node->setPosition( vector3df(X,Y,Z) );
}


/*
MoveEntity entity,x#,y#,z#
Parameters
entity - name of entity to be moved 
x# - x amount that entity will be moved by 
y# - y amount that entity will be moved by 
z# - z amount that entity will be moved by  

Description
Moves an entity relative to its current position and orientation. 

What this means is that an entity will move in whatever direction it is facing. So for example if you have an game character is upright when first loaded into Blitz3D and it remains upright (i.e. turns left or right only), then moving it by a z amount will always see it move forward or backward, moving it by a y amount will always see it move up or down, and moving it by an x amount will always see it strafe. 
*/
/* ----------------------------------------------------------------------------
move the node using matricies
*/
DLL_EXPORT void BBCALL iMoveNode ( ISceneNode* node, float x, float y, float z )
{
//	if(smgr->getSceneNodeFromId((s32)node))
//	{
		// get rotation of the node
		vector3df rot = node->getRotation();

		// create a clean matrix from the nodes current rotation
		matrix4 currentmat;
		currentmat.setRotationDegrees(rot);

		// apply positional forces to the node
		vector3df velocity( x, y, z );

		// transform the forces to the same orientation as the node
	    currentmat.transformVect( velocity );
	    node->setPosition( node->getPosition() + velocity );
	    node->updateAbsolutePosition();
//	}
}


/*
TranslateEntity entity,x#,y#,z#,[,global]
Parameters
entity - name of entity to be translated 
x# - x amount that entity will be translated by 
y# - y amount that entity will be translated by 
z# - z amount that entity will be translated by 
global (optional) -  

Description
Translates an entity relative to its current position and not its orientation. 

What this means is that an entity will move in a certain direction despite where it may be facing. Imagine that you have a game character that you want to make jump in the air at the same time as doing a triple somersault. Translating the character by a positive y amount will mean the character will always travel directly up in their air, regardless of where it may be facing due to the somersault action.  
*/



/*
RotateEntity entity,pitch#,yaw#,roll#,[,global]
Parameters
entity - name of the entity to be rotated 
pitch# - angle in degrees of pitch rotation 
yaw# - angle in degrees of yaw rotation 
roll# - angle in degrees of roll rotation 
global (optional) - true if the angle rotated should be relative to 0,0,0 rather than a parent entity's orientation. False by default.  

Description
Rotates an entity so that it is at an absolute orientation. 

Pitch is the same as the x angle of an entity, and is equivalent to tilting forward/backwards. 

Yaw is the same as the y angle of an entity, and is equivalent to turning left/right. 

Roll is the same as the z angle of an entity, and is equivalent to tilting left/right. 
*/
/* ----------------------------------------------------------------------------
rotate a node
*/
DLL_EXPORT void BBCALL iRotateNode ( IAnimatedMeshSceneNode* node, float iX, float iY, float iZ )
{
    // reposition the model
//	if(smgr->getSceneNodeFromId((s32)node))
		node->setRotation(vector3df(iX,iY,iZ));
}


/*
TurnEntity entity,pitch#,yaw#,roll#,[,global]
Parameters
entity - name of entity to be rotated 
pitch# - angle in degrees that entity will be pitched 
yaw# - angle in degrees that entity will be yawed 
roll# - angle in degrees that entity will be rolled 
global (optional) -  

Description
Turns an entity relative to its current orientation. 

Pitch is the same as the x angle of an entity, and is equivalent to tilting forward/backwards. 

Yaw is the same as the y angle of an entity, and is equivalent to turning left/right. 

Roll is the same as the z angle of an entity, and is equivalent to tilting left/right.  
*/
/* ----------------------------------------------------------------------------
turn the node using matricies
*/
DLL_EXPORT void BBCALL iTurnNode ( ISceneNode* node, float pitch, float yaw, float roll )
{
//	if(smgr->getSceneNodeFromId((s32)node))
//	{
		// place the rotations to be applied
		vector3df rPlus( pitch, yaw, roll );

		// get rotation of the node
		vector3df rot = node->getRotation();

		// create a clean matrix from the nodes current rotation
		matrix4 currentmat;
		currentmat.setRotationDegrees(rot);

		// create a clean matrix from our desired rotation
		matrix4 relmat;
		relmat.setRotationDegrees(rPlus);

		// multiply the matrices to apply the relative rotation (relative matrix must be the 2nd term)
		matrix4 resmat;
		resmat=currentmat*relmat;

		// get rotation of our final matrix
		vector3df newrot=resmat.getRotationDegrees();

		// apply our new rotation to the node
		node->setRotation(newrot);
//	}
}


/*
PointEntity entity,target[,roll#]
Parameters
entity - entity handle 
target - target entity handle 
roll# (optional) - roll angle of entity  

Description
Points one entity at another. 

The optional roll parameter allows you to specify a roll angle as pointing an entity only sets pitch and yaw angles. 

If you wish for an entity to point at a certain position rather than another entity, simply create a pivot entity at your desired position, point the entity at this and then free the pivot.  
*/



/*
AlignToVector entity,vector_x#,vector_y#,vector_z#,axis[,rate#]
Parameters
entity - entity handle 
vector_x# - vector x 
vector_y# - vector y 
vector_z# - vector z 

axis - axis of entity that will be aligned to vector 
1: x-axis 
2: y-axis 
3: z-axis 

rate# (optional) - rate at which entity is aligned from current orientation to vector orientation. Should be in the range 0 to 1, 0 for smooth transition and 1 for 'snap' transition. Defaults to 1.  
*/





















}
