//! Base implementation of a sphere for the sju physics engine /*! * A physical sphere is actually a particle with a volume. It * will respond accordingly to nearly all the effects and objects included in * the physics engine and can be used to simulate more complicated objects * cheaply. */ /* Copyright (C) 2009-10 Alejandro Valenzuela Roca, * * This file is part of MotorJ, a free framework for videogame creation. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #include "psphere-class.h" pSphere::pSphere() { float * ptrToData; cGeometry = CG_SPHERE; cGeometryData = new float; ptrToData = (float*)cGeometryData; (*ptrToData) = 0.0; rotDragFactor = 0; objectInteractionEffect = PE_CONTACT; } void pSphere::SetRadius(float r) { float * ptrToData = (float*) cGeometryData; *ptrToData = r; } void pSphere::ApplyEffect(vector3 effect, vector3 &pointOfAction, sjuPETypes effectType, IPhysicalObject* interactionObject) { //printf("Got effect %d:%f,%f,%f\n", effectType, effect.x, effect.y, effect.z); if (effectType == PE_C_IMMOVABLE) { // Collision reaction needs to be delayed until the speed // has been recalculated collisionDetected = true; vec_copy(effect, &f_1); normalize(&f_1); } else if (effectType == PE_ACCEL) { // Acceleration response vec_sum2(effect, &a); } else if (effectType == PE_FRFIELD) { v.x *= 1-effect.x; v.y *= 1-effect.y; v.z *= 1-effect.z; } else if (effectType == PE_ROTACCEL) { vec_sum2(effect, &rota); } else if (effectType == PE_TORQUE) { vec_sum(invMInertia, effect, &rota); } else if (effectType == PE_CONTACT) { //float radius = *(float*) cGeometryData; //float vSize = vec_norm(v); vec_copy(effect, &v); // Correct the sphere's position. In this case PointOfAction refers to the // "corrected" center of the sphere vec_copy(pointOfAction, &p); } else { //printf("%3.3f: %3.3f, %3.3f, %3.3f\n", invmass, effect.x, effect.y, effect.z); vec_sum(invmass, effect, &a); } }