MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / update_main

Method update_main

src/DrawCamera.cpp:82–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82void DrawCamera::update_main(World& w) {
83 if(smoothMove.occurring) {
84 BezierEasing zoomAnim{w.main.conf.jumpTransitionEasing};
85 float smoothTime = smooth_two_way_animation_time_get_lerp(smoothMove.moveTime, w.main.deltaTime, true, w.main.conf.jumpTransitionTime);
86 float lerpTime;
87 float rotationLerpTime = zoomAnim(smoothTime);
88 lerpTime = zoomAnim(smoothTime);
89
90 WorldVec mVec = smoothMove.startCenter - smoothMove.endCenter;
91 WorldScalar startLog2 = FixedPoint::log2(smoothMove.start.inverseScale);
92 WorldScalar endLog2 = FixedPoint::log2(smoothMove.endUniformZoom);
93 WorldVec windowCenter = smoothMove.endCenter;
94 if(FixedPoint::abs(startLog2 - endLog2) < WorldScalar(3)) {
95 c.inverseScale = FixedPoint::lerp_double(smoothMove.start.inverseScale, smoothMove.endUniformZoom, lerpTime);
96 if(lerpTime != 1.0)
97 windowCenter += WorldVec{mVec.x() / WorldScalar(1.0 / (1.0 - lerpTime)), mVec.y() / WorldScalar(1.0 / (1.0 - lerpTime))};
98 c.pos = windowCenter - (w.main.window.size.cast<float>() * 0.5f).cast<WorldScalar>() * c.inverseScale;
99 }
100 else {
101 c.inverseScale = FixedPoint::exp2(FixedPoint::lerp_double(startLog2, endLog2, lerpTime));
102 if(smoothMove.start.inverseScale < smoothMove.endUniformZoom) {
103 if(smoothMove.start.inverseScale > c.inverseScale)
104 c.inverseScale = smoothMove.start.inverseScale;
105 else if(smoothMove.endUniformZoom < c.inverseScale)
106 c.inverseScale = smoothMove.endUniformZoom;
107 }
108 else {
109 if(smoothMove.start.inverseScale < c.inverseScale)
110 c.inverseScale = smoothMove.start.inverseScale;
111 else if(smoothMove.endUniformZoom > c.inverseScale)
112 c.inverseScale = smoothMove.endUniformZoom;
113 }
114 WorldScalar denominator = (smoothMove.endUniformZoom - smoothMove.start.inverseScale);
115 windowCenter += WorldVec{mVec.x() - ((mVec.x() * c.inverseScale) / denominator) + ((mVec.x() * smoothMove.start.inverseScale) / denominator),
116 mVec.y() - ((mVec.y() * c.inverseScale) / denominator) + ((mVec.y() * smoothMove.start.inverseScale) / denominator)};
117 c.pos = windowCenter - (w.main.window.size.cast<float>() * 0.5f).cast<WorldScalar>() * c.inverseScale;
118 }
119
120 c.set_rotation(0.0);
121 double midRotate = Rotation2D(smoothMove.start.rotation).slerp(rotationLerpTime, Rotation2D(smoothMove.end.rotation)).smallestPositiveAngle();
122 c.rotate_about(windowCenter, midRotate);
123
124 if(smoothTime >= 1.0f) {
125 c.inverseScale = smoothMove.endUniformZoom;
126 c.pos = smoothMove.endCenter - (w.main.window.size.cast<float>() * 0.5f).cast<WorldScalar>() * c.inverseScale;
127 c.set_rotation(0.0);
128 c.rotate_about(smoothMove.endCenter, smoothMove.end.rotation);
129 smoothMove.occurring = false;
130 }
131
132 checks_after_input(w);
133 }
134 else {
135 if(w.main.input.key(InputManager::KEY_CAMERA_ROTATE_COUNTERCLOCKWISE).held && !w.main.input.text_is_accepting_input()) {
136 c.rotate_about(c.from_space(w.main.window.size.cast<float>() * 0.5f), -w.main.deltaTime);
137 InputManager::MouseMotionCallbackArgs motion{
138 .pos = w.main.input.mouse.pos,
139 .move = {0, 0}

Callers 1

focus_updateMethod · 0.80

Calls 15

lerp_doubleFunction · 0.85
smallestPositiveAngleMethod · 0.80
set_to_layoutMethod · 0.80
log2Function · 0.50
absFunction · 0.50
exp2Function · 0.50
Rotation2DClass · 0.50
xMethod · 0.45
yMethod · 0.45
set_rotationMethod · 0.45

Tested by

no test coverage detected