<commit_before>#pragma once

#include <tudocomp/Compressor.hpp>

#include <sdsl/cst_fully.hpp>
#include <sdsl/cst_sada.hpp>

#include <tudocomp/Range.hpp>
#include <tudocomp/ds/TextDS.hpp>

#include <tudocomp/compressors/lz78/LZ78Trie.hpp>

#include "lz78u/SuffixTree.hpp"

#include "lz78u/pre_header.hpp"

namespace tdc {
namespace lz78u {

    // TODO: Define factorid for lz78u uniformly

    class Decompressor {
        std::vector<lz78::factorid_t> indices;
        std::vector<uliteral_t> literal_strings;
        std::vector<size_t> start_literal_strings;

        std::vector<uliteral_t> buffer;

        public:
        inline lz78::factorid_t ref_at(lz78::factorid_t index) const {
            DCHECK_NE(index, 0);
            size_t i = index - 1;
            return indices[i];
        }
        inline View str_at(lz78::factorid_t index) const {
            DCHECK_NE(index, 0);
            size_t i = index - 1;
            View ls = literal_strings;

            size_t start = start_literal_strings[i];
            size_t end = 0;
            if ((i + 1) < start_literal_strings.size()) {
                end = start_literal_strings[i + 1];
            } else {
                end = ls.size();
            }

            return ls.slice(start, end);
        }

        inline void decompress(lz78::factorid_t index, View literals, std::ostream& out) {
            indices.push_back(index);
            start_literal_strings.push_back(literal_strings.size());
            for (auto c : literals) {
                literal_strings.push_back(c);
            }

            //std::cout << "    indices:         " << vec_to_debug_string(indices) << "\n";
            //std::cout << "    start lit str:   " << vec_to_debug_string(start_literal_strings) << "\n";
            //std::cout << "    literal_strings: " << vec_to_debug_string(literal_strings) << "\n";

            buffer.clear();

            while(true) {
                auto inv_old_size = buffer.size();
                for (size_t i = 0; i < literals.size(); i++) {
                    buffer.push_back(literals[literals.size() - i - 1]);
                }

                DCHECK_EQ(inv_old_size + literals.size(), buffer.size());

                if (index == 0) {
                    break;
                }
                literals = str_at(index);
                index = ref_at(index);
            }

            std::reverse(buffer.begin(), buffer.end());
            //std::cout << "    reconstructed: " << vec_to_debug_string(buffer) << "\n";
            out << buffer;
        }

    };
}

template<typename strategy_t, typename ref_coder_t>
class LZ78UCompressor: public Compressor {
private:
    using node_type = SuffixTree::node_type;

    using RefEncoder = typename ref_coder_t::Encoder;
    using RefDecoder = typename ref_coder_t::Decoder;

    using CompressionStrat
        = typename strategy_t::template Compression<RefEncoder>;
    using DecompressionStrat
        = typename strategy_t::template Decompression<RefDecoder>;

public:
    inline LZ78UCompressor(Env&& env):
        Compressor(std::move(env))
    {}

    inline static Meta meta() {
        Meta m("compressor", "lz78u", "Lempel-Ziv 78 U\n\n" );
        m.option("comp").templated<strategy_t>();
        m.option("coder").templated<ref_coder_t>();
        m.option("threshold").dynamic("3");
        // m.option("dict_size").dynamic("inf");
        m.needs_sentinel_terminator();
        return m;
    }

    virtual void compress(Input& input, Output& out) override {
        auto phase1 = env().stat_phase("lz78u");
        //std::cout << "START COMPRESS\n";
        const len_t threshold = env().option("threshold").as_integer(); //factor threshold
        env().log_stat("threshold", threshold);

        auto iview = input.as_view();
        View T = iview;

        SuffixTree::cst_t backing_cst;
        {
            auto phase2 = env().stat_phase("construct suffix tree");

            // TODO: Specialize sdsl template for less alloc here
            std::string bad_copy_1 = T.slice(0, T.size() - 1);
            //std::cout << "text: " << vec_to_debug_string(bad_copy_1) << "\n";

            construct_im(backing_cst, bad_copy_1, 1);
        }
        SuffixTree ST(backing_cst);

        const size_t max_z = T.size() * bits_for(ST.cst.csa.sigma) / bits_for(T.size());
        env().log_stat("max z", max_z);

        sdsl::int_vector<> R(ST.internal_nodes,0,bits_for(max_z));

        len_t pos = 0;
        len_t z = 0;

        typedef SuffixTree::node_type node_t;

        CompressionStrat strategy {
            env().env_for_option("comp"),
            env().env_for_option("coder"),
            std::make_shared<BitOStream>(out)
        };

        len_t factor_count = 0;

        // `begin` and `end` denote a half-open range [begin, end)
        // of characters of the input string
        auto output = [&](len_t begin, len_t end, size_t ref) {
            // if trailing 0, remove
            while(T[end-1] == 0) --end;

            // First, encode the reference
            DVLOG(2) << "reference";
            strategy.encode_ref(ref, Range(factor_count));

            // factorize the factor label if the label is above the threshold
            if (end-begin >= threshold) {
                DVLOG(2) << "factorized";

                // indicate that this is a factorized string
                strategy.encode_sep(false);

                for(len_t pos = begin; pos < end;) {
                    // similar to the normal LZ78U factorization, but does not introduce new factor ids

                    const node_t leaf = ST.select_leaf(ST.cst.csa.isa[pos]);
                    len_t d = 1;
                    node_t parent = ST.root;
                    node_t node = ST.level_anc(leaf, d);
                    while(!ST.cst.is_leaf(node) && R[ST.nid(node)] != 0) {
                        parent = node;
                        node = ST.level_anc(leaf, ++d);
                    } // not a good feature: We lost the factor ids of the leaves, since R only stores the IDs of internal nodes
                    const len_t depth = ST.str_depth(parent);
                    // if the largest factor is not large enough, we only store the current character and move one text position to the right
                    if(depth < threshold) {
                        DVLOG(2) << "sub char";
                        strategy.encode_sep(false);
                        strategy.encode_char(T[pos]);
                        ++pos;
                    } else {
                        DVLOG(2) << "sub ref";
                        strategy.encode_sep(true);
                        strategy.encode_ref(R[ST.nid(parent)], Range(factor_count));
                        pos += depth;
                        // taking the last factor can make the string larger than intended, so we have to store a cut-value at the last position
                        if(pos > end) {
                            // TODO: Is this encoding efficient enough?

                            // 0 factors would not appear here, so use 0 as a escape
                            // char to indicate that a cut-value follows
                            DVLOG(2) << "special sub ref";
                            strategy.encode_sep(true);
                            strategy.encode_ref(0, Range(factor_count));
                            strategy.encode_ref(pos-end, len_r);
                        }
                    }
                }
                // all char sequencens in a factor need to be 0 terminated
                DVLOG(2) << "sub char term";
                strategy.encode_sep(false);
                strategy.encode_char(0);
            } else {
                // else just output the string as a whole

                // indicate that this is not a factorized string
                DVLOG(2) << "plain";
                strategy.encode_sep(true);
                strategy.encode_str(T.slice(begin,end));
            }

            factor_count++;
        };

        DVLOG(2) << "[ compress ]";

        // Skip the trailing 0
        while(pos < T.size() - 1) {
            const node_t l = ST.select_leaf(ST.cst.csa.isa[pos]);
            const len_t leaflabel = pos;

            if(ST.parent(l) == ST.root || R[ST.nid(ST.parent(l))] != 0) {
                const len_t parent_strdepth = ST.str_depth(ST.parent(l));

                //std::cout << "out leaf: [" << (pos+parent_strdepth)  << ","<< (pos + parent_strdepth + 1) << "] ";
                output(pos + parent_strdepth,
                       pos + parent_strdepth + 1,
                       R[ST.nid(ST.parent(l))]);

                pos += parent_strdepth+1;
                ++z;

                DCHECK_EQ(z, factor_count);

                continue;
            }

            len_t d = 1;
            node_t parent = ST.root;
            node_t node = ST.level_anc(l, d);

            while(R[ST.nid(node)] != 0) {
                parent = node;
                node = ST.level_anc(l, ++d);
            }
            pos += ST.str_depth(parent);

            // const auto& str = T.slice(leaflabel + ST.str_depth(parent), leaflabel + ST.str_depth(node));
            const len_t begin = leaflabel + ST.str_depth(parent);
            const len_t end = leaflabel + ST.str_depth(node);

            //std::cout << "out slice: [ "<< (leaflabel + ST.str_depth(parent)) << ", "<< (leaflabel + ST.str_depth(node))<< " ] ";
            output(begin,
                   end,
                   R[ST.nid(ST.parent(node))]);
            R[ST.nid(node)] = ++z;

            pos += end - begin;
            DCHECK_EQ(z, factor_count);
        }
    }

    virtual void decompress(Input& input, Output& output) override final {
        //std::cout << "START DECOMPRESS\n";
        DVLOG(2) << "[ decompress ]";
        auto out = output.as_stream();

        {
            DecompressionStrat strategy {
                env().env_for_option("strategy"),
                env().env_for_option("coder"),
                std::make_shared<BitIStream>(input)
            };

            uint64_t factor_count = 0;

            lz78u::Decompressor decomp;

            std::vector<uliteral_t> rebuilt_buffer;

            while (!strategy.eof()) {
                auto ref = strategy.decode_ref(Range(factor_count));
                DVLOG(2) << "";
                DVLOG(2) << "decode ref: " << ref;
                DVLOG(2) << "";
                bool not_factorized = strategy.decode_sep();
                DVLOG(2) << "decode sep: " << int(not_factorized);

                if (not_factorized) {
                    auto str = strategy.decode_str();
                    DVLOG(2) << "decode str: '" << str << "\\0'";
                    DVLOG(2) << "  ...'"
                        << ((ref > 0) ? decomp.str_at(ref) : ""_v)
                        << "' '"
                        << str
                        << "'";
                    decomp.decompress(ref, str, out);
                } else {
                    // rebuild the factorized string label
                    rebuilt_buffer.clear();

                    while (true) {
                        bool is_sub_char = !strategy.decode_sep();
                        DVLOG(2) << "decode sep: " << int(!is_sub_char);

                        if (is_sub_char) {
                            auto sub_chr = strategy.decode_char();
                            DVLOG(2) << "decode chr: " << int(sub_chr);

                            rebuilt_buffer.push_back(sub_chr);
                        } else {
                            auto sub_ref = strategy.decode_ref(Range(factor_count));
                            DVLOG(2) << "decode ref: " << sub_ref;

                            if (sub_ref == 0) {
                                // found a cut-value
                                auto cut = strategy.decode_ref(len_r);
                                DVLOG(2) << "decode special ref: " << cut;
                                while (cut > 0) {
                                    rebuilt_buffer.pop_back();
                                    --cut;
                                }
                            } else {
                                size_t prev_r = sub_ref;
                                size_t old_end = rebuilt_buffer.size();

                                // push the chars in reverse order
                                // to allow efficient appending of prefixes
                                do {
                                    View s = decomp.str_at(prev_r);
                                    prev_r = decomp.ref_at(prev_r);

                                    for (size_t j = 0; j < s.size(); j++) {
                                        rebuilt_buffer.push_back(s[s.size() - j - 1]);
                                    }
                                } while (prev_r != 0);
                                DCHECK_EQ(prev_r, 0);

                                // reverse suffix containing the new string fragment
                                std::reverse(rebuilt_buffer.begin() + old_end,
                                             rebuilt_buffer.end());
                            }
                        }

                        if (rebuilt_buffer.size() > 0 && rebuilt_buffer.back() == 0) {
                            rebuilt_buffer.pop_back();
                            break;
                        }
                    }
                    DVLOG(2) << "USED!";
                    DVLOG(2) << "  ...'"
                        << ((ref > 0) ? decomp.str_at(ref) : ""_v)
                        << "' '"
                        << rebuilt_buffer << "'";
                    decomp.decompress(ref, rebuilt_buffer, out);
                }

                /*
                std::cout << "in m (s,r): ("
                    << vec_to_debug_string(factor.string)
                    << ", " << int(factor.ref) << ")\n";
                */

                factor_count++;
            }
        }

        out << '\0';
        out.flush();
    }

};

}//ns
<commit_msg>strategy -> comp<commit_after>#pragma once

