#include <acknex.h>
#include <default.c>
ENTITY* object;
function deform_model()
{
var vertices_max =0;
var vertex_counter =0;
VECTOR temp;
VECTOR vertex_pos;
VECTOR temp_normal;
mouse_mode = 1;
mouse_pointer = 1;
mouse_range = 4000;
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
if(mouse_ent)
{
if(mouse_left)
{
me = mouse_ent;
//send a trace at the object's surface
vec_set(temp.x, camera.pan);
vec_for_angle(temp.x, temp.x);
vec_normalize(temp.x,1000);
vec_add(temp.x, mouse_pos3d);
c_trace(mouse_pos3d,temp.x, IGNORE_PASSABLE | USE_POLYGON| SCAN_TEXTURE);
//get the hit point
vec_set(temp.x,hit.x);
//get the account of vertices of that model
vertices_max = ent_status(my, 1);
//count through the vertices
while(vertex_counter <= vertices_max)
{
vec_set(vertex_pos.x, nullvector);
vec_for_vertex(vertex_pos.x, me, vertex_counter);
//look for the vertices within a certain distance of the hit point
if(vec_dist(vertex_pos.x, temp.x)< 4)
{
vec_set(temp_normal.x, hit.nx);//move in direction of the hit normal
vec_set(vertex_pos.x, nullvector);
vec_for_vertex(vertex_pos.x, me, vertex_counter);
// vec_diff(temp_normal.x,vertex_pos.x, my.x);//move away from the model's origin
// vec_for_normal(temp_normal.x, my, vertex_counter);//move in direction of the vertex' normal
// vec_scale(temp_normal.x, 1);
vec_add(vertex_pos.x, temp_normal.x);
vec_to_mesh(vertex_pos.x, my, vertex_counter);
}
vertex_counter += 1;
}
ent_fixnormals(my,0);//recalculate the normal after moving the vertices
c_setminmax(me);//recalculate the collision
while(mouse_left)wait(1);
}
}
vertex_counter = 0;
if(mouse_right)
{
object.pan += mouse_force.x;
object.tilt += mouse_force.y;
}
camera.x += mickey.z * 0.1;
wait(1);
}
}
function main()
{
level_load(NULL);
you = ent_create(SPHERE_MDL, nullvector, NULL);
object = you;
deform_model();
camera.x = -100;
// camera.z = 20;
// camera.tilt = -10;
}