4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): 2007 - Joshua Leung (major recode)
27 * ***** END GPL LICENSE BLOCK *****
30 #ifndef BKE_CONSTRAINT_H
31 #define BKE_CONSTRAINT_H
34 struct bConstraintTarget;
40 /* ---------------------------------------------------------------------------- */
42 /* special struct for use in constraint evaluation */
43 typedef struct bConstraintOb {
44 struct Scene *scene; /* for system time, part of deglobalization, code nicer later with local time (ton) */
45 struct Object *ob; /* if pchan, then armature that it comes from, otherwise constraint owner */
46 struct bPoseChannel *pchan; /* pose channel that owns the constraints being evaluated */
48 float matrix[4][4]; /* matrix where constraints are accumulated + solved */
49 float startmat[4][4]; /* original matrix (before constraint solving) */
51 short type; /* type of owner */
54 /* ---------------------------------------------------------------------------- */
56 /* Constraint Type-Info (shorthand in code = cti):
57 * This struct provides function pointers for runtime, so that functions can be
58 * written more generally (with fewer/no special exceptions for various constraints).
60 * Callers of these functions must check that they actually point to something useful,
61 * as some constraints don't define some of these.
63 * Warning: it is not too advisable to reorder order of members of this struct,
64 * as you'll have to edit quite a few ($NUM_CONSTRAINT_TYPES) of these
67 typedef struct bConstraintTypeInfo {
69 short type; /* CONSTRAINT_TYPE_### */
70 short size; /* size in bytes of the struct */
71 char name[32]; /* name of constraint in interface */
72 char structName[32]; /* name of struct for SDNA */
74 /* data management function pointers - special handling */
75 /* free any data that is allocated separately (optional) */
76 void (*free_data)(struct bConstraint *con);
77 /* adjust pointer to other ID-data using ID_NEW(), but not to targets (optional) */
78 void (*relink_data)(struct bConstraint *con);
79 /* copy any special data that is allocated separately (optional) */
80 void (*copy_data)(struct bConstraint *con, struct bConstraint *src);
81 /* set settings for data that will be used for bConstraint.data (memory already allocated using MEM_callocN) */
82 void (*new_data)(void *cdata);
84 /* target handling function pointers */
85 /* for multi-target constraints: return that list; otherwise make a temporary list (returns number of targets) */
86 int (*get_constraint_targets)(struct bConstraint *con, struct ListBase *list);
87 /* for single-target constraints only: flush data back to source data, and the free memory used */
88 void (*flush_constraint_targets)(struct bConstraint *con, struct ListBase *list, short nocopy);
91 /* set the ct->matrix for the given constraint target (at the given ctime) */
92 void (*get_target_matrix)(struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime);
93 /* evaluate the constraint for the given time */
94 void (*evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets);
95 } bConstraintTypeInfo;
97 /* Function Prototypes for bConstraintTypeInfo's */
98 bConstraintTypeInfo *constraint_get_typeinfo(struct bConstraint *con);
99 bConstraintTypeInfo *get_constraint_typeinfo(int type);
101 /* ---------------------------------------------------------------------------- */
102 /* Useful macros for testing various common flag combinations */
104 /* Constraint Target Macros */
105 #define VALID_CONS_TARGET(ct) ((ct) && (ct->tar))
108 /* ---------------------------------------------------------------------------- */
110 /* Constraint function prototypes */
111 void unique_constraint_name(struct bConstraint *con, struct ListBase *list);
113 void free_constraints(struct ListBase *list);
114 void copy_constraints(struct ListBase *dst, struct ListBase *src);
115 void relink_constraints(struct ListBase *list);
116 void free_constraint_data(struct bConstraint *con);
118 struct bConstraint *constraints_get_active(struct ListBase *list);
120 /* Constraints + Proxies function prototypes */
121 void extract_proxylocal_constraints(struct ListBase *dst, struct ListBase *src);
122 short proxylocked_constraints_owner(struct Object *ob, struct bPoseChannel *pchan);
124 /* Constraint Evaluation function prototypes */
125 struct bConstraintOb *constraints_make_evalob(struct Scene *scene, struct Object *ob, void *subdata, short datatype);
126 void constraints_clear_evalob(struct bConstraintOb *cob);
128 void constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, float mat[][4], short from, short to);
130 void get_constraint_target_matrix(struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime);
131 void solve_constraints(struct ListBase *conlist, struct bConstraintOb *cob, float ctime);