#include <tudocomp/Compressor.hpp>

#include <sdsl/cst_fully.hpp>
#include <sdsl/cst_sada.hpp>

#include <tudocomp/Range.hpp>
#include <tudocomp/ds/TextDS.hpp>

#include <tudocomp/compressors/lz78/LZ78Trie.hpp>

#include "lz78u/SuffixTree.hpp"

#include "lz78u/pre_header.hpp"

namespace tdc {
namespace lz78u {

    // TODO: Define factorid for lz78u uniformly

    class Decompressor {
        std::vector<lz78::factorid_t> indices;
        std::vector<uliteral_t> literal_strings;
        std::vector<size_t> start_literal_strings;

        std::vector<uliteral_t> buffer;

        public:
        inline lz78::factorid_t ref_at(lz78::factorid_t index) const {
            DCHECK_NE(index, 0);
            size_t i = index - 1;
            return indices[i];
        }
        inline View str_at(lz78::factorid_t index) const {
            DCHECK_NE(index, 0);
            size_t i = index - 1;
            View ls = literal_strings;

            size_t start = start_literal_strings[i];
            size_t end = 0;
            if ((i + 1) < start_literal_strings.size()) {
                end = start_literal_strings[i + 1];
            } else {
                end = ls.size();
            }

            return ls.slice(start, end);
        }

        inline void decompress(lz78::factorid_t index, View literals, std::ostream& out) {
            indices.push_back(index);
            start_literal_strings.push_back(literal_strings.size());
            for (auto c : literals) {
                literal_strings.push_back(c);
            }

            //std::cout << "    indices:         " << vec_to_debug_string(indices) << "\n";
            //std::cout << "    start lit str:   " << vec_to_debug_string(start_literal_strings) << "\n";
            //std::cout << "    literal_strings: " << vec_to_debug_string(literal_strings) << "\n";

            buffer.clear();

            while(true) {
                auto inv_old_size = buffer.size();
                for (size_t i = 0; i < literals.size(); i++) {
                    buffer.push_back(literals[literals.size() - i - 1]);
                }

                DCHECK_EQ(inv_old_size + literals.size(), buffer.size());

                if (index == 0) {
                    break;
                }
                literals = str_at(index);
                index = ref_at(index);
            }

            std::reverse(buffer.begin(), buffer.end());
            //std::cout << "    reconstructed: " << vec_to_debug_string(buffer) << "\n";
            out << buffer;
        }

    };
}

template<typename strategy_t, typename ref_coder_t>
class LZ78UCompressor: public Compressor {
private:
    using node_type = SuffixTree::node_type;

    using RefEncoder = typename ref_coder_t::Encoder;
    using RefDecoder = typename ref_coder_t::Decoder;

    using CompressionStrat
        = typename strategy_t::template Compression<RefEncoder>;
    using DecompressionStrat
        = typename strategy_t::template Decompression<RefDecoder>;

public:
    inline LZ78UCompressor(Env&& env):
        Compressor(std::move(env))
    {}

    inline static Meta meta() {
        Meta m("compressor", "lz78u", "Lempel-Ziv 78 U\n\n" );
        m.option("comp").templated<strategy_t>();
        m.option("coder").templated<ref_coder_t>();
        m.option("threshold").dynamic("3");
        // m.option("dict_size").dynamic("inf");
        m.needs_sentinel_terminator();
        return m;
    }

    virtual void compress(Input& input, Output& out) override {
        auto phase1 = env().stat_phase("lz78u");
        //std::cout << "START COMPRESS\n";
        const len_t threshold = env().option("threshold").as_integer(); //factor threshold
        env().log_stat("threshold", threshold);

        auto iview = input.as_view();
        View T = iview;

        SuffixTree::cst_t backing_cst;
        {
            auto phase2 = env().stat_phase("construct suffix tree");

            // TODO: Specialize sdsl template for less alloc here
            std::string bad_copy_1 = T.slice(0, T.size() - 1);
            //std::cout << "text: " << vec_to_debug_string(bad_copy_1) << "\n";

            construct_im(backing_cst, bad_copy_1, 1);
        }
        SuffixTree ST(backing_cst);

        const size_t max_z = T.size() * bits_for(ST.cst.csa.sigma) / bits_for(T.size());
        env().log_stat("max z", max_z);

        sdsl::int_vector<> R(ST.internal_nodes,0,bits_for(max_z));

        len_t pos = 0;
        len_t z = 0;

        typedef SuffixTree::node_type node_t;

        CompressionStrat strategy {
            env().env_for_option("comp"),
            env().env_for_option("coder"),
            std::make_shared<BitOStream>(out)
        };

        len_t factor_count = 0;

        // `begin` and `end` denote a half-open range [begin, end)
        // of characters of the input string
        auto output = [&](len_t begin, len_t end, size_t ref) {
            // if trailing 0, remove
            while(T[end-1] == 0) --end;

            // First, encode the reference
            DVLOG(2) << "reference";
            strategy.encode_ref(ref, Range(factor_count));

            // factorize the factor label if the label is above the threshold
            if (end-begin >= threshold) {
                DVLOG(2) << "factorized";

                // indicate that this is a factorized string
                strategy.encode_sep(false);

                for(len_t pos = begin; pos < end;) {
                    // similar to the normal LZ78U factorization, but does not introduce new factor ids

                    const node_t leaf = ST.select_leaf(ST.cst.csa.isa[pos]);
                    len_t d = 1;
                    node_t parent = ST.root;
                    node_t node = ST.level_anc(leaf, d);
                    while(!ST.cst.is_leaf(node) && R[ST.nid(node)] != 0) {
                        parent = node;
                        node = ST.level_anc(leaf, ++d);
                    } // not a good feature: We lost the factor ids of the leaves, since R only stores the IDs of internal nodes
                    const len_t depth = ST.str_depth(parent);
                    // if the largest factor is not large enough, we only store the current character and move one text position to the right
                    if(depth < threshold) {
                        DVLOG(2) << "sub char";
                        strategy.encode_sep(false);
                        strategy.encode_char(T[pos]);
                        ++pos;
                    } else {
                        DVLOG(2) << "sub ref";
                        strategy.encode_sep(true);
                        strategy.encode_ref(R[ST.nid(parent)], Range(factor_count));
                        pos += depth;
                        // taking the last factor can make the string larger than intended, so we have to store a cut-value at the last position
                        if(pos > end) {
                            // TODO: Is this encoding efficient enough?

                            // 0 factors would not appear here, so use 0 as a escape
                            // char to indicate that a cut-value follows
                            DVLOG(2) << "special sub ref";
                            strategy.encode_sep(true);
                            strategy.encode_ref(0, Range(factor_count));
                            strategy.encode_ref(pos-end, len_r);
                        }
                    }
                }
                // all char sequencens in a factor need to be 0 terminated
                DVLOG(2) << "sub char term";
                strategy.encode_sep(false);
                strategy.encode_char(0);
            } else {
                // else just output the string as a whole

                // indicate that this is not a factorized string
                DVLOG(2) << "plain";
                strategy.encode_sep(true);
                strategy.encode_str(T.slice(begin,end));
            }

            factor_count++;
        };

        DVLOG(2) << "[ compress ]";

        // Skip the trailing 0
        while(pos < T.size() - 1) {
            const node_t l = ST.select_leaf(ST.cst.csa.isa[pos]);
            const len_t leaflabel = pos;

            if(ST.parent(l) == ST.root || R[ST.nid(ST.parent(l))] != 0) {
                const len_t parent_strdepth = ST.str_depth(ST.parent(l));

                //std::cout << "out leaf: [" << (pos+parent_strdepth)  << ","<< (pos + parent_strdepth + 1) << "] ";
                output(pos + parent_strdepth,
                       pos + parent_strdepth + 1,
                       R[ST.nid(ST.parent(l))]);

                pos += parent_strdepth+1;
                ++z;

                DCHECK_EQ(z, factor_count);

                continue;
            }

            len_t d = 1;
            node_t parent = ST.root;
            node_t node = ST.level_anc(l, d);

            while(R[ST.nid(node)] != 0) {
                parent = node;
                node = ST.level_anc(l, ++d);
            }
            pos += ST.str_depth(parent);

            // const auto& str = T.slice(leaflabel + ST.str_depth(parent), leaflabel + ST.str_depth(node));
            const len_t begin = leaflabel + ST.str_depth(parent);
            const len_t end = leaflabel + ST.str_depth(node);

            //std::cout << "out slice: [ "<< (leaflabel + ST.str_depth(parent)) << ", "<< (leaflabel + ST.str_depth(node))<< " ] ";
            output(begin,
                   end,
                   R[ST.nid(ST.parent(node))]);
            R[ST.nid(node)] = ++z;

            pos += end - begin;
            DCHECK_EQ(z, factor_count);
        }
    }

