HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_SParticle.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * This is a simple particle system... Not too much to it, but this can be
27  * used as a template for your own...
28  */
29 
30 
31 #ifndef __SOP_SParticle_h__
32 #define __SOP_SParticle_h__
33 
34 #include <SOP/SOP_Node.h>
35 
36 #define INT_PARM(name, idx, vidx, t) \
37  return evalInt(name, &myOffsets[idx], vidx, t);
38 
39 #define FLT_PARM(name, idx, vidx, t) \
40  return evalFloat(name, &myOffsets[idx], vidx, t);
41 
42 class GEO_ParticleVertex;
43 class GEO_PrimParticle;
44 class GU_RayIntersect;
45 
46 namespace HDK_Sample {
47 class SOP_SParticle : public SOP_Node
48 {
49 public:
50  SOP_SParticle(OP_Network *net, const char *name, OP_Operator *op);
51  virtual ~SOP_SParticle();
52 
54  static OP_Node *myConstructor(OP_Network*, const char *,
55  OP_Operator *);
56 
57 protected:
58  virtual const char *inputLabel(unsigned idx) const;
59 
60  void birthParticle();
61  int moveParticle(GA_Offset ptoff,
62  const UT_Vector3 &force);
63 
64  void initSystem();
65  void timeStep(fpreal now);
66 
67  // Method to cook geometry for the SOP
68  virtual OP_ERROR cookMySop(OP_Context &context);
69 
70 private:
71  // These use defines to make it easy to add parms and remove them.
72  // The evaluation routines use the indexed name lookup which is quite
73  // fast, yet easy to change indices (since the order of the indices
74  // doesn't have to be in sequential order...
75  int RESET() { INT_PARM("reset", 0, 0, 0) }
76  int BIRTH(fpreal t){ INT_PARM("birth", 2, 0, t) }
77  fpreal FX(fpreal t) { FLT_PARM("force", 1, 0, t) }
78  fpreal FY(fpreal t) { FLT_PARM("force", 1, 1, t) }
79  fpreal FZ(fpreal t) { FLT_PARM("force", 1, 2, t) }
80 
81  const GU_Detail *mySource;
82  GA_Index mySourceNum; // Source point to birth from
83  GA_ROHandleV3 mySourceVel; // Velocity attrib in source
84 
85  GU_RayIntersect *myCollision;
86 
87  GEO_PrimParticle *mySystem;
88  fpreal myLastCookTime; // Last cooked time
89  GA_RWHandleV3 myVelocity; // My velocity attribute
90  GA_RWHandleF myLife; // My life attribute
91 
92  static int *myOffsets;
93 };
94 } // End HDK_Sample namespace
95 
96 #endif
virtual OP_ERROR cookMySop(OP_Context &context)
static PRM_Template myTemplateList[]
Definition: SOP_SParticle.h:53
UT_ErrorSeverity
Definition: UT_Error.h:25
SOP_SParticle(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_SParticle.C:89
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual const char * inputLabel(unsigned idx) const
GLuint const GLchar * name
Definition: glcorearb.h:785
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
#define INT_PARM(name, idx, vidx, t)
Definition: SOP_SParticle.h:36
double fpreal
Definition: SYS_Types.h:263
int moveParticle(GA_Offset ptoff, const UT_Vector3 &force)
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_SParticle.C:84
#define FLT_PARM(name, idx, vidx, t)
Definition: SOP_SParticle.h:39
void timeStep(fpreal now)