Help with meshes
Hi, well, I am trying to figure out meshes, parts, groups and the like, especially selecting them. I can do this with Phys_Hit easily enough, but I am planning a lot of meshes with simple physics if any, but need to gain the hit object and pos of the hit. Sweep seems like the answer, but I'm a bit lost. I edited lesson 14 - Mesh - Armor Rendering as below...with comments where I edited. Thanks, Rigs.
Code:
/******************************************************************************/
class Player
{
Ball bounding_ball(0); // bounding ball covering the character
MeshPtr body , // main body mesh
armor , // armor mesh
pants , // pants mesh
boots , // boots mesh
gauntlets ; // gauntlets mesh
CSkeleton cskel ; // controlled skeleton
// update
void update()
{
// set skeleton animation
cskel.clear()
.animate(UID(3342756396, 1285211226, 524185523, 499551746) , Time.time()) // animate with "left fist" animation
.animate(UID(2565101787, 1333856922, 4140992683, 1310585985), Time.time()) // animate with "right fist" animation
.animate(UID(1746491013, 1251372253, 3930150308, 1129258799), Time.time()) // animate with "walk" animation
.updateMatrix(MatrixIdentity)
.updateVelocities();
// set bounding ball
if(body)bounding_ball.setAnimated(body->box, cskel);else bounding_ball.set(2, cskel.pos());
}
// draw
void drawPrepare()
{
if(Frustum(bounding_ball)) // if player is visible in frustum
{
// add the meshes to the draw list
if(armor )armor ->draw(cskel);
if(pants )pants ->draw(cskel);
if(boots )boots ->draw(cskel);
if(gauntlets)gauntlets->draw(cskel);
if(body )body ->draw(cskel);
}
}
void drawShadow()
{
if(Frustum(bounding_ball)) // if player is visible in current shadow frustum
{
// add the meshes to the shadow draw list
if(armor )armor ->drawShadow(cskel);
if(pants )pants ->drawShadow(cskel);
if(boots )boots ->drawShadow(cskel);
if(gauntlets)gauntlets->drawShadow(cskel);
if(body )body ->drawShadow(cskel);
}
}
void createDefault()
{
// set meshes
body =Game.ObjParamsPtr(UID(2919624831, 1261075521, 753053852, 3651670215))->mesh();
armor =Game.ObjParamsPtr(UID(2031909702, 1196392633, 2341974683, 615558807))->mesh();
pants =Game.ObjParamsPtr(UID(4099872651, 1316584110, 3048579493, 1166951837))->mesh();
boots =Game.ObjParamsPtr(UID(3279260457, 1135538771, 751762862, 1888362313))->mesh();
gauntlets=Game.ObjParamsPtr(UID(3702527436, 1166112370, 2441684388, 556763633))->mesh();
// create skeleton and set initial matrixes
cskel.create(body->skeleton());
}
}
Player player;
// sweep variables - I added
MeshGroup GR; // not sure how to use ?
MeshPart MP; // not sure which to use ?
Mesh MH; //
Matrix M;
flt FRAC;
Vec POS;
int FACE;
int PRT;
int MSH;
bool wasHIT;
/******************************************************************************/
void InitPre()
{
EE_INIT();
//App.flag=APP_MS_EXCLUSIVE; // I commented out to show mouse
D.ambientPower(0.3).hpRt(true)
.shadowJitter(true).shadowSoft(1).shadowMapSize(2048)
.viewFrom(0.005).viewRange(5);
Cam.yaw = 2.7;
Cam.pitch=-0.3;
Cam.dist = 1.2;
}
/******************************************************************************/
bool Init()
{
// initialize sky & sun
Sky.atmospheric();
Sun.image=UID(1275694243, 1199742097, 1108828586, 1055787228);
Sun.pos=!Vec(1, 1, 1);
Sun.light_color=1-D.ambientColor();
// setup player data
player.createDefault();
D.full(true);
if(player.body)Cam.at=player.body->box.center(); // adjust camera to mesh center
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
if(Kb.bp(KB_ESC))return false;
CamHandle(0.01, 100, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
player.update();
// sweeping - I added
Vec start(ScreenToPos(Ms.pos(), 0.0));
Vec end(ScreenToPos(Ms.pos(), 200.0));
//Vec start(ScreenToPos((0, 0), 0.0));
//Vec end(ScreenToPos((0, 0), 200.0));
//if(Sweep(start, end-start, GR, &M, &FRAC, &POS, &FACE, &PRT, &MSH)) wasHIT=true;
if(Sweep(start, end-start, MP, &M, &FRAC, &POS, &FACE)) wasHIT=true;
return true;
}
/******************************************************************************/
void Render()
{
switch(Renderer())
{
case RM_PREPARE:
{
player.drawPrepare();
// highlighting - I added
if(wasHIT && Ms.b(0))
{
SetHighlight(Color(200, 0, 0, 128));
MP.draw(player.cskel);
SetHighlight();
}
}break;
case RM_SHADOW : player.drawShadow (); break;
}
}
void Draw()
{
Renderer(Render);
// I added text
D.text(0, 0.9, S+"wasHIT="+wasHIT);
D.text(0, 0.8, S+"meshPart Name="+MP.name);
D.text(0, 0.7, S+"hitPOS="+POS);
}
/******************************************************************************/
|