    virtual void decompress(Input& input, Output& output) override final {
        //std::cout << "START DECOMPRESS\n";
        DVLOG(2) << "[ decompress ]";
        auto out = output.as_stream();

        {
            DecompressionStrat strategy {
                env().env_for_option("comp"),
                env().env_for_option("coder"),
                std::make_shared<BitIStream>(input)
            };

            uint64_t factor_count = 0;

            lz78u::Decompressor decomp;

            std::vector<uliteral_t> rebuilt_buffer;

            while (!strategy.eof()) {
                auto ref = strategy.decode_ref(Range(factor_count));
                DVLOG(2) << "";
                DVLOG(2) << "decode ref: " << ref;
                DVLOG(2) << "";
                bool not_factorized = strategy.decode_sep();
                DVLOG(2) << "decode sep: " << int(not_factorized);

                if (not_factorized) {
                    auto str = strategy.decode_str();
                    DVLOG(2) << "decode str: '" << str << "\\0'";
                    DVLOG(2) << "  ...'"
                        << ((ref > 0) ? decomp.str_at(ref) : ""_v)
                        << "' '"
                        << str
                        << "'";
                    decomp.decompress(ref, str, out);
                } else {
                    // rebuild the factorized string label
                    rebuilt_buffer.clear();

                    while (true) {
                        bool is_sub_char = !strategy.decode_sep();
                        DVLOG(2) << "decode sep: " << int(!is_sub_char);

                        if (is_sub_char) {
                            auto sub_chr = strategy.decode_char();
                            DVLOG(2) << "decode chr: " << int(sub_chr);

                            rebuilt_buffer.push_back(sub_chr);
                        } else {
                            auto sub_ref = strategy.decode_ref(Range(factor_count));
                            DVLOG(2) << "decode ref: " << sub_ref;

                            if (sub_ref == 0) {
                                // found a cut-value
                                auto cut = strategy.decode_ref(len_r);
                                DVLOG(2) << "decode special ref: " << cut;
                                while (cut > 0) {
                                    rebuilt_buffer.pop_back();
                                    --cut;
                                }
                            } else {
                                size_t prev_r = sub_ref;
                                size_t old_end = rebuilt_buffer.size();

                                // push the chars in reverse order
                                // to allow efficient appending of prefixes
                                do {
                                    View s = decomp.str_at(prev_r);
                                    prev_r = decomp.ref_at(prev_r);

                                    for (size_t j = 0; j < s.size(); j++) {
                                        rebuilt_buffer.push_back(s[s.size() - j - 1]);
                                    }
                                } while (prev_r != 0);
                                DCHECK_EQ(prev_r, 0);

                                // reverse suffix containing the new string fragment
                                std::reverse(rebuilt_buffer.begin() + old_end,
                                             rebuilt_buffer.end());
                            }
                        }

                        if (rebuilt_buffer.size() > 0 && rebuilt_buffer.back() == 0) {
                            rebuilt_buffer.pop_back();
                            break;
                        }
                    }
                    DVLOG(2) << "USED!";
                    DVLOG(2) << "  ...'"
                        << ((ref > 0) ? decomp.str_at(ref) : ""_v)
                        << "' '"
                        << rebuilt_buffer << "'";
                    decomp.decompress(ref, rebuilt_buffer, out);
                }

                /*
                std::cout << "in m (s,r): ("
                    << vec_to_debug_string(factor.string)
                    << ", " << int(factor.ref) << ")\n";
                */

                factor_count++;
            }
        }

        out << '\0';
        out.flush();
    }

};

}//ns
<|endoftext|>


<commit_before>#include "PortalGame.h"
#include "PhysicsController.h"
#include "Sphere.h"
#include "PhysicsCamera.h"
#include "Box.h"
#include "Cylinder.h"
#include "Steerable3DController.h"
#include "Ground.h"
#include "Content.h"
#include <btBulletDynamicsCommon.h>
#include <gtc/quaternion.hpp>
#include <gtx/quaternion.hpp>
#include <gtx/euler_angles.hpp>
#include <gtx/norm.hpp>
#include "VectorDrawer.h"

using namespace BGE;

PortalGame::PortalGame(void)
{
	physicsFactory = NULL;
	dynamicsWorld = NULL;
	broadphase = NULL;
	dispatcher = NULL;
	solver = NULL;
	fullscreen = false;
}

PortalGame::~PortalGame(void)
{
}

std::shared_ptr<GameComponent> station;
//float theta = 0.0f;

bool PortalGame::Initialise()
{
	riftEnabled = false;
	// Set up the collision configuration and dispatcher
    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);

    // The world.
	btVector3 worldMin(-1000,-1000,-1000);
	btVector3 worldMax(1000,1000,1000);
	broadphase = new btAxisSweep3(worldMin,worldMax);
	solver = new btSequentialImpulseConstraintSolver();
	dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
    dynamicsWorld->setGravity(btVector3(0,-9,0));

	width = 800;
	height = 600;

	physicsFactory = make_shared<PhysicsFactory>(dynamicsWorld);

	physicsFactory->CreateGroundPhysics();
	physicsFactory->CreateCameraPhysics();

	std::shared_ptr<GameComponent> box = make_shared<Box>(1, 1, 1);
	box->position = glm::vec3(0, 5, -20);
	Attach(box);

	//floating cyl (kinematic)
	//std::shared_ptr<GameComponent> cyl = make_shared<Cylinder>(2, 1);
	//cyl->position = glm::vec3(10, 0, -10);
	//Attach(cyl);

	//non kinematic cyl

	// Stands for Box Objects
	shared_ptr<PhysicsController> colCyl_01 = physicsFactory->CreateCylinder(0.5,5, glm::vec3(5, 0, 0), glm::quat());
	//colCyl_01->tag="colObject_01";
	shared_ptr<PhysicsController> colBox_01 = physicsFactory->CreateBox(1,1,1, glm::vec3(5, 7, 0), glm::quat());
	colBox_01->tag="colObject2";

	shared_ptr<PhysicsController> colCyl_02 = physicsFactory->CreateCylinder(0.5,8, glm::vec3(12, 0, 0), glm::quat());

	shared_ptr<PhysicsController> colBox_02 = physicsFactory->CreateBox(1,1,1, glm::vec3(12, 10, 0), glm::quat());
	colBox_02->tag="colObject2";

	shared_ptr<PhysicsController> colCyl_03 = physicsFactory->CreateCylinder(0.5,10, glm::vec3(18, 0, 0), glm::quat());
	shared_ptr<PhysicsController> colBox_03 = physicsFactory->CreateBox(1,1,1, glm::vec3(18, 12, 0), glm::quat());
	colBox_03->tag="colObject2";

	//box for collision
	/*shared_ptr<PhysicsController> colBox = physicsFactory->CreateBox(1,1,1, glm::vec3(5, 10, 0), glm::quat());
	colBox->tag="colObject2";
	*/

	// Ball to throw at Boxes
	shared_ptr<PhysicsController> colBall_01 = physicsFactory->CreateSphere(0.5,glm::vec3(5, 0, 10),glm::quat());
	colBall_01->tag="colObject1";

	//physicsFactory->CreateWall(glm::vec3(-20,0,20), 50, 10);

	 //Now some constraints
	/*shared_ptr<PhysicsController> box1 = physicsFactory->CreateBox(1,1,4, glm::vec3(5, 5, 0), glm::quat());
	shared_ptr<PhysicsController> box2 = physicsFactory->CreateBox(1,1,4, glm::vec3(5, 5, 5), glm::quat()); */
	//shared_ptr<PhysicsController> cap1 = physicsFactory->CreateCapsule(1,1, glm::vec3(5, 50, 5), glm::quat());
	//cap1->scale = glm::vec3(0.001,0.001,0.001);

	 //A hinge
	//btHingeConstraint * hinge = new btHingeConstraint(*box1->rigidBody, *box2->rigidBody, btVector3(0,0,2.5f),btVector3(0,0,-2.5f), btVector3(0,1,0), btVector3(0,1,0), true);
	//dynamicsWorld->addConstraint(hinge);

	//box1 = physicsFactory->CreateBox(1,1,4, glm::vec3(10, 5, 0), glm::quat());
	//box2 = physicsFactory->CreateBox(1,1,4, glm::vec3(10, 5, 5), glm::quat());
	//cap1 = physicsFactory->CreateCapsule(5,5, glm::vec3(5, 5, 5), glm::quat());

	//physicsFactory->CreateCylinder(10, 3, glm::vec3(0, 20, 0), glm::quat());

	///*std::shared_ptr<GameComponent> ship = make_shared<GameComponent>();
	//ship->ambient = glm::vec3(0.2f, 0.2, 0.2f);
	//ship->specular = glm::vec3(1.2f, 1.2f, 1.2f);
	//std::shared_ptr<Model> model = Content::LoadModel("cobramk3", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp));
	//std::shared_ptr<GameComponent> steerable = make_shared<Steerable3DController>(model);
	//steerable->position = glm::vec3(20, 5, -20);
	//std::shared_ptr<VectorDrawer> vectorDrawer = make_shared<VectorDrawer>();
	//vectorDrawer->scale = glm::vec3(5,5,10);
	//ship->Attach(steerable);
	//ship->Attach(model);
	//ship->Attach(vectorDrawer);
	//Attach(ship);*/

	//// Create a hierarchy
	//station = make_shared<GameComponent>();
	//station->worldMode = world_modes::from_self;
	//station->ambient = glm::vec3(0.2f, 0.2, 0.2f);
	//station->specular = glm::vec3(0,0,0);
	//station->scale = glm::vec3(2,2,2);
	//std::shared_ptr<Model> cmodel = Content::LoadModel("coriolis", glm::rotate(glm::mat4(1), 90.0f, GameComponent::basisUp));
	//station->Attach(cmodel);
	//station->Attach(make_shared<VectorDrawer>(glm::vec3(7,7,7)));
	//station->position = glm::vec3(40, 5, -20);
	//Attach(station);

	//// Add a child to the station and update by including the parent's world transform
	//std::shared_ptr<GameComponent> ship1 = make_shared<GameComponent>();
	//ship1->worldMode = world_modes::from_self_with_parent;
	//ship1->ambient = glm::vec3(0.2f, 0.2, 0.2f);
	//ship1->specular = glm::vec3(1.2f, 1.2f, 1.2f);
	//std::shared_ptr<Model> ana = Content::LoadModel("anaconda", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp));
	//ship1->Attach(ana);
	//ship1->position = glm::vec3(0, 0, -10);
	//station->Attach(ship1);

	//physicsFactory->CreateVehicle(glm::vec3(0,10,-30));

	// Create Inca Pyramid
	//position(), baseWidth, blockHeight, blockWidth, blockDepth
    //physicsFactory->CreateIncaPyramid(glm::vec3(20,0,-20), 6, 1.5, 1.5, 1.5);

	//Create Rag Doll
	//physicsFactory->CreateRagDoll(glm::vec3(25,0,-50));

	if (!Game::Initialise()) {
		return false;
	}

	camera->GetController()->position = glm::vec3(0,10, 0);

	return true;
}

