ShapeData ShapeGenerator::makeTriangle() { ShapeData tri; Vertex genTri[] = { Vertex(QVector3D(+0.0f, +0.9f, +0.0f),//idx 0 QVector3D(+1.0f, +0.0f, +0.0f)), Vertex(QVector3D(+0.9f, -0.9f, +0.0f),//idx 1 QVector3D(+0.0f, +1.0f, +0.0f)), Vertex(QVector3D(-0.9f, -0.9f, +0.0f),//idx 2 QVector3D(+0.0f, +0.0f, +1.0f)), }; tri.numVertices = NUM_ARRAY_ELEMENTS(genTri); tri.vertices = new Vertex[tri.numVertices]; memcpy(tri.vertices,genTri,sizeof(genTri)); GLushort genIndices[] = {0,1,2}; tri.numIndices = NUM_ARRAY_ELEMENTS(genIndices); tri.indices = new GLushort[tri.numIndices]; memcpy(tri.indices,genIndices,sizeof(genIndices)); return tri; }
//Create the spring mass vertex and color data ShapeData ObjectGenerator::makeSpringMass(glm::vec3 anchorPosition, GLfloat springWidth, GLfloat stretch, GLfloat width, GLfloat height) { ShapeData ret; glm::vec3 springColor{ 1.0f, 0.0f, 0.0f }, massColor{ 0.0f, 1.0f, 0.0f }, connectionPoint{ anchorPosition.x, anchorPosition.y - (17 * stretch), 0.0f }; Vertex vertices[] = { glm::vec3(anchorPosition.x, anchorPosition.y, 0.0f), // 0 springColor, glm::vec3(anchorPosition.x, anchorPosition.y - (0.1 *stretch),0.0f), // 1 springColor, glm::vec3(anchorPosition.x + springWidth, anchorPosition.y - (1 * stretch), 0.0f), // 2 springColor, glm::vec3(anchorPosition.x - springWidth, anchorPosition.y - (3 * stretch), 0.0f), // 3 springColor, glm::vec3(anchorPosition.x + springWidth, anchorPosition.y - (5 * stretch), 0.0f), // 4 springColor, glm::vec3(anchorPosition.x - springWidth, anchorPosition.y - (7 * stretch), 0.0f), // 5 springColor, glm::vec3(anchorPosition.x + springWidth, anchorPosition.y - (9 * stretch), 0.0f), // 6 springColor, glm::vec3(anchorPosition.x - springWidth, anchorPosition.y - (11 * stretch), 0.0f), // 7 springColor, glm::vec3(anchorPosition.x + springWidth, anchorPosition.y - (13 * stretch), 0.0f), // 8 springColor, glm::vec3(anchorPosition.x - springWidth, anchorPosition.y - (15 * stretch), 0.0f), // 9 springColor, glm::vec3(anchorPosition.x, anchorPosition.y - (16 * stretch), 0.0f), // 10 springColor, connectionPoint, // 11 ===> The joint between the spring and the mass springColor, //=================Mass==============// glm::vec3(connectionPoint.x - width, connectionPoint.y, 0.0f), //top Left 12 massColor, glm::vec3(connectionPoint.x + width, connectionPoint.y, 0.0f), //top Right 13 massColor, glm::vec3(connectionPoint.x + width, connectionPoint.y - height, 0.0f), // bottom right 14 massColor, glm::vec3(connectionPoint.x - width, connectionPoint.y - height, 0.0f), // bottom left 15 massColor, }; ret.numVertices = NUM_ARRAY_ELEMENTS(vertices); ret.vertices = new Vertex[ret.numVertices]; //Used to ensure the data we have just created on the stack is moved into location that won't be overwritten //As opposed to a reference to a stack array which can be damaged memcpy(ret.vertices, vertices, sizeof(vertices)); //memcpy(dest, source, size); GLushort indices[] = { 0,1 ,1,2, 2,3, 3,4, 4,5, 5,6, 6,7, 7,8, 8,9, 9,10, 10,11, 11,12, 12,13, 13,14, 14,15, 15,12 }; ret.numIndices = NUM_ARRAY_ELEMENTS(indices); ret.indices = new GLushort[ret.numIndices]; //Used to ensure the data we have just created on the stack is moved into location that won't be overwritten //As opposed to a reference to a stack array which can be damaged memcpy(ret.indices, indices, sizeof(indices)); return ret; }
int register_convert_pipeline(JNIEnv *env) { LOGV("register_convert_pipeline:"); if (registerNativeMethods(env, "com/serenegiant/usb/ConvertPipeline", methods, NUM_ARRAY_ELEMENTS(methods)) < 0) { return -1; } return 0; }
int register_uvccamera(JNIEnv *env) { LOGV("register_uvccamera:"); if (registerNativeMethods(env, "com/serenegiant/usb/UVCCamera", methods, NUM_ARRAY_ELEMENTS(methods)) < 0) { return -1; } return 0; }
ShapeData ShapeGenerator::makeQuadTex() { ShapeData quad; Vertex genQuad[] = { Vertex(QVector3D(-1.0f, +1.0f, -0.0f),//idx 0 QVector3D(+0.0f, +1.0f, +0.0f)), Vertex(QVector3D(+1.0f, +1.0f, -0.0f),//idx 1 QVector3D(+1.0f, +1.0f, +0.0f)), Vertex(QVector3D(+1.0f, -1.0f, -0.0f),//idx 2 QVector3D(+1.0f, +0.0f, +0.0f)), Vertex(QVector3D(+1.0f, -1.0f, -0.0f),//idx 3 QVector3D(+1.0f, +0.0f, +0.0f)), Vertex(QVector3D(-1.0f, -1.0f, -0.0f),//idx 4 QVector3D(+0.0f, +0.0f, +0.0f)), Vertex(QVector3D(-1.0f, +1.0f, -0.0f),//idx 5 QVector3D(+0.0f, +1.0f, +0.0f)), }; quad.numVertices = NUM_ARRAY_ELEMENTS(genQuad); quad.vertices = new Vertex[quad.numVertices]; memcpy(quad.vertices,genQuad,sizeof(genQuad)); GLushort genIndices[] = {0,1,2, 3,4,5}; quad.numIndices = NUM_ARRAY_ELEMENTS(genIndices); quad.indices = new GLushort[quad.numIndices]; memcpy(quad.indices,genIndices,sizeof(genIndices)); return quad; }
ShapeData ObjectGenerator::makeAxis() { ShapeData ret; GLuint axisLength(1.0f); glm::vec3 xAxisColor{ 1.0f, 0.0f, 0.0f }, yAxisColor{ 0.0f, 1.0f, 0.0f }, zAxisColor{ 0.0f, 0.0f, 1.0f }; Vertex vertices[] = { glm::vec3{ 0.0f,+0.01f, 0.0f }, glm::vec3{0.0f, 0.0f, 0.0f}, //X axis glm::vec3{ axisLength, +0.01f, 0.0f }, xAxisColor, //Y Axis glm::vec3{ 0.0f, axisLength, 0.0f }, yAxisColor, //Z Axis glm::vec3{ 0.0f, +0.01f, axisLength }, zAxisColor, }; ret.numVertices = NUM_ARRAY_ELEMENTS(vertices); ret.vertices = new Vertex[ret.numVertices]; //Used to ensure the data we have just created on the stack is moved into location that won't be overwritten //As opposed to a reference to a stack array which can be damaged memcpy(ret.vertices, vertices, sizeof(vertices)); //memcpy(dest, source, size); GLushort indices[] = { 0,1, 0,2, 0,3}; ret.numIndices = NUM_ARRAY_ELEMENTS(indices); ret.indices = new GLushort[ret.numIndices]; //Used to ensure the data we have just created on the stack is moved into location that won't be overwritten //As opposed to a reference to a stack array which can be damaged memcpy(ret.indices, indices, sizeof(indices)); return ret; }
ShapeData ShapeGenerator::makeCube() { ShapeData ret; Vertex stackVerts[] = { Vertex(QVector3D(-1.0f, +1.0f, +1.0f), // 0 QVector3D(+1.0f, +0.0f, +0.0f)), // Color Vertex(QVector3D(+1.0f, +1.0f, +1.0f), // 1 QVector3D(+0.0f, +1.0f, +0.0f)), // Color Vertex(QVector3D(+1.0f, +1.0f, -1.0f), // 2 QVector3D(+0.0f, +0.0f, +1.0f)), // Color Vertex(QVector3D(-1.0f, +1.0f, -1.0f), // 3 QVector3D(+1.0f, +1.0f, +1.0f)), // Color Vertex(QVector3D(-1.0f, +1.0f, -1.0f), // 4 QVector3D(+1.0f, +0.0f, +1.0f)), // Color Vertex(QVector3D(+1.0f, +1.0f, -1.0f), // 5 QVector3D(+0.0f, +0.5f, +0.2f)), // Color Vertex(QVector3D(+1.0f, -1.0f, -1.0f), // 6 QVector3D(+0.8f, +0.6f, +0.4f)), // Color Vertex(QVector3D(-1.0f, -1.0f, -1.0f), // 7 QVector3D(+0.3f, +1.0f, +0.5f)), // Color Vertex(QVector3D(+1.0f, +1.0f, -1.0f), // 8 QVector3D(+0.2f, +0.5f, +0.2f)), // Color Vertex(QVector3D(+1.0f, +1.0f, +1.0f), // 9 QVector3D(+0.9f, +0.3f, +0.7f)), // Color Vertex(QVector3D(+1.0f, -1.0f, +1.0f), // 10 QVector3D(+0.3f, +0.7f, +0.5f)), // Color Vertex(QVector3D(+1.0f, -1.0f, -1.0f), // 11 QVector3D(+0.5f, +0.7f, +0.5f)), // Color Vertex(QVector3D(-1.0f, +1.0f, +1.0f), // 12 QVector3D(+0.7f, +0.8f, +0.2f)), // Color Vertex(QVector3D(-1.0f, +1.0f, -1.0f), // 13 QVector3D(+0.5f, +0.7f, +0.3f)), // Color Vertex(QVector3D(-1.0f, -1.0f, -1.0f), // 14 QVector3D(+0.4f, +0.7f, +0.7f)), // Color Vertex(QVector3D(-1.0f, -1.0f, +1.0f), // 15 QVector3D(+0.2f, +0.5f, +1.0f)), // Color Vertex(QVector3D(+1.0f, +1.0f, +1.0f), // 16 QVector3D(+0.6f, +1.0f, +0.7f)), // Color Vertex(QVector3D(-1.0f, +1.0f, +1.0f), // 17 QVector3D(+0.6f, +0.4f, +0.8f)), // Color Vertex(QVector3D(-1.0f, -1.0f, +1.0f), // 18 QVector3D(+0.2f, +0.8f, +0.7f)), // Color Vertex(QVector3D(+1.0f, -1.0f, +1.0f), // 19 QVector3D(+0.2f, +0.7f, +1.0f)), // Color Vertex(QVector3D(+1.0f, -1.0f, -1.0f), // 20 QVector3D(+0.8f, +0.3f, +0.7f)), // Color Vertex(QVector3D(-1.0f, -1.0f, -1.0f), // 21 QVector3D(+0.8f, +0.9f, +0.5f)), // Color Vertex(QVector3D(-1.0f, -1.0f, +1.0f), // 22 QVector3D(+0.5f, +0.8f, +0.5f)), // Color Vertex(QVector3D(+1.0f, -1.0f, +1.0f), // 23 QVector3D(+0.9f, +1.0f, +0.2f)), // Color }; ret.numVertices = NUM_ARRAY_ELEMENTS(stackVerts); ret.vertices = new Vertex[ret.numVertices]; memcpy(ret.vertices, stackVerts, sizeof(stackVerts)); unsigned short stackIndices[] = { 0, 1, 2, 0, 2, 3, // Top 4, 5, 6, 4, 6, 7, // Front 8, 9, 10, 8, 10, 11, // Right 12, 13, 14, 12, 14, 15, // Left 16, 17, 18, 16, 18, 19, // Back 20, 22, 21, 20, 23, 22, // Bottom }; ret.numIndices = NUM_ARRAY_ELEMENTS(stackIndices); ret.indices = new GLushort[ret.numIndices]; memcpy(ret.indices, stackIndices, sizeof(stackIndices)); return ret; }
int register_Quaternion(JNIEnv *env) { return registerNativeMethods(env, "com/serenegiant/androbulletglue/math/Quaternion", methods, NUM_ARRAY_ELEMENTS(methods)); }
void loop() { // quickly scan through baudrates until we receive a valid packet within timeout period #if 0 // the baud rate change still isn't working for some reason. if (autodetect_baudrates_index != 0xFF) { if (millis() - first_rcvd_time > MAX_FRAME_COMPLETION_DELAY_MS * 1.5) // make sure its not a multiple of 100ms { PSERIAL.end(); PSERIAL.flush(); autodetect_baudrates_index += 1; if (autodetect_baudrates_index >= NUM_ARRAY_ELEMENTS(autodetect_baudrates)) autodetect_baudrates_index = 0; PSERIAL.begin(pgm_read_dword(&autodetect_baudrates[autodetect_baudrates_index])); recv_buf_len = 0; first_rcvd_time = millis(); } } #endif if (get_command()) { autodetect_baudrates_index = 0xFF; last_order_time = millis(); is_host_active = true; order_code = recv_buf[PM_ORDER_BYTE_OFFSET]; control_byte = recv_buf[PM_CONTROL_BYTE_OFFSET]; parameter_length = recv_buf[PM_LENGTH_BYTE_OFFSET]-2; #if TRACE_ORDER DEBUGPGM("\nOrder("); DEBUG_F(order_code, HEX); DEBUGPGM(", plen="); DEBUG_F(parameter_length, DEC); DEBUGPGM(", cb="); DEBUG_F(control_byte, HEX); DEBUGPGM("):"); for (uint8_t i = 0; i < parameter_length; i++) { DEBUG_CH(' '); DEBUG_F(recv_buf[i], HEX); } DEBUG_EOL(); #endif // does this match the sequence number of the last reply if ((control_byte & CONTROL_BYTE_SEQUENCE_NUMBER_MASK) == (reply_control_byte & CONTROL_BYTE_SEQUENCE_NUMBER_MASK) && (control_byte & CONTROL_BYTE_ORDER_HOST_RESET_BIT) == 0 && reply_control_byte != 0xFF) { if (!reply_started) { // resend last response reply_started = true; generate_response_send(); } else { // this is an unexpected error case (matching sequence number but nothing to send) generate_response_transport_error_start(PARAM_FRAME_RECEIPT_ERROR_TYPE_UNABLE_TO_ACCEPT, control_byte); generate_response_msg_addPGM(PMSG(MSG_ERR_NO_RESPONSE_TO_SEND)); generate_response_send(); } } else { reply_sent = false; process_command(); if (!reply_sent) { send_app_error_response(PARAM_APP_ERROR_TYPE_FIRMWARE_ERROR, PMSG(MSG_ERR_NO_RESPONSE_GENERATED)); } } recv_buf_len = 0; } // Idle loop activities // Check if heaters need to be updated? if (temp_meas_ready) { Device_TemperatureSensor::UpdateTemperatureSensors(); Device_Heater::UpdateHeaters(); } // Now check low-priority stuff uint32_t now = millis(); if (now - last_idle_check > 1000) // checked every second { #if !DEBUG_DISABLE_HOST_TIMEOUT // have we heard from the host within the timeout? if (now - last_order_time > (HOST_TIMEOUT_SECS * 1000) && is_host_active) { is_host_active = false; if (!is_stopped) { emergency_stop(PARAM_STOPPED_CAUSE_HOST_TIMEOUT); } } #endif #if TRACE_MOVEMENT print_movement_ISR_state(); #endif last_idle_check = now; } }