void Label::Draw() { //If this assert is hit, it means there isn't a Shader set assert(m_Shader != nullptr); //Is the render target null if(m_RenderTarget != nullptr) { //Draw the render target m_RenderTarget->GetTextureFrame()->Draw(m_ModelMatrix); } else { //Draw the text with out the render target DrawText(); } //Draw a debug label rect #if DRAW_LABEL_RECT Rect rect(GetWorldPosition().x, GetWorldPosition().y, GetWidth(), GetHeight()); rect.SetIsFilled(false); rect.SetColor(DRAW_LABEL_RECT_COLOR); rect.SetAnchorPoint(GetAnchorPoint()); rect.SetLocalAngle(GetWorldAngle()); rect.SetLocalScale(GetWorldScale()); rect.Draw(); #endif //Draw the GameObject, which draws all the children GameObject::Draw(); }
const bool VCNRenderNode::UpdateWorldTransform() { if ( VCNNode::UpdateWorldTransform() ) { // Update mesh bounding sphere const VCNResID meshID = GetMeshID(); if ( meshID != kInvalidResID ) { VCNMesh* mesh = VCNResourceCore::GetInstance()->GetResource<VCNMesh>(meshID); const VCNSphere boundingSphere = mesh->GetBoundingSphere(); // Transform the sphere relative to the render node const Vector3 ascSacle = GetWorldScale(); const VCNFloat radius = boundingSphere.GetRadius() * std::max(ascSacle.x, std::max(ascSacle.y, ascSacle.z)); mBoundingSphere.Set( radius, boundingSphere.GetCenter() * mWorld ); mBoundingBox.vcMin = (mesh->GetBoundingBox().vcMin.MulComponents(ascSacle)) + GetWorldTranslation(); mBoundingBox.vcMax = (mesh->GetBoundingBox().vcMax.MulComponents(ascSacle)) + GetWorldTranslation(); } return true; } return false; }
void Label::ResetModelMatrix() { //Translate the anchor, then translate the position mat4 anchor = translate(mat4(1.0f), vec3(-GetWidth() * GetWorldScale().x * GetAnchorPoint().x, -GetHeight() * GetWorldScale().y * GetAnchorPoint().y, 0.0f)); mat4 viewTranslate = translate(anchor, vec3(GetWorldPosition().x, GetWorldPosition().y, 0.0f)); //Calculate the rotation based on the anchor point mat4 halfTranslate1 = translate(viewTranslate, vec3(GetWidth() * GetWorldScale().x * GetAnchorPoint().x, GetHeight() * GetWorldScale().y * GetAnchorPoint().y, 0.0f)); mat4 viewRotation = rotate(halfTranslate1, GetWorldAngle(), vec3(0.0f, 0.0f, 1.0f)); mat4 halfTranslate2 = translate(viewRotation, vec3(-GetWidth() * GetWorldScale().x * GetAnchorPoint().x, -GetHeight() * GetWorldScale().y * GetAnchorPoint().y, 0.0f)); //Lastly the scale m_ModelMatrix = scale(halfTranslate2, vec3(GetWorldScale().x, GetWorldScale().y, 0.0f)); //Reset the model matrix GameObject::ResetModelMatrix(); }
void Polygon::ResetModelMatrix() { //Local variables used below float left = 0.0f; float right = 0.0f; float bottom = 0.0f; float top = 0.0f; //Cycle through and set the left, right, bottom and top vars for(unsigned int i = 0; i < m_Vertices.size(); i++) { left = fminf(left, m_Vertices.at(i).x); right = fmaxf(right, m_Vertices.at(i).x); bottom = fminf(bottom, m_Vertices.at(i).y); top = fmaxf(top, m_Vertices.at(i).y); } //Set the width and height float width = right - left; float height = top - bottom; //Translate the anchor, then translate the position mat4 anchor = translate(mat4(1.0f), vec3(-width * GetWorldScale().x * GetAnchorPoint().x, -height * GetWorldScale().y * GetAnchorPoint().y, 0.0f)); mat4 viewTranslate = translate(anchor, vec3(GetWorldPosition().x, GetWorldPosition().y, 0.0f)); //Calculate the rotation based on the anchor point mat4 halfTranslate1 = translate(viewTranslate, vec3(width * GetWorldScale().x * GetAnchorPoint().x, height * GetWorldScale().y * GetAnchorPoint().y, 0.0f)); #if DRAW_POLYGON_ANCHOR_POINT vec4 transformedVector = halfTranslate1 * vec4(0.0f, 0.0f, 0.0f, 1.0); m_AnchorLocation = vec2(transformedVector.x, transformedVector.y); #endif mat4 viewRotation = rotate(halfTranslate1, GetWorldAngle(), vec3(0.0f, 0.0f, 1.0f)); mat4 halfTranslate2 = translate(viewRotation, vec3(-width * GetWorldScale().x * GetAnchorPoint().x, -height * GetWorldScale().y * GetAnchorPoint().y, 0.0f)); //Lastly the scale m_ModelMatrix = scale(halfTranslate2, vec3(GetWorldScale().x, GetWorldScale().y, 0.0f)); //Reset the model matrix GameObject::ResetModelMatrix(); }
//------------------------------------------------------------------------------------------------------- void LightNode::Update( uint milisecon ) { if( isChange() || isFatherChange() || m_isLightChange ) { if ( isChange() || isFatherChange() ) { LocatableObject::Update( milisecon ); vector3f ws = GetWorldScale(); m_MaxScale = Math::GetMin( ws.m_x, Math::GetMin( ws.m_y, ws.m_z ) ); if ( m_eLightType != LT_POINT ) { m_WorldDirection = LightDirectionRaw * GetWorldRotation(); m_WorldUp = LightUpRaw * GetWorldRotation(); } CastChangedMessage();//通知子节点 _SetChangeFlag( false ); } m_isLightChange = false; _OnLightChangeRecaculater();//告诉自己的继承类,灯光变了 } }
void PhysicsServer::ProcessCollision( void *data, dGeomID o1, dGeomID o2 ) { // skip connected bodies dBodyID bodyID1 = dGeomGetBody( o1 ); dBodyID bodyID2 = dGeomGetBody( o2 ); if (bodyID1 && bodyID2 && dAreConnected( bodyID1, bodyID2 )) return; if (!bodyID1 && !bodyID2) return; // do collision int nContacts = dCollide( o1, o2, c_MaxContacts, &m_Contacts[0].geom, sizeof( dContact ) ); if (nContacts == 0) return; float scale = GetWorldScale(); nContacts = tmin( nContacts, c_MaxContacts - m_NContacts ); for (int i = 0; i < nContacts; i++) { PhysMaterial* pSurf1 = GetGeomSurface( o1 ); PhysMaterial* pSurf2 = GetGeomSurface( o2 ); dContact& contact = m_Contacts[i]; dSurfaceParameters& surface = contact.surface; // TODO: proper flags setup m_Contacts[i].surface.mode = //dContactApprox1 | //dContactFDir1 | dContactSoftERP | dContactSoftCFM | //dContactSlip1 | //dContactSlip2 | dContactBounce; if (!pSurf1 && !pSurf2) { surface.mu = 8.0f; surface.mu2 = 8.0f; surface.bounce = 1.0f; surface.bounce_vel = 0.0f; surface.soft_erp = 0.1f; surface.soft_cfm = 1e-3f; surface.motion1 = 0.0f; surface.motion2 = 0.0f; surface.slip1 = 0.1f; surface.slip2 = 0.1f; } else if (pSurf2 == pSurf1) { surface.mu = pSurf1->m_Mu; surface.mu2 = pSurf1->m_Mu2; surface.bounce = pSurf1->m_Bounce; surface.bounce_vel = pSurf1->m_BounceVel; surface.soft_erp = pSurf1->m_SoftERP; surface.soft_cfm = pSurf1->m_SoftCFM; surface.motion1 = pSurf1->m_Motion1; surface.motion2 = pSurf1->m_Motion2; surface.slip1 = pSurf1->m_Slip1; surface.slip2 = pSurf1->m_Slip2; } else { if (!pSurf1) pSurf1 = pSurf2; if (!pSurf2) pSurf2 = pSurf1; surface.mu = sqrtf( pSurf1->m_Mu * pSurf2->m_Mu ); surface.mu2 = sqrtf( pSurf1->m_Mu2 * pSurf2->m_Mu2 ); surface.bounce = 0.5f*( pSurf1->m_Bounce + pSurf2->m_Bounce ); surface.bounce_vel = tmin( pSurf1->m_BounceVel, pSurf2->m_BounceVel ); surface.soft_erp = sqrtf( pSurf1->m_SoftERP * pSurf2->m_SoftERP ); surface.soft_cfm = 0.5f*( pSurf1->m_SoftCFM + pSurf2->m_SoftCFM ); surface.motion1 = sqrtf( pSurf1->m_Motion1 * pSurf2->m_Motion1 ); surface.motion2 = sqrtf( pSurf1->m_Motion2 * pSurf2->m_Motion2 ); surface.slip1 = sqrtf( pSurf1->m_Slip1 * pSurf2->m_Slip1 ); surface.slip2 = sqrtf( pSurf1->m_Slip2 * pSurf2->m_Slip2 ); } PhysObject* pObj1 = (PhysObject*)dGeomGetData( o1 ); PhysObject* pObj2 = (PhysObject*)dGeomGetData( o2 ); int obj1 = pObj1 ? pObj1->GetID() : -1; int obj2 = pObj2 ? pObj2->GetID() : -1; dContactGeom& geom = contact.geom; m_NContacts++; if (IsDrawBounds()) { Vec3 pos = Vec3( geom.pos[0], geom.pos[1], geom.pos[2] ); pos /= scale; Vec3 norm = Vec3( geom.normal[0], geom.normal[1], geom.normal[2] ); const float c_HandleSize = 0.3f; g_pDrawServer->SetWorldTM( Mat4::identity ); g_pDrawServer->DrawBox( AABox( pos, c_HandleSize*0.5f ), 0x5500FF00, 0x22FFFF00 ); g_pDrawServer->DrawLine( pos, pos + norm*c_HandleSize, 0x5500FF00, 0x5500FF00 ); } dJointID jID = dJointCreateContact( m_WorldID, m_ContactGroupID, &contact ); dJointAttach( jID, bodyID1, bodyID2 ); } } // PhysicsServer::ProcessCollision
//-------------------------------------------------------------------------------------------------------------------------------------- void Emitter::Update(uint millisecond) { LocatableObject::Update( millisecond ); m_isInview = false; if( !m_isForceStop ) { if( isEmit() || m_uLifedTime <= m_EmitterLife + m_LifeSpan.m_y )//如果粒子还活着 { aabbox3df worldbox = m_BindBox; //初始的绑定和不能变 worldbox.SetCenter( GetWorldPosition() ); if ( Engine::Instance().GetCamera()->GetFrustum().Intersect( worldbox ) )//判断是否可视 { m_isInview = true; } //更新粒子 m_uLifedTime += millisecond; if( m_isInview ) { m_ActiveTime += millisecond; if( m_isEmit ) { m_isEmit = m_uLifedTime < m_EmitterLife || m_EmitterLife < 0;//计算是否继续发射 vector2d view = Engine::Instance().GetDevice()->GetResolutionSize(); float particlesize = ( view.m_x + view.m_y ) * 0.5; float worldscale = Math::GetMax( GetWorldScale().m_x, Math::GetMax( GetWorldScale().m_y, GetWorldScale().m_z ) ); m_uTimeSpan += millisecond; int randomNum = Math::Random(m_CountSec.m_x, m_CountSec.m_y); float fnum = randomNum * TO_SEC( m_uTimeSpan ); int relaseNum = fnum; if( 0 != relaseNum) { m_uTimeSpan = ( fnum - relaseNum ) / randomNum * m_uTimeSpan; //计算一下小数位置的粒子个数是对应多长时间差内的粒子个数,这个是降低误差用的 relaseNum = Math::GetMin( relaseNum , m_Index.Max() ); int beginIndex = m_Index; for (int i = 0 ; i < relaseNum ; i++) { Quaternionf rotation; rotation.YawPitchRoll(Math::fRandom(-m_Angle.m_y,m_Angle.m_y), Math::fRandom(-m_Angle.m_x,m_Angle.m_x) , Math::fRandom(-m_Angle.m_z,m_Angle.m_z)); //Matrix33f rotation; //rotation.YawPitchRoll(fRandom(-m_Angle.m_y,m_Angle.m_y), fRandom(-m_Angle.m_x,m_Angle.m_x) , fRandom(-m_Angle.m_z,m_Angle.m_z)); vector3f Velocity = m_Direction * rotation * GetWorldRotation(); Velocity.NormalizeSelf(); Velocity *= ( Math::fRandom( m_Speed.m_x , m_Speed.m_y ) ); Color Beginclr, Endclr, clrInc; if( m_isBeginChangeColor ) { Beginclr = Color(Math::fRandom(m_BeginColorA.m_r, m_BeginColorB.m_r),Math::fRandom(m_BeginColorA.m_g, m_BeginColorB.m_g),Math::fRandom(m_BeginColorA.m_b, m_BeginColorB.m_b),Math::fRandom(m_BeginColorA.m_a, m_BeginColorB.m_a)); } else { Beginclr = m_BeginColorA; } if( m_isEndChangeColor ) { Endclr = Color(Math::fRandom(m_EndColorA.m_r, m_EndColorB.m_r),Math::fRandom(m_EndColorA.m_g, m_EndColorB.m_g),Math::fRandom(m_EndColorA.m_b, m_EndColorB.m_b),Math::fRandom(m_EndColorA.m_a, m_EndColorB.m_a)); } else { Endclr = m_EndColorA; } if( m_PositionNoise == vector3f::Zero() ) { m_pParticle[m_Index].Create( GetWorldPosition(), Beginclr, Endclr, Velocity * worldscale, m_ActiveTime, Math::Random(m_LifeSpan.m_x, m_LifeSpan.m_y), Math::fRandom(m_BeginSize.m_x, m_BeginSize.m_y) * particlesize * worldscale, Math::fRandom(m_EndSize.m_x, m_EndSize.m_y) * particlesize * worldscale, Math::fRandom(m_ColorPow.m_x, m_ColorPow.m_y), Math::fRandom(m_AlphaPow.m_x, m_AlphaPow.m_y), Math::fRandom(m_SizePow.m_x, m_SizePow.m_y) ); m_Index++; } else { m_pParticle[m_Index].Create( GetWorldPosition() + vector3f( Math::fRandom( -m_PositionNoise.m_x, m_PositionNoise.m_x ), Math::fRandom( -m_PositionNoise.m_y, m_PositionNoise.m_y ), Math::fRandom( -m_PositionNoise.m_z, m_PositionNoise.m_z ) ) * worldscale, Beginclr, Endclr, Velocity * worldscale, m_ActiveTime, Math::Random(m_LifeSpan.m_x, m_LifeSpan.m_y), Math::fRandom(m_BeginSize.m_x, m_BeginSize.m_y) * particlesize * worldscale, Math::fRandom(m_EndSize.m_x, m_EndSize.m_y) * particlesize * worldscale, Math::fRandom(m_ColorPow.m_x, m_ColorPow.m_y), Math::fRandom(m_AlphaPow.m_x, m_AlphaPow.m_y), Math::fRandom(m_SizePow.m_x, m_SizePow.m_y) ); m_Index++; } } if( beginIndex + relaseNum > m_ArraySize ) //头尾事件,从新flush { int toend = m_ArraySize - beginIndex; m_pVertexBuffer->FlushVertexBuffer( beginIndex, toend, &m_pParticle[beginIndex] ); m_pVertexBuffer->FlushVertexBuffer( 0, relaseNum - toend, &m_pParticle[0] ); } else { m_pVertexBuffer->FlushVertexBuffer( beginIndex, relaseNum, &m_pParticle[beginIndex] ); } } } } } } }