void BGE::PortalGame::Update(float timeDelta)
{
	dynamicsWorld->stepSimulation(timeDelta,100);
	//station->Yaw(timeDelta * 20.0f);

	//collision detection check
	 int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
        for (int i=0;i<numManifolds;i++)
        {
                btPersistentManifold* contactManifold =  dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
                btCollisionObject* obA = (btCollisionObject*)(contactManifold->getBody0());
				btCollisionObject* obB = (btCollisionObject*)(contactManifold->getBody1());
				// btCollisionObject* obA = (btCollisionObject*)(contactManifold->colCyl = physicsFactory->CreateCylinder(2,1, glm::vec3(5, 0, -10), glm::quat()); );
				//btCollisionObject* obB = (btCollisionObject*)(contactManifold->colBox = physicsFactory->CreateBox(1,1,1, glm::vec3(5, 0, 0), glm::quat()); );
                PhysicsController * pcA = reinterpret_cast<PhysicsController*>(obA->getUserPointer());
                PhysicsController * pcB = reinterpret_cast<PhysicsController*>(obB->getUserPointer());

                int numContacts = contactManifold->getNumContacts();
                if (numContacts > 0)
                {
                        if ((pcA != nullptr) && (pcB != nullptr))
                        {
							//PrintText("Collision between " + pcA->tag + " and " + pcB->tag);
							if (pcA->tag == "colObject1" && pcB->tag == "colObject2")
                            {
								  PrintText("Collision between " + pcA->tag + " and " + pcB->tag);
							}
							/*if (pcB->tag == "colObject1" && pcA->tag == "colObject2")
                            {
								  PrintText("Collision between " + pcA->tag + " and " + pcB->tag);
							}*/
                        }
                }
        }

	Game::Update(timeDelta);

}

void BGE::PortalGame::Cleanup()
{
	Game::Cleanup();
}
<commit_msg>walls<commit_after>#include "PortalGame.h"
#include "PhysicsController.h"
#include "Sphere.h"
#include "PhysicsCamera.h"
#include "Box.h"
#include "Cylinder.h"
#include "Steerable3DController.h"
#include "Ground.h"
#include "Content.h"
#include <btBulletDynamicsCommon.h>
#include <gtc/quaternion.hpp>
#include <gtx/quaternion.hpp>
#include <gtx/euler_angles.hpp>
#include <gtx/norm.hpp>
#include "VectorDrawer.h"

using namespace BGE;

PortalGame::PortalGame(void)
{
	physicsFactory = NULL;
	dynamicsWorld = NULL;
	broadphase = NULL;
	dispatcher = NULL;
	solver = NULL;
	fullscreen = false;
}

PortalGame::~PortalGame(void)
{
}

std::shared_ptr<GameComponent> station;
//float theta = 0.0f;

bool PortalGame::Initialise()
{
	riftEnabled = false;
	// Set up the collision configuration and dispatcher
    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);

    // The world.
	btVector3 worldMin(-1000,-1000,-1000);
	btVector3 worldMax(1000,1000,1000);
	broadphase = new btAxisSweep3(worldMin,worldMax);
	solver = new btSequentialImpulseConstraintSolver();
	dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
    dynamicsWorld->setGravity(btVector3(0,-9,0));

	width = 800;
	height = 600;

	physicsFactory = make_shared<PhysicsFactory>(dynamicsWorld);

	physicsFactory->CreateGroundPhysics();
	physicsFactory->CreateCameraPhysics();

	//std::shared_ptr<GameComponent> box = make_shared<Box>(1, 1, 1);
	//box->position = glm::vec3(0, 5, -20);
	//Attach(box);

	//non kinematic cyl
	shared_ptr<PhysicsController> colCyl = physicsFactory->CreateCylinder(2,1, glm::vec3(5, 0, -10), glm::quat());

	colCyl->tag="colObject1";

	//box for collision
	shared_ptr<PhysicsController> colBox = physicsFactory->CreateBox(1,1,1, glm::vec3(5, 0, 0), glm::quat());
	colBox->tag="colObject2";

	//create walls for games
	//left wall for box 1
	shared_ptr<PhysicsController> leftWall1 = physicsFactory->CreateBox(0.5,10,15, glm::vec3(-10, 0, -20), glm::quat());
	leftWall1->diffuse = glm::vec3(1,0,1);
	//leftWall1

	//right wall for box 1
	shared_ptr<PhysicsController> rightWall1 = physicsFactory->CreateBox(0.5,10,15, glm::vec3(-2, 0, -20), glm::quat());
	rightWall1->diffuse = glm::vec3(1,0,1);

	//top wall for box 1
	shared_ptr<PhysicsController> topWall1 = physicsFactory->CreateBox(15,0.5,15, glm::vec3(-4, 0, -20), glm::quat());
	topWall1->diffuse = glm::vec3(1,0,1);

	//physicsFactory->CreateWall(glm::vec3(-20,0,20), 50, 10);

	 //Now some constraints
	/*shared_ptr<PhysicsController> box1 = physicsFactory->CreateBox(1,1,4, glm::vec3(5, 5, 0), glm::quat());
	shared_ptr<PhysicsController> box2 = physicsFactory->CreateBox(1,1,4, glm::vec3(5, 5, 5), glm::quat()); */
	//shared_ptr<PhysicsController> cap1 = physicsFactory->CreateCapsule(1,1, glm::vec3(5, 50, 5), glm::quat());
	//cap1->scale = glm::vec3(0.001,0.001,0.001);

	 //A hinge
	//btHingeConstraint * hinge = new btHingeConstraint(*box1->rigidBody, *box2->rigidBody, btVector3(0,0,2.5f),btVector3(0,0,-2.5f), btVector3(0,1,0), btVector3(0,1,0), true);
	//dynamicsWorld->addConstraint(hinge);

	//box1 = physicsFactory->CreateBox(1,1,4, glm::vec3(10, 5, 0), glm::quat());
	//box2 = physicsFactory->CreateBox(1,1,4, glm::vec3(10, 5, 5), glm::quat());
	//cap1 = physicsFactory->CreateCapsule(5,5, glm::vec3(5, 5, 5), glm::quat());

	//physicsFactory->CreateCylinder(10, 3, glm::vec3(0, 20, 0), glm::quat());

	///*std::shared_ptr<GameComponent> ship = make_shared<GameComponent>();
	//ship->ambient = glm::vec3(0.2f, 0.2, 0.2f);
	//ship->specular = glm::vec3(1.2f, 1.2f, 1.2f);
	//std::shared_ptr<Model> model = Content::LoadModel("cobramk3", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp));
	//std::shared_ptr<GameComponent> steerable = make_shared<Steerable3DController>(model);
	//steerable->position = glm::vec3(20, 5, -20);
	//std::shared_ptr<VectorDrawer> vectorDrawer = make_shared<VectorDrawer>();
	//vectorDrawer->scale = glm::vec3(5,5,10);
	//ship->Attach(steerable);
	//ship->Attach(model);
	//ship->Attach(vectorDrawer);
	//Attach(ship);*/

	//// Create a hierarchy
	//station = make_shared<GameComponent>();
	//station->worldMode = world_modes::from_self;
	//station->ambient = glm::vec3(0.2f, 0.2, 0.2f);
	//station->specular = glm::vec3(0,0,0);
	//station->scale = glm::vec3(2,2,2);
	//std::shared_ptr<Model> cmodel = Content::LoadModel("coriolis", glm::rotate(glm::mat4(1), 90.0f, GameComponent::basisUp));
	//station->Attach(cmodel);
	//station->Attach(make_shared<VectorDrawer>(glm::vec3(7,7,7)));
	//station->position = glm::vec3(40, 5, -20);
	//Attach(station);

	//// Add a child to the station and update by including the parent's world transform
	//std::shared_ptr<GameComponent> ship1 = make_shared<GameComponent>();
	//ship1->worldMode = world_modes::from_self_with_parent;
	//ship1->ambient = glm::vec3(0.2f, 0.2, 0.2f);
	//ship1->specular = glm::vec3(1.2f, 1.2f, 1.2f);
	//std::shared_ptr<Model> ana = Content::LoadModel("anaconda", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp));
	//ship1->Attach(ana);
	//ship1->position = glm::vec3(0, 0, -10);
	//station->Attach(ship1);

	//physicsFactory->CreateVehicle(glm::vec3(0,10,-30));

	// Create Inca Pyramid
	//position(), baseWidth, blockHeight, blockWidth, blockDepth
    //physicsFactory->CreateIncaPyramid(glm::vec3(20,0,-20), 6, 1.5, 1.5, 1.5);

	//Create Rag Doll
	//physicsFactory->CreateRagDoll(glm::vec3(25,0,-50));

	if (!Game::Initialise()) {
		return false;
	}

	camera->GetController()->position = glm::vec3(0,10, 0);

	return true;
}

void BGE::PortalGame::Update(float timeDelta)
{
	dynamicsWorld->stepSimulation(timeDelta,100);
	//station->Yaw(timeDelta * 20.0f);

	//collision detection check
	 int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
        for (int i=0;i<numManifolds;i++)
        {
                btPersistentManifold* contactManifold =  dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
                btCollisionObject* obA = (btCollisionObject*)(contactManifold->getBody0());
				btCollisionObject* obB = (btCollisionObject*)(contactManifold->getBody1());
				// btCollisionObject* obA = (btCollisionObject*)(contactManifold->colCyl = physicsFactory->CreateCylinder(2,1, glm::vec3(5, 0, -10), glm::quat()); );
				//btCollisionObject* obB = (btCollisionObject*)(contactManifold->colBox = physicsFactory->CreateBox(1,1,1, glm::vec3(5, 0, 0), glm::quat()); );
                PhysicsController * pcA = reinterpret_cast<PhysicsController*>(obA->getUserPointer());
                PhysicsController * pcB = reinterpret_cast<PhysicsController*>(obB->getUserPointer());

                int numContacts = contactManifold->getNumContacts();
                if (numContacts > 0)
                {
                        if ((pcA != nullptr) && (pcB != nullptr))
                        {
							//PrintText("Collision between " + pcA->tag + " and " + pcB->tag);
							if (pcA->tag == "colObject1" && pcB->tag == "colObject2")
                            {
								  PrintText("Collision between " + pcA->tag + " and " + pcB->tag);
							}
							/*if (pcB->tag == "colObject1" && pcA->tag == "colObject2")
                            {
								  PrintText("Collision between " + pcA->tag + " and " + pcB->tag);
							}*/
                        }
                }
        }

	Game::Update(timeDelta);

}

