Permalink
Browse files

Added rotation capability in main.cpp . Runs but not fully debugged.

Rotation of cloud with ctrl-key. Moving cloud with shift-key.
Right now, cloud rotation does not stop when I release shift-key. I might
have to deal with deltas instead of absolutes.
  • Loading branch information...
1 parent 2357988 commit a82392f84441ffaf62ddb33aaa7f1cb84954b369 @erlebach erlebach committed Jun 27, 2011
View
@@ -60,7 +60,7 @@ set (rtpslib_INCLUDES
${rtpslib_SOURCE_DIR}/system/outer
${rtpslib_SOURCE_DIR}/system/common
${rtpslib_SOURCE_DIR}/render
- ${rtpslib_SOURCE_DIR}/rotations
+ #${rtpslib_SOURCE_DIR}/rotations
${rtpslib_SOURCE_DIR}/render/util
${rtpslib_SOURCE_DIR}/domain
${rtpslib_SOURCE_DIR}/opencl
@@ -80,7 +80,7 @@ set (rtpslib_SOURCES
${rtpslib_SOURCE_DIR}/rtps_common
${rtpslib_SOURCE_DIR}/render/Render
- ${rtpslib_SOURCE_DIR}/render/rotations
+ #${rtpslib_SOURCE_DIR}/render/rotations
${rtpslib_SOURCE_DIR}/render/SpriteRender
${rtpslib_SOURCE_DIR}/render/SSFRender
${rtpslib_SOURCE_DIR}/render/util/stb_image.c
View
@@ -137,5 +137,13 @@ printf("created system in RTPS\n");
{
return cloud_translate;
}
+ void RTPS::setRotationAxis(float4& rotation_axis)
+ {
+ this->rotation_axis = rotation_axis;
+ }
+ float4& RTPS::getRotationAxis()
+ {
+ return rotation_axis;
+ }
};
View
@@ -73,12 +73,15 @@ namespace rtps
void setCloudMovement(bool mvt);
bool getCloudMovement();
void setCloudTranslate(float cx, float cy, float cz);
+ void setRotationAxis(float4& rotation_axis);
+ float4& getRotationAxis();
float4& getCloudTranslate();
private:
bool cl_managed;
bool cloud_movement; // move or stop cloud 'S'
float4 cloud_translate;
+ float4 rotation_axis;
};
}
@@ -1,114 +0,0 @@
-
-#include "rotations.h"
-
-//----------------------------------------------------------------------
-Rotate::Rotate()
-{}
-//----------------------------------------------------------------------
-//Vectorize()
-// Create a 3D position vector on a unit sphere based on
-// mouse hitPt, sphere's screen origin, and sphere radius in
-// pixels. Return zero on success or non-zero if hit point
-// was outside the sphere. This routine uses Quickdraw[TM] 3D
-// and assumes that the relevant QD3D headers and library
-// files have been included. Also need to #include <math.h>.
-
-#define BOUNDS_ERR 1L
-
-long Rotate::Vectorize(
- Point *hit,
- Point *origin,
- float radius,
- TQ3Vector3D *vec )
-{
- float x,y,z, modulus;
-
- x = (float)(hit->h - origin->h)/radius;
- y = (float)(hit->v - origin->v)/radius;
-
- y *= -1.0; // compensate for "inverted" screen y-axis!
-
- modulus = x*x + y*y;
-
- if (modulus > 1.) // outside radius!
- return BOUNDS_ERR;
-
- z = sqrt(1. - (x*x + y*y) ); // compute fictitious 'z' value
-
- Q3Vector3D_Set( vec, x,y,z ); // compute pseudo-3D mouse position
-
- return 0L;
-}
-//----------------------------------------------------------------------
-Rotate::ZeroHysteresisRotation()
-// From two 3D vectors representing the positions of
-// points on a unit sphere, calculate an axis of rotation
-// and an amount of rotation such that Point A can be
-// moved along a geodesic to Point B.
-// CAUTION: Error-checking omitted for clarity.
-
-void ZeroHysteresisRotation( TQ3Vector3D v1, TQ3Vector3D v2 )
-{
- TQ3Vector3D cross;
- TQ3Matrix4x4 theMatrix;
- TQ3Point3D orig = { 0.,0.,0. };
- float dot,angle;
-
- dot = Q3Vector3D_Dot( &v1, &v2 );
-
- if (dot == 1.0)
- return; // nothing to do
-
- Q3Vector3D_Cross( &v1, &v2, &cross ); // axis of rotation
- Q3Vector3D_Normalize( &cross,&cross );
-
- angle = 2.*acos( dot ); // angle of rotation
-
- // set up a rotation around our chosen axis...
- Q3Matrix4x4_SetRotateAboutAxis(&theMatrix,
- &orig, &cross, angle);
-
- Q3Matrix4x4_Multiply( &gDocument.fRotation,
- &theMatrix,
- &gDocument.fRotation); // multiply
-
- DocumentDraw( &gDocument ) ; // draw
-}
-//----------------------------------------------------------------------
-//Rotate::FreeRotateWithMouse()
-// Call this function from the main event loop to
-// do free-rotations of 3D objects
-
-// the mouse action radius in pixels:
-#define RADIUS_VALUE 300.0
-
-void Rotate::FreeRotateWithMouse(void)
-{
- Point now, oldPt, center;
- WindowPtr win = FrontWindow();
- float radius = RADIUS_VALUE;
- TQ3Vector3D v1,v2;
- long err;
-
- GetMouse( &oldPt );
-
- center.h = (win->portRect.right - win->portRect.left)/2;
-
- center.v = (win->portRect.bottom - win->portRect.top)/2;
-
- while (StillDown())
- {
- GetMouse( &now );
-
- err = Vectorize(&oldPt, &center, RADIUS_VALUE, &v1 );
- err += Vectorize(&now, &center, RADIUS_VALUE, &v2 );
-
- if (!err)
- ZeroHysteresisRotation( v1,v2 );
-
- oldPt = now;
- }
-}
-//----------------------------------------------------------------------
-//----------------------------------------------------------------------
-//----------------------------------------------------------------------
View
@@ -1,17 +0,0 @@
-#ifndef _ROTATE_GE_H_
-#define _ROTATE_GE_H_
-
-// Derived from: (no use of quaternions)
-// http://www.mactech.com/articles/mactech/Vol.15/15.03/NaturalObjectRotation/index.html
-
-//----------------------------------------------------------------------
-class Rotate
-{
- Rotate();
- void Vectorize();
- void ZeroHysteresisRotation();
- void FreeRotateWithMouse();
-};
-//----------------------------------------------------------------------
-
-#endif
View
@@ -61,8 +61,8 @@ namespace rtps
addCloud();
float scale = 30.;
- float cloud_omega_mag = 0.; // velocity
- cloud_omega = float4(1.,1.,10.,cloud_omega_mag);
+ float cloud_omega_mag = 0.2; // velocity
+ cloud_omega = float4(0.,1.,10.,cloud_omega_mag);
float nn = cloud_omega.x*cloud_omega.x +
cloud_omega.y*cloud_omega.y +
cloud_omega.z*cloud_omega.z;
@@ -120,14 +120,19 @@ namespace rtps
//----------------------------------------------------------------------
void CLOUD::cloudVelocityExecute()
{
- printf("**** BEFORE velocity execute *****\n");
//u.printDevArray(cl_position_s, "pos_s", 10, 10);
//u.printDevArray(cl_velocity_s, "vel_s", 10, 10);
cloud_cg_prev = cloud_cg;
cloud_cg = cloud_cg0 + ps->getCloudTranslate();
+
+ float4 cloud_omega = ps->getRotationAxis();
ps->getCloudTranslate().print("translate");
+ cloud_omega.w = 10.; // Angular rotation
+
+ printf("**** BEFORE vel exec, ");
cloud_cg.print("cloud_cg");
+ cloud_omega.print("*** BEFORE vel exec, rotation axis ***");
velocity.execute(
cloud_num,
@@ -208,6 +213,7 @@ namespace rtps
cl_normal_s,
cl_velocity_u,
cl_velocity_s,
+ cloud_cg,
cg_diff, // must make more efficient
cl_sort_indices,
*cl_sphp,
View
@@ -973,11 +973,14 @@ namespace rtps
cloud->cloudVelocityExecute(); // before collision?
}
- cloud->cloudVelocityExecute(); // before collision?
+ //cloud->cloudVelocityExecute(); // before collision?
+ printf("REMOVE COLLISIONS GE\n");
cloud->collision(cl_position_s, cl_velocity_s, cl_force_s, cl_sphp, num);
;
- cloud->integrate();
+ if (ps->getCloudMovement()) {
+ cloud->integrate();
+ }
}
//----------------------------------------------------------------------
void SPH::cloudCleanup()
@@ -21,6 +21,7 @@ namespace rtps
Buffer<float4>& velocity_u,
Buffer<float4>& velocity_s,
float4& pos_cg,
+ float4& diff_pos_cg,
//float4 vel,
Buffer<unsigned int>& indices,
//params
@@ -38,11 +39,14 @@ namespace rtps
k_cloud_euler.setArg(iargs++, velocity_u.getDevicePtr());
k_cloud_euler.setArg(iargs++, velocity_s.getDevicePtr());
k_cloud_euler.setArg(iargs++, pos_cg);
+ k_cloud_euler.setArg(iargs++, diff_pos_cg);
//k_cloud_euler.setArg(iargs++, vel);
k_cloud_euler.setArg(iargs++, indices.getDevicePtr());
k_cloud_euler.setArg(iargs++, sphp.getDevicePtr());
k_cloud_euler.setArg(iargs++, dt); //time step
+ pos_cg.print("*** pos_cg ***");
+
//printf("BEFORE k_cloud_euler.execute\n");
@@ -13,23 +13,22 @@ namespace rtps
CloudEuler() { cli = NULL; timer = NULL; };
CloudEuler(std::string path, CL* cli, EB::Timer* timer);
void execute(int num,
- float dt,
- Buffer<float4>& pos_u,
- Buffer<float4>& pos_s,
- Buffer<float4>& normal_u,
- Buffer<float4>& normal_s,
- Buffer<float4>& velocity_u,
- Buffer<float4>& velocity_s,
- float4& pos_cg,
- //float4 vel,
- Buffer<unsigned int>& indices,
- //params
- Buffer<SPHParams>& sphp,
- //debug
- Buffer<float4>& clf_debug,
- Buffer<int4>& cli_debug);
-
-
+ float dt,
+ Buffer<float4>& pos_u,
+ Buffer<float4>& pos_s,
+ Buffer<float4>& normal_u,
+ Buffer<float4>& normal_s,
+ Buffer<float4>& velocity_u,
+ Buffer<float4>& velocity_s,
+ float4& pos_cg,
+ float4& diff_pos_cg,
+ //float4 vel,
+ Buffer<unsigned int>& indices,
+ //params
+ Buffer<SPHParams>& sphp,
+ //debug
+ Buffer<float4>& clf_debug,
+ Buffer<int4>& cli_debug);
private:
CL* cli;
@@ -16,6 +16,7 @@ __kernel void cloudEuler(
__global float4* velocity_s,
// pos_cg: difference from previous time step
float4 pos_cg, // just the tnraslation from pos_cg0
+ float4 diff_pos_cg, // just the tnraslation from pos_cg0
__global int* sort_indices,
__constant struct SPHParams* sphp,
float dt)
@@ -29,7 +30,7 @@ __kernel void cloudEuler(
float4 p = pos_s[i] * ss;
float4 vel = velocity_s[i];
- p += dt*vel + pos_cg*ss;
+ p += dt*vel + diff_pos_cg*ss;
//p = pos_cg*sphp->simulation_scale + dt*vel;
//p = dt*vel;
@@ -13,7 +13,7 @@ __kernel void kern_cloud_velocity(
if (i >= num) return;
// SHOULD NOT BE HARDCODED!! :-)
- float4 simulation_scale = 0.05; // pass sphp as argument
+ float simulation_scale = 0.05; // pass sphp as argument
float4 p = simulation_scale*(pos_s[i] - pos_cg);
vel_s[i] = (float4)(p.y*omega.z-p.z*omega.y, p.z*omega.x-p.x*omega.z,
Oops, something went wrong.

0 comments on commit a82392f

Please sign in to comment.