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