void BGE::PortalGame::Cleanup()
{
	Game::Cleanup();
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: OOo2Oasis.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2004-11-09 12:23:19 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _XMLOFF_OOO2OASIS_HXX
#define _XMLOFF_OOO2OASIS_HXX

#ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
#include <com/sun/star/document/XImporter.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
#include <com/sun/star/document/XFilter.hpp>
#endif

#ifndef _XMLOFF_ACTIONMAPTYPESOOO_HXX
#include "ActionMapTypesOOo.hxx"
#endif
#ifndef _XMLOFF_TRANSFORMERBASE_HXX_
#include "TransformerBase.hxx"
#endif

class XMLTransformerOOoEventMap_Impl;

class OOo2OasisTransformer :
        public XMLTransformerBase,
        public ::com::sun::star::document::XImporter,
        public ::com::sun::star::document::XFilter
{
    ::rtl::OUString m_aImplName;
    ::rtl::OUString m_aSubServiceName;

    XMLTransformerActions       *m_aActions[MAX_OOO_ACTIONS];
    XMLTransformerOOoEventMap_Impl *m_pEventMap;

protected:

    virtual XMLTransformerContext *CreateUserDefinedContext(
                                      const TransformerAction_Impl& rAction,
                                      const ::rtl::OUString& rQName,
                                         sal_Bool bPersistent=sal_False );

    virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );

public:
    OOo2OasisTransformer( const sal_Char *pImplName=0,
                          const sal_Char *pSubServiceName=0 ) throw();
    virtual ~OOo2OasisTransformer() throw();

    static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
    static OOo2OasisTransformer * getImplementation( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ) throw();

    // XInterface

    // (XInterface methods need to be implemented to disambigouate
    // between those inherited through XMLTransformerBase and
    // the new interfaces).

    virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
        const ::com::sun::star::uno::Type& aType )
        throw (::com::sun::star::uno::RuntimeException);

    virtual void SAL_CALL acquire(  ) throw ()
        { XMLTransformerBase::acquire(); };

    virtual void SAL_CALL release(  ) throw ()
        { XMLTransformerBase::release(); };

    // XInitialization
    virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // XServiceInfo
    virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);

    // XTypeProvider
    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);

    // XUnoTunnel
    virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);

    // XImporter
    virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);

    // XFilter
    virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL cancel(  ) throw (::com::sun::star::uno::RuntimeException);

    void SAL_CALL Initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // ::com::sun::star::xml::sax::XDocumentHandler
    virtual void SAL_CALL startDocument(void)
        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );

    virtual ::rtl::OUString GetEventName( const ::rtl::OUString& rName,
                                            sal_Bool bForm = sal_False );
};

#endif  //  _XMLOFF_TRANSFORMER_BASE_HXX
<commit_msg>INTEGRATION: CWS impress17 (1.2.88); FILE MERGED 2004/10/29 11:43:07 cl 1.2.88.1: #i13778# convert wrong twips measures for connectors in writer documents<commit_after>/*************************************************************************
 *
 *  $RCSfile: OOo2Oasis.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: obo $ $Date: 2004-11-17 10:37:55 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _XMLOFF_OOO2OASIS_HXX
#define _XMLOFF_OOO2OASIS_HXX

#ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
#include <com/sun/star/document/XImporter.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
#include <com/sun/star/document/XFilter.hpp>
#endif

#ifndef _XMLOFF_ACTIONMAPTYPESOOO_HXX
#include "ActionMapTypesOOo.hxx"
#endif
#ifndef _XMLOFF_TRANSFORMERBASE_HXX_
#include "TransformerBase.hxx"
#endif

class XMLTransformerOOoEventMap_Impl;

class OOo2OasisTransformer :
        public XMLTransformerBase,
        public ::com::sun::star::document::XImporter,
        public ::com::sun::star::document::XFilter
{
    ::rtl::OUString m_aImplName;
    ::rtl::OUString m_aSubServiceName;

    XMLTransformerActions       *m_aActions[MAX_OOO_ACTIONS];
    XMLTransformerOOoEventMap_Impl *m_pEventMap;
protected:

    virtual XMLTransformerContext *CreateUserDefinedContext(
                                      const TransformerAction_Impl& rAction,
                                      const ::rtl::OUString& rQName,
                                         sal_Bool bPersistent=sal_False );

    virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );

public:
    OOo2OasisTransformer( const sal_Char *pImplName=0,
                          const sal_Char *pSubServiceName=0 ) throw();
    virtual ~OOo2OasisTransformer() throw();

    static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
    static OOo2OasisTransformer * getImplementation( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ) throw();

    // XInterface

    // (XInterface methods need to be implemented to disambigouate
    // between those inherited through XMLTransformerBase and
    // the new interfaces).

    virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
        const ::com::sun::star::uno::Type& aType )
        throw (::com::sun::star::uno::RuntimeException);

    virtual void SAL_CALL acquire(  ) throw ()
        { XMLTransformerBase::acquire(); };

    virtual void SAL_CALL release(  ) throw ()
        { XMLTransformerBase::release(); };

    // XInitialization
    virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // XServiceInfo
    virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);

    // XTypeProvider
    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);

    // XUnoTunnel
    virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);

    // XImporter
    virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);

    // XFilter
    virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL cancel(  ) throw (::com::sun::star::uno::RuntimeException);

    void SAL_CALL Initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // ::com::sun::star::xml::sax::XDocumentHandler
    virtual void SAL_CALL startDocument(void)
        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );

    virtual ::rtl::OUString GetEventName( const ::rtl::OUString& rName,
                                            sal_Bool bForm = sal_False );
};

#endif  //  _XMLOFF_TRANSFORMER_BASE_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sourcecontext.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-20 06:02:56 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _COM_SUN_STAR_DATATRANSFER_DND_DNDCONSTANTS_HPP_
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#endif

#include "sourcecontext.hxx"

#ifndef _RTL_UNLOAD_H_
#include <rtl/unload.h>
#endif

using namespace com::sun::star::datatransfer::dnd;
using namespace com::sun::star::datatransfer::dnd::DNDConstants;
extern rtl_StandardModuleCount g_moduleCount;

SourceContext::SourceContext( DragSource* pSource,
                             const Reference<XDragSourceListener>& listener):
        WeakComponentImplHelper1<XDragSourceContext>(m_mutex),
        m_pDragSource( pSource),
        m_dragSource( static_cast<XDragSource*>( m_pDragSource) )
{
    g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
#if OSL_DEBUG_LEVEL > 1
    if( listener.is())
#endif
    rBHelper.addListener( ::getCppuType( &listener ), listener );
}

SourceContext::~SourceContext()
{
    g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
}

void SAL_CALL SourceContext::addDragSourceListener(
    const Reference<XDragSourceListener >& )
    throw( RuntimeException)
{
}

void SAL_CALL SourceContext::removeDragSourceListener(
     const Reference<XDragSourceListener >& )
    throw( RuntimeException)
{
}

sal_Int32 SAL_CALL SourceContext::getCurrentCursor(  )
    throw( RuntimeException)
{
    return 0;
}

void SAL_CALL SourceContext::setCursor( sal_Int32 /*cursorId*/ )
    throw( IllegalArgumentException, RuntimeException)
{
}

void SAL_CALL SourceContext::setImage( sal_Int32 /*imageId*/ )
    throw( IllegalArgumentException, RuntimeException)
{
}

void SAL_CALL SourceContext::transferablesFlavorsChanged(  )
    throw( RuntimeException)
{
}

// non -interface functions
// Fires XDragSourceListener::dragDropEnd events.
void SourceContext::fire_dragDropEnd( sal_Bool success, sal_Int8 effect)
{

    DragSourceDropEvent e;

    if( success == sal_True)
    {
        e.DropAction=  effect;
        e.DropSuccess= sal_True;
    }
    else
    {
        e.DropAction= ACTION_NONE;
        e.DropSuccess= sal_False;
    }
    e.DragSource= m_dragSource;
    e.DragSourceContext= static_cast<XDragSourceContext*>( this);
    e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);

    OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
        getCppuType( (Reference<XDragSourceListener>* )0 ) );

    if( pContainer)
    {
        OInterfaceIteratorHelper iter( *pContainer);
        while( iter.hasMoreElements())
        {
            Reference<XDragSourceListener> listener(
                static_cast<XDragSourceListener*>( iter.next()));
            listener->dragDropEnd( e);
        }
    }
}

void SourceContext::fire_dropActionChanged( sal_Int8 dropAction, sal_Int8 userAction)
{
    if( m_currentAction != dropAction)
    {
        m_currentAction= dropAction;
        DragSourceDragEvent e;
        e.DropAction= dropAction;
        e.UserAction= userAction;
        e.DragSource= m_dragSource;
        e.DragSourceContext= static_cast<XDragSourceContext*>( this);
        e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);

        OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
            getCppuType( (Reference<XDragSourceListener>* )0 ) );

        if( pContainer)
        {
            OInterfaceIteratorHelper iter( *pContainer);
            while( iter.hasMoreElements())
            {
                Reference<XDragSourceListener> listener(
                    static_cast<XDragSourceListener*>( iter.next()));
                listener->dropActionChanged( e);
            }
        }
    }
}
<commit_msg>INTEGRATION: CWS pchfix02 (1.7.14); FILE MERGED 2006/09/01 17:25:37 kaib 1.7.14.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sourcecontext.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 16:58:49 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dtrans.hxx"

#ifndef _COM_SUN_STAR_DATATRANSFER_DND_DNDCONSTANTS_HPP_
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#endif

#include "sourcecontext.hxx"

#ifndef _RTL_UNLOAD_H_
#include <rtl/unload.h>
#endif

using namespace com::sun::star::datatransfer::dnd;
using namespace com::sun::star::datatransfer::dnd::DNDConstants;
extern rtl_StandardModuleCount g_moduleCount;

SourceContext::SourceContext( DragSource* pSource,
                             const Reference<XDragSourceListener>& listener):
        WeakComponentImplHelper1<XDragSourceContext>(m_mutex),
        m_pDragSource( pSource),
        m_dragSource( static_cast<XDragSource*>( m_pDragSource) )
{
    g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
#if OSL_DEBUG_LEVEL > 1
    if( listener.is())
#endif
    rBHelper.addListener( ::getCppuType( &listener ), listener );
}

SourceContext::~SourceContext()
{
    g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
}

void SAL_CALL SourceContext::addDragSourceListener(
    const Reference<XDragSourceListener >& )
    throw( RuntimeException)
{
}

void SAL_CALL SourceContext::removeDragSourceListener(
     const Reference<XDragSourceListener >& )
    throw( RuntimeException)
{
}

sal_Int32 SAL_CALL SourceContext::getCurrentCursor(  )
    throw( RuntimeException)
{
    return 0;
}

