Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search

Drawing a spline

Page  12>
Author
Message
  Topic Search Topic Search
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 831
Direct Link To This Post Topic: Drawing a spline
    Posted: 2011 Feb 06 at 7:34pm

User Information:

Cinema 4D Version:   12 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Okay so I am delving into doing some work with splines.  I am able to create a spline object with...

SplineObject *sp = SplineObject::Alloc(6, SPLINETYPE_CUBIC);
    if(!sp) return NULL;

and can insert that spline in to the scene,

But how do I set the value of each of the 6 points that I created?  As of right now, this just creates a spline object that has no points.  How can I create a spline and specify the individual points of that spline before it gets inserted in to the scene?

Thanks,

Shawn
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2011 Feb 06 at 9:35pm
In Coffee one can use "sp->SetPoint(int i,vector pos);" if you want to set just one Point. If the point does not exist it will be automatically created.
If you have an array of vectors, one can use "sp->SetPoints(array arr);".

I don't think it's much different in C++, it should be documented in the SDK. (PointObject)

Cheers, nux

Edited by nux95 - 2011 Feb 07 at 1:20am
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 2204
Direct Link To This Post Posted: 2011 Feb 07 at 12:37am
The SplineObject class is derived from the PointObject class. Look at the methods of the PointObject class to modify spline points. The SplineObject class has additional methods to access tangent data.

cheers,
Matthias

MAXON
developer support
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 831
Direct Link To This Post Posted: 2011 Feb 07 at 3:21am
Thanks to both of you.  I see in the C++ docs that SetPoint() and SetPoints() are part of the Modeling Class.  Are these the methods that I would use to insert the points of the spline?

Thanks,

Shawn
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 658
Direct Link To This Post Posted: 2011 Feb 07 at 4:41am
I usually access the writeable point array.


Vector *padr = ((PointObject*)splineop)->GetPointW();
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 2204
Direct Link To This Post Posted: 2011 Feb 07 at 5:24am
Originally posted by c4dJack

I usually access the writeable point array.


Vector *padr = ((PointObject*)splineop)->GetPointW();


Casting is not necessary because SplineObject is derived from PointObject.

Just write:
Vector *padr = splineop->GetPointW();


cheers,
Matthias


MAXON
developer support
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 831
Direct Link To This Post Posted: 2011 Feb 07 at 5:58am
Okay so let's see fi I understand right.   I create the spline the way I did at teh top and because I point a point number in the allocation, that is the number of points I will have in teh spline,   then, I access those points through the points array like listed above? 
 
~Shawn
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 2204
Direct Link To This Post Posted: 2011 Feb 07 at 6:14am
Yes, that's correct so far. Please check the circle.cpp file of the SDK examples, especially the stuff in the GenerateCircle fucnction.

cheers,
Matthias

MAXON
developer support
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 831
Direct Link To This Post Posted: 2011 Feb 07 at 6:34am
cool.. thanks Matthias.  I'll check it out when I get home tonight.,  :)
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2011 Feb 07 at 10:55am
I looked at the Circle.cpp example. But It's dealing with creating a spline primitive. Not a new spline from scratch. So I'm still not sure how to properly create a spline from scratch.

This code will create a spline for me:
SplineObject *sp = SplineObject::Alloc(3, SPLINETYPE_LINEAR); // create a spline with 3 verts
    if(!sp) return NULL;
  doc->InsertObject(sp, NULL, NULL, 0); // Add it to the OM

  Vector *gp = sp->GetPointW();// The point array of the spline
  gp[0] = Vector(0,0,-100);// Place the first point here
  gp[1] = Vector(0,0,0);// Place the second point here
  gp[2] = Vector(0,0,100);// Place the third point here
EventAdd();//Update all the changes

But the problem is the spline doesn't show up properly in the view until I physically move the points around a little bit.


In Coffee you have to use this code with the spline class:
var vc = new(VariableChanged);
vc->Init(0,pointcount);
myspline->Message(MSG_POINTS_CHANGED,vc);

So I was wondering if I need to also use this same code in C++ for the splines to draw properly?
I'm having a hard time converting that to a C++ version.

-ScottA


Edited by ScottA - 2011 Feb 07 at 10:56am
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 831
Direct Link To This Post Posted: 2011 Feb 07 at 11:49am
probably because all points are created at world center?  That's just a guess.  I have to get home to see the docs to be sure.
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2011 Feb 07 at 12:11pm
The three vector lines of code place the points so they aren't at the origin. So that's not it.
I'm pretty sure the problem is C4D needs to be told that points have been changed for it to work properly. I just don't know how to write the C++ version of that.

