Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): 2007 - Joshua Leung (major recode) 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00028 #ifndef BKE_CONSTRAINT_H 00029 #define BKE_CONSTRAINT_H 00030 00036 struct ID; 00037 struct bConstraint; 00038 struct bConstraintTarget; 00039 struct ListBase; 00040 struct Object; 00041 struct Scene; 00042 struct bPoseChannel; 00043 00044 /* ---------------------------------------------------------------------------- */ 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 /* special struct for use in constraint evaluation */ 00050 typedef struct bConstraintOb { 00051 struct Scene *scene; /* for system time, part of deglobalization, code nicer later with local time (ton) */ 00052 struct Object *ob; /* if pchan, then armature that it comes from, otherwise constraint owner */ 00053 struct bPoseChannel *pchan; /* pose channel that owns the constraints being evaluated */ 00054 00055 float matrix[4][4]; /* matrix where constraints are accumulated + solved */ 00056 float startmat[4][4]; /* original matrix (before constraint solving) */ 00057 00058 short type; /* type of owner */ 00059 short rotOrder; /* rotation order for constraint owner (as defined in eEulerRotationOrders in BLI_math.h) */ 00060 } bConstraintOb; 00061 00062 /* ---------------------------------------------------------------------------- */ 00063 00064 /* Callback format for performing operations on ID-pointers for Constraints */ 00065 typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, void *userdata); 00066 00067 /* ....... */ 00068 00069 /* Constraint Type-Info (shorthand in code = cti): 00070 * This struct provides function pointers for runtime, so that functions can be 00071 * written more generally (with fewer/no special exceptions for various constraints). 00072 * 00073 * Callers of these functions must check that they actually point to something useful, 00074 * as some constraints don't define some of these. 00075 * 00076 * Warning: it is not too advisable to reorder order of members of this struct, 00077 * as you'll have to edit quite a few ($NUM_CONSTRAINT_TYPES) of these 00078 * structs. 00079 */ 00080 typedef struct bConstraintTypeInfo { 00081 /* admin/ident */ 00082 short type; /* CONSTRAINT_TYPE_### */ 00083 short size; /* size in bytes of the struct */ 00084 char name[32]; /* name of constraint in interface */ 00085 char structName[32]; /* name of struct for SDNA */ 00086 00087 /* data management function pointers - special handling */ 00088 /* free any data that is allocated separately (optional) */ 00089 void (*free_data)(struct bConstraint *con); 00090 /* adjust pointer to other ID-data using ID_NEW(), but not to targets (optional) */ 00091 void (*relink_data)(struct bConstraint *con); 00092 /* run the provided callback function on all the ID-blocks linked to the constraint */ 00093 void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata); 00094 /* copy any special data that is allocated separately (optional) */ 00095 void (*copy_data)(struct bConstraint *con, struct bConstraint *src); 00096 /* set settings for data that will be used for bConstraint.data (memory already allocated using MEM_callocN) */ 00097 void (*new_data)(void *cdata); 00098 00099 /* target handling function pointers */ 00100 /* for multi-target constraints: return that list; otherwise make a temporary list (returns number of targets) */ 00101 int (*get_constraint_targets)(struct bConstraint *con, struct ListBase *list); 00102 /* for single-target constraints only: flush data back to source data, and the free memory used */ 00103 void (*flush_constraint_targets)(struct bConstraint *con, struct ListBase *list, short nocopy); 00104 00105 /* evaluation */ 00106 /* set the ct->matrix for the given constraint target (at the given ctime) */ 00107 void (*get_target_matrix)(struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime); 00108 /* evaluate the constraint for the given time */ 00109 void (*evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets); 00110 } bConstraintTypeInfo; 00111 00112 /* Function Prototypes for bConstraintTypeInfo's */ 00113 bConstraintTypeInfo *constraint_get_typeinfo(struct bConstraint *con); 00114 bConstraintTypeInfo *get_constraint_typeinfo(int type); 00115 00116 /* ---------------------------------------------------------------------------- */ 00117 /* Useful macros for testing various common flag combinations */ 00118 00119 /* Constraint Target Macros */ 00120 #define VALID_CONS_TARGET(ct) ((ct) && (ct->tar)) 00121 00122 /* ---------------------------------------------------------------------------- */ 00123 00124 /* Constraint function prototypes */ 00125 void unique_constraint_name(struct bConstraint *con, struct ListBase *list); 00126 00127 void free_constraints(struct ListBase *list); 00128 void copy_constraints(struct ListBase *dst, const struct ListBase *src, int do_extern); 00129 void relink_constraints(struct ListBase *list); 00130 void id_loop_constraints(struct ListBase *list, ConstraintIDFunc func, void *userdata); 00131 void free_constraint_data(struct bConstraint *con); 00132 00133 /* Constraint API function prototypes */ 00134 struct bConstraint *constraints_get_active(struct ListBase *list); 00135 void constraints_set_active(ListBase *list, struct bConstraint *con); 00136 struct bConstraint *constraints_findByName(struct ListBase *list, const char *name); 00137 00138 struct bConstraint *add_ob_constraint(struct Object *ob, const char *name, short type); 00139 struct bConstraint *add_pose_constraint(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type); 00140 00141 int remove_constraint(ListBase *list, struct bConstraint *con); 00142 void remove_constraints_type(ListBase *list, short type, short last_only); 00143 00144 /* Constraints + Proxies function prototypes */ 00145 void extract_proxylocal_constraints(struct ListBase *dst, struct ListBase *src); 00146 short proxylocked_constraints_owner(struct Object *ob, struct bPoseChannel *pchan); 00147 00148 /* Constraint Evaluation function prototypes */ 00149 struct bConstraintOb *constraints_make_evalob(struct Scene *scene, struct Object *ob, void *subdata, short datatype); 00150 void constraints_clear_evalob(struct bConstraintOb *cob); 00151 00152 void constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, float mat[][4], short from, short to); 00153 00154 void get_constraint_target_matrix(struct Scene *scene, struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime); 00155 void get_constraint_targets_for_solving(struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime); 00156 void solve_constraints(struct ListBase *conlist, struct bConstraintOb *cob, float ctime); 00157 00158 #ifdef __cplusplus 00159 } 00160 #endif 00161 00162 #endif 00163