34 Airbrake::Airbrake(
ActorPtr actor,
const char* basename,
int num,
node_t* ndref,
node_t* ndx,
node_t* ndy,
node_t* nda, Ogre::Vector3 pos,
float width,
float length,
float maxang, std::string
const & texname,
float tx1,
float ty1,
float tx2,
float ty2,
float lift_coef)
43 area = width * length * lift_coef;
45 sprintf(meshname,
"airbrakemesh-%s-%i", basename, num);
56 SubMesh* sub = msh->createSubMesh();
59 sub->setMaterialName(texname);
63 size_t vbufCount = (2 * 3 + 2) * nVertices;
64 vertices = (
float*)malloc(vbufCount *
sizeof(
float));
67 covertices[0].
texcoord = Vector2(tx1, ty1);
68 covertices[1].texcoord = Vector2(tx2, ty1);
69 covertices[2].texcoord = Vector2(tx2, ty2);
70 covertices[3].texcoord = Vector2(tx1, ty2);
74 size_t ibufCount = 3 * 4;
75 unsigned short* faces = (
unsigned short*)malloc(ibufCount *
sizeof(
unsigned short));
90 covertices[0].vertex = Vector3(0, 0, 0);
91 covertices[1].vertex = Vector3(width, 0, 0);
92 covertices[2].vertex = Vector3(width, 0, length);
93 covertices[3].vertex = Vector3(0, 0, length);
95 covertices[0].normal = Vector3(0, 1, 0);
96 covertices[1].normal = Vector3(0, 1, 0);
97 covertices[2].normal = Vector3(0, 1, 0);
98 covertices[3].normal = Vector3(0, 1, 0);
101 msh->sharedVertexData =
new VertexData();
102 msh->sharedVertexData->vertexCount = nVertices;
105 VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
107 decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
108 offset += VertexElement::getTypeSize(VET_FLOAT3);
109 decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
110 offset += VertexElement::getTypeSize(VET_FLOAT3);
113 decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
114 offset += VertexElement::getTypeSize(VET_FLOAT2);
118 HardwareVertexBufferSharedPtr vbuf =
119 HardwareBufferManager::getSingleton().createVertexBuffer(
120 offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
123 vbuf->writeData(0, vbuf->getSizeInBytes(), vertices,
true);
126 VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
127 bind->setBinding(0, vbuf);
130 HardwareIndexBufferSharedPtr faceibuf = HardwareBufferManager::getSingleton().
132 HardwareIndexBuffer::IT_16BIT,
134 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
137 faceibuf->writeData(0, faceibuf->getSizeInBytes(), faces,
true);
140 sub->useSharedVertices =
true;
141 sub->indexData->indexBuffer = faceibuf;
142 sub->indexData->indexCount = ibufCount;
143 sub->indexData->indexStart = 0;
146 msh->_setBounds(AxisAlignedBox(-1, -1, 0, 1, 1, 0),
true);
154 sprintf(entname,
"airbrakenode-%s-%i", basename, num);
157 snode->attachObject(ec);
165 void Airbrake::updatePosition(
float amount)
171 void Airbrake::applyForce()
174 float altitude = noderef->AbsPosition.y;
176 float sea_level_pressure = 101325;
178 float airpressure = sea_level_pressure * pow(1.0 - 0.0065 * altitude / 288.15, 5.24947);
179 float airdensity = airpressure * 0.0000120896;
181 Vector3 wind = -noderef->Velocity;
182 float wspeed = wind.length();
184 Vector3 drag = (1.2 * area * sin(fabs(ratio * maxangle / 57.3)) * 0.5 * airdensity * wspeed / 4.0) * wind;
185 noderef->Forces += drag;
186 nodex->Forces += drag;
187 nodey->Forces += drag;
188 nodea->Forces += drag;