BTW: I'm a Coffee user and new to the whole C++ API thing. But I've learned a lot from your posts. So keep posting those questions and code snippets. Beer

Back to Top
Cactus Dan View Drop Down
Member
Member
Avatar

Joined: 2003 Apr 18
Location: United States
Online Status: Offline
Posts: 1053
Direct Link To This Post Posted: 2011 Feb 07 at 12:23pm
Howdy,

Try adding the line:
sp->Message(MSG_UPDATE);

...after you change the points. Wink

Adios,
Cactus Dan
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2011 Feb 07 at 1:10pm
@ScottA:
You forgot to set the points back to the SplineObject. I'm just using Coffe, so i can't give you the C++ code, but it should be similiar to what i said in the second post.

sp->SetPoints(gp);


Btw: As far as I know, one have to use VariableChanged only when the SplineObject has tags on it like a selectiontag for e.g. which depends on the points of it's Object.


Edited by nux95 - 2011 Feb 07 at 1:31pm
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2011 Feb 07 at 1:40pm
Thanks Dan. That seems to help.
I'm also using Vista64 without Aero enabled. Which causes draw issues in C4D for me.
That was also making the spline look like it wasn't there, when it really was there.

So this whole VariableChanged stuff for splines is only for things with tags on them then?
I just want to make sure I understand how the spline class works.

-ScottA


Edited by ScottA - 2011 Feb 07 at 1:41pm
Back to Top
Cactus Dan View Drop Down
Member
Member
Avatar

Joined: 2003 Apr 18
Location: United States
Online Status: Offline
Posts: 1053
Direct Link To This Post Posted: 2011 Feb 07 at 1:48pm
Howdy,

In C++, there is no SetPoints() function. Calling the GetPointW() function returns a pointer to the points array, giving you direct access to the points.

In the documentation for the MSG_UPDATE:

MSG_UPDATE

Must be sent if the bounding box has to be recalculated. (Otherwise you can use MSG_CHANGE.)

... since the point's positions have been changed, the bounding box of the spline must be recalculated. I'm not exactly sure but I think some other things get updated, too, when that message is received. In any case, when a point object receives that message it seems to update the point positions.

By the way, an object's points are stored in a hidden variable tag (Tpoint), so every spline and polygon object has that hidden tag on it. Wink

In the C++ documentation, if you go to the C4DAtom class and then to the Message() function of that class, you'll see a list of messages from the MSG_Atom with explanations of their use.

Adios,
Cactus Dan


Edited by Cactus Dan - 2011 Feb 07 at 1:49pm
Back to Top
NiklasR View Drop Down
Member
Member


Joined: 2010 Dec 13
Location: Germany
Online Status: Offline
Posts: 2575
Direct Link To This Post Posted: 2011 Feb 07 at 1:59pm
Oh, thanks, couldn't imagine it's different in C++, but now i know better. ;)
Back to Top
Cactus Dan View Drop Down
Member
Member
Avatar

Joined: 2003 Apr 18
Location: United States
Online Status: Offline
Posts: 1053
Direct Link To This Post Posted: 2011 Feb 07 at 2:05pm
Howdy,

Yeah, coffee is very similar to c++, but from what I remember about coffee, there were more functions you had to call to perform an operation, where in c++ you simply performed the operation.

Adios,
Cactus Dan
Back to Top
emberintherain View Drop Down
Member
Member
Avatar

Joined: 2008 Dec 23
Location: United States
Online Status: Offline
Posts: 831
Direct Link To This Post Posted: 2011 Feb 07 at 4:04pm
hey scott would you mind sharing with me the final working code you got.  The4 code above keeps making my c4d crash out. 

Thanks,

Shawn
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2288
Direct Link To This Post Posted: 2011 Feb 07 at 9:11pm
Sure. Here's the code again:


SplineObject *sp = SplineObject::Alloc(3, SPLINETYPE_LINEAR); // create a linear spline with 3 verts
    if(!sp) return NULL;
  doc->InsertObject(sp, NULL, NULL, 0); // Add it to the OM

  Vector *gp = sp->GetPointW();// The point array of the spline
  gp[0] = Vector(10,0,-100);// Place the first point here
  gp[1] = Vector(0,0,0);// Place the first point here
  gp[2] = Vector(-10,0,100);// Place the first point here
  EventAdd();//Update all the changes
  sp->Message(MSG_UPDATE);


I'm a little surprised that there's no code block formatting option for this forum. To make posting code snippets easier to read.

-ScottA


Edited by ScottA - 2011 Feb 07 at 9:15pm
Back to Top
Page  12>

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.141 seconds.