void SAL_CALL SourceContext::setCursor( sal_Int32 /*cursorId*/ )
    throw( IllegalArgumentException, RuntimeException)
{
}

void SAL_CALL SourceContext::setImage( sal_Int32 /*imageId*/ )
    throw( IllegalArgumentException, RuntimeException)
{
}

void SAL_CALL SourceContext::transferablesFlavorsChanged(  )
    throw( RuntimeException)
{
}

// non -interface functions
// Fires XDragSourceListener::dragDropEnd events.
void SourceContext::fire_dragDropEnd( sal_Bool success, sal_Int8 effect)
{

    DragSourceDropEvent e;

    if( success == sal_True)
    {
        e.DropAction=  effect;
        e.DropSuccess= sal_True;
    }
    else
    {
        e.DropAction= ACTION_NONE;
        e.DropSuccess= sal_False;
    }
    e.DragSource= m_dragSource;
    e.DragSourceContext= static_cast<XDragSourceContext*>( this);
    e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);

    OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
        getCppuType( (Reference<XDragSourceListener>* )0 ) );

    if( pContainer)
    {
        OInterfaceIteratorHelper iter( *pContainer);
        while( iter.hasMoreElements())
        {
            Reference<XDragSourceListener> listener(
                static_cast<XDragSourceListener*>( iter.next()));
            listener->dragDropEnd( e);
        }
    }
}

void SourceContext::fire_dropActionChanged( sal_Int8 dropAction, sal_Int8 userAction)
{
    if( m_currentAction != dropAction)
    {
        m_currentAction= dropAction;
        DragSourceDragEvent e;
        e.DropAction= dropAction;
        e.UserAction= userAction;
        e.DragSource= m_dragSource;
        e.DragSourceContext= static_cast<XDragSourceContext*>( this);
        e.Source= Reference<XInterface>( static_cast<XDragSourceContext*>( this), UNO_QUERY);

        OInterfaceContainerHelper* pContainer= rBHelper.getContainer(
            getCppuType( (Reference<XDragSourceListener>* )0 ) );

        if( pContainer)
        {
            OInterfaceIteratorHelper iter( *pContainer);
            while( iter.hasMoreElements())
            {
                Reference<XDragSourceListener> listener(
                    static_cast<XDragSourceListener*>( iter.next()));
                listener->dropActionChanged( e);
            }
        }
    }
}
<|endoftext|>


<commit_before>/*
   For more information, please see: http://software.sci.utah.edu

   The MIT License

   Copyright (c) 2008 Scientific Computing and Imaging Institute,
   University of Utah.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE.
*/

/**
  \file    ArcBall.cpp
  \author  Jens Krueger
           SCI Institute
           University of Utah
           Based on the NeHe Tutorial 48
  \date    October 2008
*/

#include "ArcBall.h"

float ArcBall::ms_fEpsilon = 1.0e-5f;

ArcBall::ArcBall(UINT32 iWinWidth, UINT32 iWinHeight, int iWinOffsetX, int iWinOffsetY) :
    m_vStartDrag(),
    m_iWinDim(iWinWidth, iWinHeight),
    m_iWinOffsets(iWinOffsetX, iWinOffsetY),
    m_fRadius(1.0f)
{
}

void ArcBall::SetWindowSize(UINT32 iWinWidth, UINT32 iWinHeight) {
    m_iWinDim = UINTVECTOR2(iWinWidth, iWinHeight);
}

void ArcBall::SetWindowOffset(int iWinOffsetX, int iWinOffsetY) {
  m_iWinOffsets = INTVECTOR2(iWinOffsetX, iWinOffsetY);
}

void ArcBall::Click(UINTVECTOR2 vPosition) {
  m_vStartDrag = MapToSphere(vPosition);
}

FLOATQUATERNION4 ArcBall::Drag(UINTVECTOR2 vPosition) {
  FLOATQUATERNION4 qRotation;

  // Map the point to the sphere
  FLOATVECTOR3 vCurrent = MapToSphere(vPosition);

  // Compute the vector perpendicular to the begin and end vectors
  FLOATVECTOR3 vCross(vCurrent % m_vStartDrag);
  float        fDot(vCurrent ^ m_vStartDrag);

  if (vCross.length() > ms_fEpsilon)    //if its non-zero
      return FLOATQUATERNION4(vCross.x, vCross.y, vCross.z, fDot);
  else
      return FLOATQUATERNION4(0,0,0,0);
}

FLOATVECTOR3 ArcBall::MapToSphere(UINTVECTOR2 vPosition) const {
  FLOATVECTOR3 vResult;

  // normalize position to [-1 ... 1]
  FLOATVECTOR2 vNormPosition;
  vNormPosition.x =  -(((vPosition.x-m_iWinOffsets.x) / (float(m_iWinDim.x - 1) / 2.0f)) - 1.0f);
  vNormPosition.y =  ((vPosition.y-m_iWinOffsets.y) / (float(m_iWinDim.y - 1) / 2.0f)) - 1.0f;

  // Compute the length of the vector to the point from the center
  float length = vNormPosition.length();

  // If the point is mapped outside of the sphere... (length > radius)
  if (length > m_fRadius) {
      // Compute a normalizing factor (radius / length)
      float norm = float(m_fRadius / length);

      // Return the "normalized" vector, a point on the sphere
      vResult.x = vNormPosition.x * norm;
      vResult.y = vNormPosition.y * norm;
      vResult.z = 0.0f;
  } else    // Else it's on the inside
  {
      // Return a vector to a point mapped inside the sphere
      vResult.x = vNormPosition.x;
      vResult.y = vNormPosition.y;
      vResult.z = length-m_fRadius;
  }

  vResult = vResult * m_mTranslation;

  return vResult;
}
<commit_msg>Remove EOL whitespace.<commit_after>/*
   For more information, please see: http://software.sci.utah.edu

   The MIT License

   Copyright (c) 2008 Scientific Computing and Imaging Institute,
   University of Utah.

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE.
*/

/**
  \file    ArcBall.cpp
  \author  Jens Krueger
           SCI Institute
           University of Utah
           Based on the NeHe Tutorial 48
  \date    October 2008
*/

#include "ArcBall.h"

float ArcBall::ms_fEpsilon = 1.0e-5f;

ArcBall::ArcBall(UINT32 iWinWidth, UINT32 iWinHeight, int iWinOffsetX, int iWinOffsetY) :
    m_vStartDrag(),
    m_iWinDim(iWinWidth, iWinHeight),
    m_iWinOffsets(iWinOffsetX, iWinOffsetY),
    m_fRadius(1.0f)
{
}

void ArcBall::SetWindowSize(UINT32 iWinWidth, UINT32 iWinHeight) {
    m_iWinDim = UINTVECTOR2(iWinWidth, iWinHeight);
}

void ArcBall::SetWindowOffset(int iWinOffsetX, int iWinOffsetY) {
  m_iWinOffsets = INTVECTOR2(iWinOffsetX, iWinOffsetY);
}

void ArcBall::Click(UINTVECTOR2 vPosition) {
  m_vStartDrag = MapToSphere(vPosition);
}

FLOATQUATERNION4 ArcBall::Drag(UINTVECTOR2 vPosition) {
  FLOATQUATERNION4 qRotation;

  // Map the point to the sphere
  FLOATVECTOR3 vCurrent = MapToSphere(vPosition);

  // Compute the vector perpendicular to the begin and end vectors
  FLOATVECTOR3 vCross(vCurrent % m_vStartDrag);
  float        fDot(vCurrent ^ m_vStartDrag);

  if (vCross.length() > ms_fEpsilon)    //if its non-zero
      return FLOATQUATERNION4(vCross.x, vCross.y, vCross.z, fDot);
  else
      return FLOATQUATERNION4(0,0,0,0);
}

FLOATVECTOR3 ArcBall::MapToSphere(UINTVECTOR2 vPosition) const {
  FLOATVECTOR3 vResult;

  // normalize position to [-1 ... 1]
  FLOATVECTOR2 vNormPosition;
  vNormPosition.x =  -(((vPosition.x-m_iWinOffsets.x) / (float(m_iWinDim.x - 1) / 2.0f)) - 1.0f);
  vNormPosition.y =  ((vPosition.y-m_iWinOffsets.y) / (float(m_iWinDim.y - 1) / 2.0f)) - 1.0f;

  // Compute the length of the vector to the point from the center
  float length = vNormPosition.length();

  // If the point is mapped outside of the sphere... (length > radius)
  if (length > m_fRadius) {
      // Compute a normalizing factor (radius / length)
      float norm = float(m_fRadius / length);

      // Return the "normalized" vector, a point on the sphere
      vResult.x = vNormPosition.x * norm;
      vResult.y = vNormPosition.y * norm;
      vResult.z = 0.0f;
  } else    // Else it's on the inside
  {
      // Return a vector to a point mapped inside the sphere
      vResult.x = vNormPosition.x;
      vResult.y = vNormPosition.y;
      vResult.z = length-m_fRadius;
  }

  vResult = vResult * m_mTranslation;

  return vResult;
}
<|endoftext|>


<commit_before>/* Copyright (c) 2007-2012, Eddie Kohler
 * Copyright (c) 2007, Regents of the University of California
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Tamer LICENSE file. These conditions include: you must
 * preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Tamer LICENSE file; the license in that file is
 * legally binding.
 */
#include "config.h"
#include <tamer/tamer.hh>
#include <tamer/adapter.hh>
#include <stdio.h>

