1
votes

I got a car simulation software that allows parameter inputs via a script control window.

What I want to do is write a small C++ Application which does some calculation and starts feeding line by line commands into the tcl script control window of the car simulator.

The idea is to use a head-tracking sensor to get the current position in the xyz - plane and then based on the data do some processing and automatically write something like:

>> Movie eval {dict set View(0:0) xrot 12 yrot 0 zrot 0}

into the script window, to adjust the current view.

Above command would translate into panning the current camera view into the 12 degree position to the right (x -direction), being 0 degrees = looking to the front.

So my question is now: How can I tell my C++ Application to write above command into an open script control window?

1
I'm not convinced that you want to do exactly what you've written, based on knowledge of dict set, but that's not what your question is really about… - Donal Fellows

1 Answers

0
votes

The simplest way might be to use the comm package in Tcllib (the Tcl community standard library). The only real complexity is that the protocol it uses is not publicly defined (it's mostly sending commands encoded in a particular format) so you'll need some way to talk it easily.

The easiest method of talking it may be to embed a Tcl interpreter in your C++ application. Then you'll be able to load the comm package into the interpreter and use comm::comm send to do what you want (you'll also have to require the package on the other side and copy across the ID, but that should be easy enough).

set remoteid ???;  # Look this up with [comm::comm self] on the other side
comm::comm send $remoteid \
    dict set View(0:0) xrot 12 yrot 0 zrot 0

Of course, you'll need to wrap that up inside appropriate calls to Tcl_Eval(), having first created a local interpreter with Tcl_CreateInterp() after initialising the Tcl library with Tcl_FindExecutable(), and so on, but that's just standard embedding.