77 FlexAirfoil::FlexAirfoil(Ogre::String
const & name,
ActorPtr actor,
NodeNum_t pnfld,
NodeNum_t pnfrd,
NodeNum_t pnflu,
NodeNum_t pnfru,
NodeNum_t pnbld,
NodeNum_t pnbrd,
NodeNum_t pnblu,
NodeNum_t pnbru, std::string
const & texband, Vector2 texlf, Vector2 texrf, Vector2 texlb, Vector2 texrb,
char mtype,
float controlratio,
float mind,
float maxd, Ogre::String
const & afname,
float lift_coef,
bool break_able)
110 hascontrol=(mtype!=
'n' && mtype!=
'S'&& mtype!=
'T' && mtype!=
'U'&& mtype!=
'V');
111 isstabilator=(mtype==
'S' || mtype==
'T' || mtype==
'U' || mtype==
'V');
140 subface->setMaterialName(texband);
141 subband->setMaterialName(texband);
142 subcup->setMaterialName(texband);
143 subcdn->setMaterialName(texband);
306 msh->sharedVertexData =
new VertexData();
310 decl =
msh->sharedVertexData->vertexDeclaration;
312 decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
313 offset += VertexElement::getTypeSize(VET_FLOAT3);
314 decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
315 offset += VertexElement::getTypeSize(VET_FLOAT3);
318 decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
319 offset += VertexElement::getTypeSize(VET_FLOAT2);
324 HardwareBufferManager::getSingleton().createVertexBuffer(
325 offset,
msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
331 VertexBufferBinding* bind =
msh->sharedVertexData->vertexBufferBinding;
332 bind->setBinding(0,
vbuf);
336 HardwareIndexBufferSharedPtr faceibuf = HardwareBufferManager::getSingleton().
338 HardwareIndexBuffer::IT_16BIT,
340 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
343 faceibuf->writeData(0, faceibuf->getSizeInBytes(),
facefaces,
true);
346 subface->useSharedVertices =
true;
347 subface->indexData->indexBuffer = faceibuf;
349 subface->indexData->indexStart = 0;
353 HardwareIndexBufferSharedPtr bandibuf = HardwareBufferManager::getSingleton().
355 HardwareIndexBuffer::IT_16BIT,
357 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
360 bandibuf->writeData(0, bandibuf->getSizeInBytes(),
bandfaces,
true);
363 subband->useSharedVertices =
true;
364 subband->indexData->indexBuffer = bandibuf;
366 subband->indexData->indexStart = 0;
370 HardwareIndexBufferSharedPtr cupibuf = HardwareBufferManager::getSingleton().
372 HardwareIndexBuffer::IT_16BIT,
374 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
377 cupibuf->writeData(0, cupibuf->getSizeInBytes(),
cupfaces,
true);
380 subcup->useSharedVertices =
true;
381 subcup->indexData->indexBuffer = cupibuf;
383 subcup->indexData->indexStart = 0;
387 HardwareIndexBufferSharedPtr cdnibuf = HardwareBufferManager::getSingleton().
389 HardwareIndexBuffer::IT_16BIT,
391 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
394 cdnibuf->writeData(0, cdnibuf->getSizeInBytes(),
cdnfaces,
true);
397 subcdn->useSharedVertices =
true;
398 subcdn->indexData->indexBuffer = cdnibuf;
400 subcdn->indexData->indexStart = 0;
403 msh->_setBounds(AxisAlignedBox(-20,-20,-20,20,20,20),
true);
425 else {
broken=(vx.crossProduct(vzl).squaredLength()>
sref)||(vx.crossProduct(vzr).squaredLength()>
sref);}
449 Vector3 vx=gfx_nodes[
nfrd].AbsPosition-gfx_nodes[
nfld].AbsPosition;
450 Vector3 vyl=gfx_nodes[
nflu].AbsPosition-gfx_nodes[
nfld].AbsPosition;
451 Vector3 vzl=gfx_nodes[
nbld].AbsPosition-gfx_nodes[
nfld].AbsPosition;
452 Vector3 vyr=gfx_nodes[
nfru].AbsPosition-gfx_nodes[
nfrd].AbsPosition;
453 Vector3 vzr=gfx_nodes[
nbrd].AbsPosition-gfx_nodes[
nfrd].AbsPosition;
455 Vector3 facenormal=vx;
456 facenormal.normalise();
488 Vector3 rcent, raxis;
491 rcent=((gfx_nodes[
nflu].AbsPosition+gfx_nodes[
nbld].AbsPosition)/2.0+(gfx_nodes[
nflu].AbsPosition-gfx_nodes[
nblu].AbsPosition)/4.0)-center;
492 raxis=(gfx_nodes[
nflu].AbsPosition-gfx_nodes[
nfld].AbsPosition).crossProduct(gfx_nodes[
nflu].AbsPosition-gfx_nodes[
nblu].AbsPosition);
496 rcent=((gfx_nodes[
nfru].AbsPosition+gfx_nodes[
nbrd].AbsPosition)/2.0+(gfx_nodes[
nfru].AbsPosition-gfx_nodes[
nbru].AbsPosition)/4.0)-center;
497 raxis=(gfx_nodes[
nfru].AbsPosition-gfx_nodes[
nfrd].AbsPosition).crossProduct(gfx_nodes[
nfru].AbsPosition-gfx_nodes[
nbru].AbsPosition);
500 Quaternion rot=Quaternion(Degree(
deflection), raxis);
519 v1=v1.crossProduct(v2);
530 v1=v1.crossProduct(v2);
541 v1=v1.crossProduct(v2);
601 float wspeed=wind.length();
604 float chord=chordv.length();
607 float span=spanv.length();
609 Vector3 liftv=spanv.crossProduct(-wind);
613 Vector3 normv=chordv.crossProduct(spanv);
617 pwind=Plane(Vector3::ZERO, normv, chordv).projectVector(-wind);
620 chordv.getRotationTo(-pwind).ToAngleAxis(daoa, dumb);
621 aoa=daoa.valueDegrees();
622 float raoa=daoa.valueRadians();
623 if (dumb.dotProduct(spanv)>0) {
aoa=-
aoa; raoa=-raoa;};
635 float sea_level_pressure=101325;
636 float airpressure=sea_level_pressure*
approx_pow(1.0-0.0065*altitude/288.15, 5.24947);
637 float airdensity=airpressure*0.0000120896;
639 Vector3 wforce=Vector3::ZERO;
641 wforce=(cx*0.5*airdensity*wspeed*s)*wind;
661 wforce+=(cz*0.5*airdensity*wspeed*chord)*liftv;
664 float moment=-cm*0.5*airdensity*wspeed*wspeed*s;
667 Vector3 f1=wforce*(
liftcoef * 0.75/4.0f)+normv*(
liftcoef *moment/(4.0f*0.25f));
668 Vector3 f2=wforce*(
liftcoef *0.25/4.0f)-normv*(
liftcoef *moment/(4.0f*0.75f));
688 Ogre::MeshManager::getSingleton().remove(
msh->getHandle());