namespace tamer {
namespace tamerpriv {

abstract_rendezvous *abstract_rendezvous::unblocked = 0;
abstract_rendezvous **abstract_rendezvous::unblocked_ptail = &unblocked;

void abstract_rendezvous::hard_free() {
    if (unblocked_next_ != unblocked_sentinel()) {
	abstract_rendezvous **p = &unblocked;
	while (*p != this)
	    p = &(*p)->unblocked_next_;
	if (!(*p = unblocked_next_))
	    unblocked_ptail = p;
    }
    _blocked_closure->tamer_block_position_ = 1;
    _blocked_closure->tamer_activator_(_blocked_closure);
}

tamer_closure *abstract_rendezvous::linked_closure() const {
    if (rtype_ == rgather) {
	const gather_rendezvous *gr = static_cast<const gather_rendezvous *>(this);
	return gr->linked_closure_;
    } else
	return _blocked_closure;
}

void simple_event::simple_trigger(simple_event *x, bool values) TAMER_NOEXCEPT {
    if (!x)
	return;
    simple_event *to_delete = 0;

 retry:
    abstract_rendezvous *r = x->_r;

    if (r) {
	// See also trigger_list_for_remove(), trigger_for_unuse().
	x->_r = 0;
	*x->_r_pprev = x->_r_next;
	if (x->_r_next)
	    x->_r_next->_r_pprev = x->_r_pprev;

	if (r->rtype_ == rgather) {
	    if (!r->waiting_)
		r->unblock();
	} else if (r->rtype_ == rexplicit) {
	    explicit_rendezvous *er = static_cast<explicit_rendezvous *>(r);
	    simple_event::use(x);
	    *er->ready_ptail_ = x;
	    er->ready_ptail_ = &x->_r_next;
	    x->_r_next = 0;
	    er->unblock();
	} else {
	    // rfunctional || rdistribute
	    functional_rendezvous *fr = static_cast<functional_rendezvous *>(r);
	    fr->f_(fr, x, values);
	}
    }

    // Important to keep an event in memory until all its at_triggers are
    // triggered -- some functional rendezvous, like with_helper_rendezvous,
    // depend on this property -- so don't delete just yet.
    if (--x->_refcount == 0) {
	x->_r_next = to_delete;
	to_delete = x;
    }

    if (r && x->at_trigger_) {
	if (x->at_trigger_f_)
	    x->at_trigger_f_(x->at_trigger_, x->at_trigger_arg2_);
	else {
	    x = static_cast<simple_event *>(x->at_trigger_);
	    values = false;
	    goto retry;
	}
    }

    while ((x = to_delete)) {
	to_delete = x->_r_next;
	delete x;
    }
}

void simple_event::trigger_list_for_remove() TAMER_NOEXCEPT {
    // first, remove all the events (in case an at_trigger() is also waiting
    // on this rendezvous)
    for (simple_event *e = this; e; e = e->_r_next)
	e->_r = 0;
    // then call any left-behind at_triggers
    for (simple_event *e = this; e; e = e->_r_next)
	if (e->at_trigger_ && e->at_trigger_f_)
	    e->at_trigger_f_(e->at_trigger_, e->at_trigger_arg2_);
	else {
	    simple_event *t = static_cast<simple_event *>(e->at_trigger_);
	    t->simple_trigger(false);
	}
}

void simple_event::trigger_for_unuse() TAMER_NOEXCEPT {
#if TAMER_DEBUG
    assert(_r && _refcount == 0);
#endif
    message::event_prematurely_dereferenced(this, _r);
    _refcount = 2;		// to prevent a recursive call to unuse
    simple_trigger(false);
    _refcount = 0;		// restore old _refcount
}

simple_event *simple_event::at_trigger_event() {
    if (!at_trigger_f_)
	return static_cast<simple_event *>(at_trigger_);
    else
	return tamer::fun_event(at_trigger_f_, at_trigger_,
				at_trigger_arg2_).__take_simple();
}

void simple_event::hard_at_trigger(simple_event *x, simple_event *at_e) {
    if (!at_e || !*at_e)
	/* ignore */;
    else if (!x || !*x)
	at_e->simple_trigger(false);
    else {
	x->at_trigger_ =
	    tamer::distribute(event<>::__make(x->at_trigger_event()),
			      event<>::__make(at_e))
	    .__take_simple();
	x->at_trigger_f_ = 0;
    }
}

void simple_event::hard_at_trigger(simple_event *x, void (*f)(void *, int),
				   void *arg1, int arg2) {
    if (!x || !*x)
	f(arg1, arg2);
    else {
	simple_event *n = tamer::fun_event(f, arg1, arg2).__take_simple();
	x->at_trigger_ =
	    tamer::distribute(event<>::__make(x->at_trigger_event()),
			      event<>::__make(n))
	    .__take_simple();
	x->at_trigger_f_ = 0;
    }
}

namespace message {

void event_prematurely_dereferenced(simple_event *, abstract_rendezvous *r) {
    tamer_closure *c = r->linked_closure();
    if (r->is_volatile())
	/* no error message */;
    else if (c && int(c->tamer_block_position_) < 0) {
	tamer_debug_closure *dc = static_cast<tamer_debug_closure *>(c);
	fprintf(stderr, "%s:%d: avoided leak of active event\n",
		dc->tamer_blocked_file_, dc->tamer_blocked_line_);
    } else
	fprintf(stderr, "avoided leak of active event\n");
}

} // namespace tamer::tamerpriv::message
} // namespace tamer::tamerpriv

void rendezvous<uintptr_t>::clear()
{
    abstract_rendezvous::remove_waiting();
    explicit_rendezvous::remove_ready();
}

void rendezvous<>::clear()
{
    abstract_rendezvous::remove_waiting();
    explicit_rendezvous::remove_ready();
}

void gather_rendezvous::clear()
{
    abstract_rendezvous::remove_waiting();
}

} // namespace tamer
<commit_msg>Internal: Don't call NULL->method, and clarity.<commit_after>/* Copyright (c) 2007-2012, Eddie Kohler
 * Copyright (c) 2007, Regents of the University of California
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Tamer LICENSE file. These conditions include: you must
 * preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Tamer LICENSE file; the license in that file is
 * legally binding.
 */
#include "config.h"
#include <tamer/tamer.hh>
#include <tamer/adapter.hh>
#include <stdio.h>

namespace tamer {
namespace tamerpriv {

abstract_rendezvous *abstract_rendezvous::unblocked = 0;
abstract_rendezvous **abstract_rendezvous::unblocked_ptail = &unblocked;

void abstract_rendezvous::hard_free() {
    if (unblocked_next_ != unblocked_sentinel()) {
	abstract_rendezvous **p = &unblocked;
	while (*p != this)
	    p = &(*p)->unblocked_next_;
	if (!(*p = unblocked_next_))
	    unblocked_ptail = p;
    }
    _blocked_closure->tamer_block_position_ = 1;
    _blocked_closure->tamer_activator_(_blocked_closure);
}

tamer_closure *abstract_rendezvous::linked_closure() const {
    if (rtype_ == rgather) {
	const gather_rendezvous *gr = static_cast<const gather_rendezvous *>(this);
	return gr->linked_closure_;
    } else
	return _blocked_closure;
}

void simple_event::simple_trigger(simple_event *x, bool values) TAMER_NOEXCEPT {
    if (!x)
	return;
    simple_event *to_delete = 0;

 retry:
    abstract_rendezvous *r = x->_r;

    if (r) {
	// See also trigger_list_for_remove(), trigger_for_unuse().
	x->_r = 0;
	*x->_r_pprev = x->_r_next;
	if (x->_r_next)
	    x->_r_next->_r_pprev = x->_r_pprev;

	if (r->rtype_ == rgather) {
	    if (!r->waiting_)
		r->unblock();
	} else if (r->rtype_ == rexplicit) {
	    explicit_rendezvous *er = static_cast<explicit_rendezvous *>(r);
	    simple_event::use(x);
	    *er->ready_ptail_ = x;
	    er->ready_ptail_ = &x->_r_next;
	    x->_r_next = 0;
	    er->unblock();
	} else {
	    // rfunctional || rdistribute
	    functional_rendezvous *fr = static_cast<functional_rendezvous *>(r);
	    fr->f_(fr, x, values);
	}
    }

    // Important to keep an event in memory until all its at_triggers are
    // triggered -- some functional rendezvous, like with_helper_rendezvous,
    // depend on this property -- so don't delete just yet.
    if (--x->_refcount == 0) {
	x->_r_next = to_delete;
	to_delete = x;
    }

    if (r && x->at_trigger_) {
	if (x->at_trigger_f_)
	    x->at_trigger_f_(x->at_trigger_, x->at_trigger_arg2_);
	else {
	    x = static_cast<simple_event *>(x->at_trigger_);
	    values = false;
	    goto retry;
	}
    }

    while ((x = to_delete)) {
	to_delete = x->_r_next;
	delete x;
    }
}

void simple_event::trigger_list_for_remove() TAMER_NOEXCEPT {
    // first, remove all the events (in case an at_trigger() is also waiting
    // on this rendezvous)
    for (simple_event *e = this; e; e = e->_r_next)
	e->_r = 0;
    // then call any left-behind at_triggers
    for (simple_event *e = this; e; e = e->_r_next)
	if (e->at_trigger_ && e->at_trigger_f_)
	    e->at_trigger_f_(e->at_trigger_, e->at_trigger_arg2_);
	else if (e->at_trigger_) {
	    simple_event *t = static_cast<simple_event *>(e->at_trigger_);
	    t->simple_trigger(false);
	}
}

void simple_event::trigger_for_unuse() TAMER_NOEXCEPT {
#if TAMER_DEBUG
    assert(_r && _refcount == 0);
#endif
    message::event_prematurely_dereferenced(this, _r);
    _refcount = 2;		// to prevent a recursive call to unuse
    simple_trigger(false);
    _refcount = 0;		// restore old _refcount
}

simple_event *simple_event::at_trigger_event() {
    if (!at_trigger_f_)
	return static_cast<simple_event *>(at_trigger_);
    else
	return tamer::fun_event(at_trigger_f_, at_trigger_,
				at_trigger_arg2_).__take_simple();
}

void simple_event::hard_at_trigger(simple_event *x, simple_event *at_e) {
    if (!at_e || !*at_e)
	/* ignore */;
    else if (!x || !*x)
	at_e->simple_trigger(false);
    else {
	x->at_trigger_ =
	    tamer::distribute(event<>::__make(x->at_trigger_event()),
			      event<>::__make(at_e))
	    .__take_simple();
	x->at_trigger_f_ = 0;
    }
}

void simple_event::hard_at_trigger(simple_event *x, void (*f)(void *, int),
				   void *arg1, int arg2) {
    if (!x || !*x)
	f(arg1, arg2);
    else {
	x->at_trigger_ =
	    tamer::distribute(event<>::__make(x->at_trigger_event()),
			      tamer::fun_event(f, arg1, arg2))
	    .__take_simple();
	x->at_trigger_f_ = 0;
    }
}

namespace message {

void event_prematurely_dereferenced(simple_event *, abstract_rendezvous *r) {
    tamer_closure *c = r->linked_closure();
    if (r->is_volatile())
	/* no error message */;
    else if (c && int(c->tamer_block_position_) < 0) {
	tamer_debug_closure *dc = static_cast<tamer_debug_closure *>(c);
	fprintf(stderr, "%s:%d: avoided leak of active event\n",
		dc->tamer_blocked_file_, dc->tamer_blocked_line_);
    } else
	fprintf(stderr, "avoided leak of active event\n");
}

} // namespace tamer::tamerpriv::message
} // namespace tamer::tamerpriv

void rendezvous<uintptr_t>::clear()
{
    abstract_rendezvous::remove_waiting();
    explicit_rendezvous::remove_ready();
}

void rendezvous<>::clear()
{
    abstract_rendezvous::remove_waiting();
    explicit_rendezvous::remove_ready();
}

void gather_rendezvous::clear()
{
    abstract_rendezvous::remove_waiting();
}

} // namespace tamer
<|endoftext|>


