MCPcopy Create free account
hub / github.com/axmolengine/axmol / OnUpdate

Method OnUpdate

tests/live2d-tests/Source/LAppLive2DManager.cpp:196–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196void LAppLive2DManager::OnUpdate(Csm::Rendering::CubismCommandBuffer_Cocos2dx* commandBuffer) const
197{
198 Director* director = Director::getInstance();
199 Size window = director->getWinSize();
200
201 Csm::Rendering::CubismRenderer_Cocos2dx::StartFrame(commandBuffer);
202
203 for (csmUint32 i = 0; i < _models.GetSize(); ++i)
204 {
205 CubismMatrix44 projection;
206 LAppModel* model = GetModel(i);
207 if (model->GetModel()->GetCanvasWidth() > 1.0f && window.width < window.height)
208 {
209 // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する
210 model->GetModelMatrix()->SetWidth(2.0f);
211 projection.Scale(1.0f, static_cast<float>(window.width) / static_cast<float>(window.height));
212 }
213 else
214 {
215 projection.Scale(static_cast<float>(window.height) / static_cast<float>(window.width), 1.0f);
216 }
217
218 // 必要があればここで乗算
219 if (_viewMatrix != NULL)
220 {
221 projection.MultiplyByMatrix(_viewMatrix);
222 }
223
224 if (_renderTarget == SelectTarget_ViewFrameBuffer && _renderBuffer && _sprite)
225 {// レンダリングターゲット使いまわしの場合
226 // レンダリング開始
227 _renderBuffer->BeginDraw(commandBuffer, NULL);
228 _renderBuffer->Clear(commandBuffer, _clearColor[0], _clearColor[1], _clearColor[2], _clearColor[3]); // 背景クリアカラー
229
230 model->Update();
231 model->Draw(commandBuffer, projection);///< 参照渡しなのでprojectionは変質する
232
233 _renderBuffer->EndDraw(commandBuffer);
234
235 float uvVertex[] =
236 {
237 1.0f, 1.0f,
238 0.0f, 1.0f,
239 0.0f, 0.0f,
240 1.0f, 0.0f,
241 };
242
243 // program退避
244 Csm::Rendering::CubismCommandBuffer_Cocos2dx* lastCommandBuffer = commandBuffer;
245
246 _sprite->SetColor(1.0f, 1.0f, 1.0f, 0.25f + (float)i * 0.5f);
247 _sprite->RenderImmidiate(commandBuffer, _renderBuffer->GetColorBuffer()->getBackendTexture(), uvVertex);
248
249 // 元に戻す
250 commandBuffer = lastCommandBuffer;
251 }
252 else {
253 model->Update();

Callers 1

onDrawMethod · 0.80

Calls 15

getInstanceFunction · 0.85
GetCanvasWidthMethod · 0.80
SetWidthMethod · 0.80
GetModelMatrixMethod · 0.80
MultiplyByMatrixMethod · 0.80
BeginDrawMethod · 0.80
EndDrawMethod · 0.80
RenderImmidiateMethod · 0.80
getBackendTextureMethod · 0.80
GetSizeMethod · 0.45
GetModelMethod · 0.45
ScaleMethod · 0.45

Tested by

no test coverage detected