void EditorBodyControl::ApplyTransform(float32 x, float32 y, float32 z) { if (!InModificationMode()) return; Entity *selectedNode = scene->GetProxy(); if(selectedNode) { Matrix4 modification; modification.Identity(); Matrix4 t1, t2; t1.CreateTranslation(-selectedNode->GetWorldTransform().GetTranslationVector()); t2.CreateTranslation(selectedNode->GetWorldTransform().GetTranslationVector()); switch (GetModificationMode()) { case ResourceEditor::MODIFY_MOVE: modification.CreateTranslation(Vector3(x, y, z)); break; case ResourceEditor::MODIFY_ROTATE: modification.CreateRotation(Vector3(1, 0, 0), DegToRad(x)); modification *= Matrix4::MakeRotation(Vector3(0, 1, 0), DegToRad(y)); modification *= Matrix4::MakeRotation(Vector3(0, 0, 1), DegToRad(z)); modification = (t1 * modification) * t2; break; case ResourceEditor::MODIFY_SCALE: modification.CreateScale(Vector3(1, 1, 1) + Vector3(x + y + z, x + y + z, x + y + z) / 100.f); modification = (t1 * modification) * t2; break; default: break; } Matrix4 originalTransform = selectedNode->GetLocalTransform(); modification = originalTransform * modification; if (IsLandscapeRelative()) { modification = modification * GetLandscapeOffset(modification); } CommandsManager::Instance()->ExecuteAndRelease(new CommandTransformObject(selectedNode, originalTransform, modification), scene); } }
void ParticleLayer3D::Draw(Camera * camera) { if(!sprite) return; Matrix4 rotationMatrix = Matrix4::IDENTITY; switch(RenderManager::Instance()->GetRenderOrientation()) { case Core::SCREEN_ORIENTATION_LANDSCAPE_LEFT: //glRotatef(90.0f, 0.0f, 0.0f, 1.0f); rotationMatrix.CreateRotation(Vector3(0.0f, 0.0f, 1.0f), DegToRad(90.0f)); break; case Core::SCREEN_ORIENTATION_LANDSCAPE_RIGHT: //glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); rotationMatrix.CreateRotation(Vector3(0.0f, 0.0f, 1.0f), DegToRad(-90.0f)); break; } Matrix4 mv = RenderManager::Instance()->GetMatrix(RenderManager::MATRIX_MODELVIEW)*rotationMatrix; Vector3 _up(mv._01, mv._11, mv._21); Vector3 _left(mv._00, mv._10, mv._20); verts.clear(); textures.clear(); colors.clear(); int32 totalCount = 0; Particle * current = head; if(current) { renderBatch->GetMaterial()->GetRenderState()->SetTexture(sprite->GetTexture(current->frame)); } while(current != 0) { Vector3 dx(_left); Vector3 dy(_up); //dx *= sqrt(2.f); //dy *= sqrt(2.f); float32 sine; float32 cosine; SinCosFast(current->angle, sine, cosine); float32 pivotRight = ((sprite->GetWidth()-pivotPoint.x)*current->size.x*current->sizeOverLife)/2.f; float32 pivotLeft = (pivotPoint.x*current->size.x*current->sizeOverLife)/2.f; float32 pivotUp = (pivotPoint.y*current->size.y*current->sizeOverLife)/2.f; float32 pivotDown = ((sprite->GetHeight()-pivotPoint.y)*current->size.y*current->sizeOverLife)/2.f; Vector3 dxc = dx*cosine; Vector3 dxs = dx*sine; Vector3 dyc = dy*cosine; Vector3 dys = dy*sine; Vector3 topLeft = current->position+(-dxc+dys)*pivotUp + (dxs+dyc)*pivotLeft; Vector3 topRight = current->position+(-dxs-dyc)*pivotRight + (-dxc+dys)*pivotUp; Vector3 botLeft = current->position+(dxs+dyc)*pivotLeft + (dxc-dys)*pivotDown; Vector3 botRight = current->position+(dxc-dys)*pivotDown + (-dxs-dyc)*pivotRight; verts.push_back(topLeft.x);//0 verts.push_back(topLeft.y); verts.push_back(topLeft.z); verts.push_back(topRight.x);//1 verts.push_back(topRight.y); verts.push_back(topRight.z); verts.push_back(botLeft.x);//2 verts.push_back(botLeft.y); verts.push_back(botLeft.z); verts.push_back(botLeft.x);//2 verts.push_back(botLeft.y); verts.push_back(botLeft.z); verts.push_back(topRight.x);//1 verts.push_back(topRight.y); verts.push_back(topRight.z); verts.push_back(botRight.x);//3 verts.push_back(botRight.y); verts.push_back(botRight.z); float32 *pT = sprite->GetTextureVerts(current->frame); textures.push_back(pT[0]); textures.push_back(pT[1]); textures.push_back(pT[2]); textures.push_back(pT[3]); textures.push_back(pT[4]); textures.push_back(pT[5]); textures.push_back(pT[4]); textures.push_back(pT[5]); textures.push_back(pT[2]); textures.push_back(pT[3]); textures.push_back(pT[6]); textures.push_back(pT[7]); // Yuri Coder, 2013/04/03. Need to use drawColor here instead of just colot // to take colorOverlife property into account. uint32 color = (((uint32)(current->drawColor.a*255.f))<<24) | (((uint32)(current->drawColor.b*255.f))<<16) | (((uint32)(current->drawColor.g*255.f))<<8) | ((uint32)(current->drawColor.r*255.f)); for(int32 i = 0; i < 6; ++i) { colors.push_back(color); } totalCount++; current = TYPE_PARTICLES == type ? current->next : 0; } renderBatch->SetTotalCount(totalCount); if(totalCount > 0) { renderData->SetStream(EVF_VERTEX, TYPE_FLOAT, 3, 0, &verts.front()); renderData->SetStream(EVF_TEXCOORD0, TYPE_FLOAT, 2, 0, &textures.front()); renderData->SetStream(EVF_COLOR, TYPE_UNSIGNED_BYTE, 4, 0, &colors.front()); renderBatch->SetRenderDataObject(renderData); } }
void EditorBodyControl::PrepareModMatrix(const Vector2 & point) { float32 winx = point.x - touchStart.x; float32 winy = point.y - touchStart.y; Matrix4 modification; modification.Identity(); ArrowsNode* arrowsNode = GetArrowsNode(false); if (!arrowsNode) return; if (GetModificationMode() == ResourceEditor::MODIFY_MOVE) { Vector3 from, dir; GetCursorVectors(&from, &dir, point); Vector3 currPoint; bool result = GetIntersectionVectorWithPlane(from, dir, planeNormal, rotationCenter, currPoint); if (result) { if (arrowsNode) { switch (arrowsNode->GetModAxis()) { case ArrowsNode::AXIS_X: currPoint.y = startDragPoint.y; currPoint.z = startDragPoint.z; break; case ArrowsNode::AXIS_Y: currPoint.x = startDragPoint.x; currPoint.z = startDragPoint.z; break; case ArrowsNode::AXIS_Z: currPoint.x = startDragPoint.x; currPoint.y = startDragPoint.y; break; default: break; } modification.CreateTranslation(currPoint - startDragPoint); } } } else if (GetModificationMode() == ResourceEditor::MODIFY_ROTATE) { Matrix4 d; switch (arrowsNode->GetModAxis()) { case ArrowsNode::AXIS_X: case ArrowsNode::AXIS_Y: modification.CreateRotation(vect[arrowsNode->GetModAxis()], winy / 100.0f); break; case ArrowsNode::AXIS_Z: modification.CreateRotation(vect[arrowsNode->GetModAxis()], winx / 100.0f); break; case ArrowsNode::AXIS_XY: modification.CreateRotation(vect[ArrowsNode::AXIS_X], winx / 100.0f); d.CreateRotation(vect[ArrowsNode::AXIS_Y], winy / 100.0f); modification *= d; break; case ArrowsNode::AXIS_YZ: modification.CreateRotation(vect[ArrowsNode::AXIS_Y], winx / 100.0f); d.CreateRotation(vect[ArrowsNode::AXIS_Z], winy / 100.0f); modification *= d; break; case ArrowsNode::AXIS_XZ: modification.CreateRotation(vect[ArrowsNode::AXIS_X], winx / 100.0f); d.CreateRotation(vect[ArrowsNode::AXIS_Z], winy / 100.0f); modification *= d; break; default: break; } modification = (translate1 * modification) * translate2; } else if (GetModificationMode() == ResourceEditor::MODIFY_SCALE) { float kf = winx / 100.0f; if (kf < -1.0) kf = - kf - 2.0; modification.CreateScale(Vector3(1,1,1) + Vector3(1,1,1) * kf); modification = (translate1 * modification) * translate2; } currTransform = startTransform * modification; }