<commit_before>#include "Task.h"
#include "FileIO.h"

#include "view/PropertySettingPanel.h"
#include "view/StagePanel.h"
#include "view/ToolbarPanel.h"
#include "view/TimeLinePanel.h"
#include "view/LayersPanel.h"

#include <easycomplex.h>
#include <easymesh.h>
#include <easyscale9.h>
#include <easyicon.h>

#include <wx/splitter.h>

namespace eanim
{

Task::Task(wxFrame* parent)
	: m_root(NULL)
	, m_parent(parent)
	, m_controller(&m_widgets)
{
	InitLayout();

	m_widgets.m_library->LoadFromConfig();

	d2d::ClearPanelSJ::Instance()->Register(this);
}

Task::~Task()
{
	d2d::SymbolMgr::Instance()->Clear();
	d2d::BitmapMgr::Instance()->Clear();
	delete m_root;

	d2d::ClearPanelSJ::Instance()->UnRegister(this);
}

void Task::Notify(int sj_id, void* ud)
{
	if (sj_id == d2d::MSG_CLEAR_PANEL) {
		m_controller.Clear();
		m_widgets.m_layersPanel->insertLayer();
	}
}

void Task::Load(const char* filepath)
{
	if (!d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anim) &&
		!d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anis)) {
		return;
	}

	m_controller.Clear();

	try {
		FileIO::Load(filepath, &m_controller);
	} catch (d2d::Exception& e) {
		d2d::ExceptionDlg dlg(m_parent, e);
		dlg.ShowModal();
	}
	m_widgets.m_stage->GetCanvas()->ResetViewport();
}

void Task::Store(const char* filepath) const
{
	if (d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anim)) {
		FileIO::StoreSingle(filepath, const_cast<Controller*>(&m_controller));
		m_widgets.m_stage->OnSave();
	} else if (d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anis)) {
		FileIO::StoreTemplate(filepath, const_cast<Controller*>(&m_controller));
		m_widgets.m_stage->OnSave();
	}
}

bool Task::IsDirty() const
{
	return m_widgets.m_stage->IsEditDirty();
}

void Task::GetAllSprite(std::vector<const d2d::ISprite*>& sprites) const
{
	m_widgets.m_stage->TraverseSprites(d2d::FetchAllVisitor<const d2d::ISprite>(sprites));
}

const d2d::EditPanel* Task::GetEditPanel() const
{
	return m_widgets.m_stage;
}

void Task::InitLayout()
{
	wxSplitterWindow* right_split = new wxSplitterWindow(m_parent);
	wxSplitterWindow* left_split = new wxSplitterWindow(right_split);

	wxWindow* left = InitLayoutLeft(left_split);
	wxWindow* center = InitLayoutCenter(left_split);
	wxWindow* right = InitLayoutRight(right_split);

	left_split->SetSashGravity(0.12f);
	left_split->SplitVertically(left, center);

	right_split->SetSashGravity(0.9f);
	right_split->SplitVertically(left_split, right);

	m_root = right_split;
}

wxWindow* Task::InitLayoutLeft(wxWindow* parent)
{
	wxSplitterWindow* split = new wxSplitterWindow(parent);

	// library
	m_widgets.m_library = new d2d::LibraryPanel(split);
	wxWindow* nb = m_widgets.m_library->GetNotebook();
	m_widgets.m_library->AddPage(m_widgets.m_imagePage = new d2d::LibraryImagePage(nb));
	m_widgets.m_library->AddPage(new ecomplex::LibraryPage(nb));
	m_widgets.m_library->AddPage(new emesh::LibraryPage(nb));
	m_widgets.m_library->AddPage(new escale9::LibraryPage(nb));
	m_widgets.m_library->AddPage(new eicon::LibraryPage(nb));

	// property
	m_widgets.m_property = new PropertySettingPanel(split);

	split->SetSashGravity(0.55f);
	split->SplitHorizontally(m_widgets.m_library, m_widgets.m_property);

	return split;
}

wxWindow* Task::InitLayoutCenter(wxWindow* parent)
{
	wxSplitterWindow* bottom_split = new wxSplitterWindow(parent);
	wxSplitterWindow* top_split = new wxSplitterWindow(bottom_split);

	// stage
	m_widgets.m_stage = new StagePanel(top_split, m_parent, m_widgets.m_property,
		&m_controller);
	m_widgets.m_property->SetEditPanel(m_widgets.m_stage->GetStageImpl());
	m_widgets.m_library->SetCanvas(m_widgets.m_stage->GetCanvas());	// ?

	// toolbar
	m_widgets.m_toolbar = new ToolbarPanel(top_split, m_widgets.m_stage,
		m_widgets.m_property, false, &m_controller);

	// timeline
	TimeLinePanel* timeline = new TimeLinePanel(bottom_split, &m_controller);

	top_split->SetSashGravity(0.1f);
	top_split->SplitHorizontally(m_widgets.m_toolbar, m_widgets.m_stage);

	bottom_split->SetSashGravity(0.9f);
	bottom_split->SplitHorizontally(top_split, timeline);

	return bottom_split;
}

wxWindow* Task::InitLayoutRight(wxWindow* parent)
{
	// viewlist
	m_widgets.m_viewlist = new d2d::ViewlistPanel(parent);
	return m_widgets.m_viewlist;
}

}<commit_msg>[FIXED] anim clear library<commit_after>#include "Task.h"
#include "FileIO.h"

#include "view/PropertySettingPanel.h"
#include "view/StagePanel.h"
#include "view/ToolbarPanel.h"
#include "view/TimeLinePanel.h"
#include "view/LayersPanel.h"

#include <easycomplex.h>
#include <easymesh.h>
#include <easyscale9.h>
#include <easyicon.h>

#include <wx/splitter.h>

namespace eanim
{

Task::Task(wxFrame* parent)
	: m_root(NULL)
	, m_parent(parent)
	, m_controller(&m_widgets)
{
	InitLayout();

	m_widgets.m_library->LoadFromConfig();

	d2d::ClearPanelSJ::Instance()->Register(this);
}

Task::~Task()
{
	d2d::SymbolMgr::Instance()->Clear();
	d2d::BitmapMgr::Instance()->Clear();
	delete m_root;

	d2d::ClearPanelSJ::Instance()->UnRegister(this);
}

void Task::Notify(int sj_id, void* ud)
{
	if (sj_id == d2d::MSG_CLEAR_PANEL) {
		m_controller.Clear();
		m_widgets.m_library->Clear();
		m_widgets.m_layersPanel->insertLayer();
	}
}

void Task::Load(const char* filepath)
{
	if (!d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anim) &&
		!d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anis)) {
		return;
	}

	m_controller.Clear();

	try {
		FileIO::Load(filepath, &m_controller);
	} catch (d2d::Exception& e) {
		d2d::ExceptionDlg dlg(m_parent, e);
		dlg.ShowModal();
	}
	m_widgets.m_stage->GetCanvas()->ResetViewport();
}

void Task::Store(const char* filepath) const
{
	if (d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anim)) {
		FileIO::StoreSingle(filepath, const_cast<Controller*>(&m_controller));
		m_widgets.m_stage->OnSave();
	} else if (d2d::FileNameParser::isType(filepath, d2d::FileNameParser::e_anis)) {
		FileIO::StoreTemplate(filepath, const_cast<Controller*>(&m_controller));
		m_widgets.m_stage->OnSave();
	}
}

bool Task::IsDirty() const
{
	return m_widgets.m_stage->IsEditDirty();
}

void Task::GetAllSprite(std::vector<const d2d::ISprite*>& sprites) const
{
	m_widgets.m_stage->TraverseSprites(d2d::FetchAllVisitor<const d2d::ISprite>(sprites));
}

const d2d::EditPanel* Task::GetEditPanel() const
{
	return m_widgets.m_stage;
}

void Task::InitLayout()
{
	wxSplitterWindow* right_split = new wxSplitterWindow(m_parent);
	wxSplitterWindow* left_split = new wxSplitterWindow(right_split);

	wxWindow* left = InitLayoutLeft(left_split);
	wxWindow* center = InitLayoutCenter(left_split);
	wxWindow* right = InitLayoutRight(right_split);

	left_split->SetSashGravity(0.12f);
	left_split->SplitVertically(left, center);

	right_split->SetSashGravity(0.9f);
	right_split->SplitVertically(left_split, right);

	m_root = right_split;
}

wxWindow* Task::InitLayoutLeft(wxWindow* parent)
{
	wxSplitterWindow* split = new wxSplitterWindow(parent);

	// library
	m_widgets.m_library = new d2d::LibraryPanel(split);
	wxWindow* nb = m_widgets.m_library->GetNotebook();
	m_widgets.m_library->AddPage(m_widgets.m_imagePage = new d2d::LibraryImagePage(nb));
	m_widgets.m_library->AddPage(new ecomplex::LibraryPage(nb));
	m_widgets.m_library->AddPage(new emesh::LibraryPage(nb));
	m_widgets.m_library->AddPage(new escale9::LibraryPage(nb));
	m_widgets.m_library->AddPage(new eicon::LibraryPage(nb));

	// property
	m_widgets.m_property = new PropertySettingPanel(split);

	split->SetSashGravity(0.55f);
	split->SplitHorizontally(m_widgets.m_library, m_widgets.m_property);

	return split;
}

wxWindow* Task::InitLayoutCenter(wxWindow* parent)
{
	wxSplitterWindow* bottom_split = new wxSplitterWindow(parent);
	wxSplitterWindow* top_split = new wxSplitterWindow(bottom_split);

	// stage
	m_widgets.m_stage = new StagePanel(top_split, m_parent, m_widgets.m_property,
		&m_controller);
	m_widgets.m_property->SetEditPanel(m_widgets.m_stage->GetStageImpl());
	m_widgets.m_library->SetCanvas(m_widgets.m_stage->GetCanvas());	// ?

	// toolbar
	m_widgets.m_toolbar = new ToolbarPanel(top_split, m_widgets.m_stage,
		m_widgets.m_property, false, &m_controller);

	// timeline
	TimeLinePanel* timeline = new TimeLinePanel(bottom_split, &m_controller);

	top_split->SetSashGravity(0.1f);
	top_split->SplitHorizontally(m_widgets.m_toolbar, m_widgets.m_stage);

	bottom_split->SetSashGravity(0.9f);
	bottom_split->SplitHorizontally(top_split, timeline);

	return bottom_split;
}

wxWindow* Task::InitLayoutRight(wxWindow* parent)
{
	// viewlist
	m_widgets.m_viewlist = new d2d::ViewlistPanel(parent);
	return m_widgets.m_viewlist;
}

}<|endoftext|>