MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / UpdateMouse

Function UpdateMouse

demo/main.cpp:1104–1157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1102}
1103
1104void UpdateMouse()
1105{
1106 // mouse button is up release particle
1107 if (g_lastb == -1)
1108 {
1109 if (g_mouseParticle != -1)
1110 {
1111 // restore particle mass
1112 g_buffers->positions[g_mouseParticle].w = g_mouseMass;
1113
1114 // deselect
1115 g_mouseParticle = -1;
1116 }
1117 }
1118
1119 // mouse went down, pick new particle
1120 if (g_mousePicked)
1121 {
1122 assert(g_mouseParticle == -1);
1123
1124 Vec3 origin, dir;
1125 GetViewRay(g_lastx, g_screenHeight - g_lasty, origin, dir);
1126
1127 const int numActive = NvFlexGetActiveCount(g_flex);
1128
1129 g_mouseParticle = PickParticle(origin, dir, &g_buffers->positions[0], &g_buffers->phases[0], numActive, g_params.radius*0.8f, g_mouseT);
1130
1131 if (g_mouseParticle != -1)
1132 {
1133 printf("picked: %d, mass: %f v: %f %f %f\n", g_mouseParticle, g_buffers->positions[g_mouseParticle].w, g_buffers->velocities[g_mouseParticle].x, g_buffers->velocities[g_mouseParticle].y, g_buffers->velocities[g_mouseParticle].z);
1134
1135 g_mousePos = origin + dir*g_mouseT;
1136 g_mouseMass = g_buffers->positions[g_mouseParticle].w;
1137 g_buffers->positions[g_mouseParticle].w = 0.0f; // increase picked particle's mass to force it towards the point
1138 }
1139
1140 g_mousePicked = false;
1141 }
1142
1143 // update picked particle position
1144 if (g_mouseParticle != -1)
1145 {
1146 Vec3 p = Lerp(Vec3(g_buffers->positions[g_mouseParticle]), g_mousePos, 0.8f);
1147 Vec3 delta = p - Vec3(g_buffers->positions[g_mouseParticle]);
1148
1149 g_buffers->positions[g_mouseParticle].x = p.x;
1150 g_buffers->positions[g_mouseParticle].y = p.y;
1151 g_buffers->positions[g_mouseParticle].z = p.z;
1152
1153 g_buffers->velocities[g_mouseParticle].x = delta.x / g_dt;
1154 g_buffers->velocities[g_mouseParticle].y = delta.y / g_dt;
1155 g_buffers->velocities[g_mouseParticle].z = delta.z / g_dt;
1156 }
1157}
1158
1159void UpdateWind()
1160{

Callers 1

UpdateFrameFunction · 0.85

Calls 3

PickParticleFunction · 0.85
GetViewRayFunction · 0.50
LerpFunction · 0.50

Tested by

no test coverage detected